Skip to content

Commit

Permalink
call cbingen from scripts, not from the rust build
Browse files Browse the repository at this point in the history
  • Loading branch information
ypopovych committed Jan 29, 2024
1 parent 16dc341 commit e7333e9
Show file tree
Hide file tree
Showing 16 changed files with 86 additions and 113 deletions.
12 changes: 10 additions & 2 deletions .github/workflows/on_new_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ on:
types: [created]
jobs:
publish_pod:
name: Publish to Cocoa Pods
uses: "./.github/workflows/publish_pod.yml"
with:
version: ${{ github.event.release.tag_name }}
version: ${{ github.event.release.tag_name }}
secrets:
trunk-token: ${{ secrets.COCOAPODS_TRUNK_TOKEN }}
trunk-token: ${{ secrets.COCOAPODS_TRUNK_TOKEN }}
publish_crate:
name: Publish to Crates
uses: "./.github/workflows/publish_crate.yml"
with:
version: ${{ github.event.release.tag_name }}
secrets:
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
36 changes: 36 additions & 0 deletions .github/workflows/publish_crate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Publish to Crates
on:
workflow_call:
inputs:
version:
required: true
type: string
secrets:
registry-token:
required: true
jobs:
publish:
runs-on: macOS-13
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ inputs.version }}
- name: Select Xcode
run: sudo xcode-select -s /Applications/Xcode_14.3.1.app
- name: Set release version
run: sed -i '' "s|version[[:blank:]]*=[[:blank:]]*\".*\"\(.*\)#AUTOVERSION|version = \"${VERSION}\"\1|g" Cargo.toml
env:
VERSION: ${{ inputs.version }}
- name: Publish Utils
run: cargo publish -p tesseract-swift-utils
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.registry-token }}
- name: Publish Transport
run: cargo publish -p tesseract-swift-transport
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.registry-token }}
- name: Publish SDK
run: cargo publish -p tesseract-swift
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.registry-token }}
10 changes: 10 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ jobs:
toolchain: ${{env.RUST_VERSION}}
targets: ${{env.RUST_TARGETS}}
profile: minimal
- name: Install cbindgen
run: cargo install --force cbindgen
- name: Build Core Zip
id: build-core-zip
env:
Expand Down Expand Up @@ -91,3 +93,11 @@ jobs:
version: ${{ inputs.version }}
secrets:
trunk-token: ${{ secrets.COCOAPODS_TRUNK_TOKEN }}
publish-crate:
name: Publish to Crates
needs: build-core-and-deploy
uses: "./.github/workflows/publish_crate.yml"
with:
version: ${{ inputs.version }}
secrets:
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
toolchain: ${{env.RUST_VERSION}}
targets: ${{env.RUST_TARGETS}}
profile: minimal
- name: Install cbindgen
run: cargo install --force cbindgen
- name: Build Core rust binary
run: Rust/generate_headers.sh && Rust/generate_xcframework.sh
- name: Patch Package.swift for testing
Expand Down
11 changes: 4 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ members = [ "Rust/sdk", "Rust/transport", "Rust/utils", "Rust/framework" ]
[workspace.package]
authors = ["Daniel Leping", "Yehor Popovych", "Tesseract Systems, Inc."]
edition = "2021"
version = "0.5.6"
version = "999.99.9" #AUTOVERSION
license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/tesseract-one/Tesseract.swift"
Expand All @@ -19,9 +19,6 @@ async-trait = "0.1"
errorcon = "0.1"
log = "0.4"

#build deps (C-interop)
cbindgen = "0.26"

#tesseract
tesseract-one = "0.5"

Expand All @@ -30,9 +27,9 @@ tesseract-protocol-test = "0.5"
tesseract-protocol-substrate = "0.5"

#local
tesseract-swift-utils = { path = "Rust/utils", version = "0.5.6"}
tesseract-swift-transport = { path = "Rust/transport", version = "0.5.6"}
tesseract-swift = { path = "Rust/sdk", version = "0.5.6"}
tesseract-swift-utils = { path = "Rust/utils", version = "999.99.9" } #AUTOVERSION
tesseract-swift-transport = { path = "Rust/transport", version = "999.99.9" } #AUTOVERSION
tesseract-swift = { path = "Rust/sdk", version = "999.99.9" } #AUTOVERSION

[profile.release]
strip = true
Expand Down
4 changes: 0 additions & 4 deletions Rust/framework/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ tesseract-one.workspace = true
tesseract-protocol-test = { workspace = true, optional = true, features = ["client", "service"] }
tesseract-protocol-substrate = { workspace = true, optional = true, features = ["client", "service"] }

[build-dependencies]
cbindgen.workspace = true

[features]
default = ["client", "service", "protocol-all"]

Expand All @@ -41,4 +38,3 @@ protocol-all = ["protocol-test", "protocol-substrate"]

[lib]
crate-type = ["staticlib"]

21 changes: 0 additions & 21 deletions Rust/framework/build.rs

This file was deleted.

14 changes: 6 additions & 8 deletions Rust/generate_headers.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
#!/bin/zsh
set -e

CRATES=("tesseract-swift-utils" "tesseract-swift-transport")
MODULE_NAME="CTesseractShared"
MAIN_CRATE="tesseract-swift-transport"
HEADERS_DIR="target/release/include"
OUTPUT_DIR="Sources/$MODULE_NAME/include"

DIR="$(cd "$(dirname "$0")" && pwd -P)/.."
cd "$DIR"
DIR="$(cd "$(dirname "$0")" && pwd -P)"

rm -rf "$HEADERS_DIR"

cargo build -p "$MAIN_CRATE" --release --all-features
cd "$DIR/.."

rm -rf "$OUTPUT_DIR"
mkdir -p "$OUTPUT_DIR"

cp "$HEADERS_DIR/"*.h "$OUTPUT_DIR/"
for crate in $CRATES; do
cbindgen -q --crate $crate -o "$OUTPUT_DIR/$crate.h"
done

exit 0
6 changes: 3 additions & 3 deletions Rust/generate_xcframework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ for btarget in ${BUILD_TARGETS[@]}; do

lipo ${built_libs} -create -output "${OUT_LIB_PATH}"

cbindgen -q --crate $CRATE -o "${HEADERS_DIR}/${LIBRARY_NAME}.h"

generate_modulemap "${HEADERS_DIR}" "${XCFRAMEWORK_NAME}" "${LIBRARY_NAME}"

cp -f "${RUST_TARGET_DIR}/${CONFIGURATION}/include/${CRATE}.h" "${HEADERS_DIR}/${LIBRARY_NAME}.h"


add_library_to_xcframework "${XCFRAMEWORK_PATH}" \
"${HEADERS_DIR}/" "${OUT_LIB_PATH}" \
"${platform}" "${archs}" "${variant}"
Expand Down
3 changes: 0 additions & 3 deletions Rust/transport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,3 @@ tesseract-swift-utils.workspace = true
[features]
client = ["tesseract-one/client"]
service = ["tesseract-one/service"]

[build-dependencies]
cbindgen.workspace = true
21 changes: 0 additions & 21 deletions Rust/transport/build.rs

This file was deleted.

3 changes: 0 additions & 3 deletions Rust/utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,5 @@ keywords.workspace = true
log.workspace = true
num-bigint = { version = "0.4", optional = true }

[build-dependencies]
cbindgen.workspace = true

[features]
bigint = ["dep:num-bigint"]
21 changes: 0 additions & 21 deletions Rust/utils/build.rs

This file was deleted.

3 changes: 3 additions & 0 deletions Rust/utils/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ cpp_compat = true
[enum]
prefix_with_name = true

[defines]
"feature = bigint" = "DEFINE_FEATURE_BIGINT"

[export]
include = [
"CPtrRef", "CStringRef", "CFutureNothing",
Expand Down
5 changes: 0 additions & 5 deletions Rust/utils/src/future_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,3 @@ pub type CFutureUInt64 = CFuture<u64>;
pub type CFutureBool = CFuture<bool>;
pub type CFutureInt128 = CFuture<CInt128>;
pub type CFutureUInt128 = CFuture<CUInt128>;

#[cfg(feature = "bigint")]
use crate::bigint::CBigInt;
#[cfg(feature = "bigint")]
pub type CFutureBigInt = CFuture<CBigInt>;
27 changes: 12 additions & 15 deletions Sources/CTesseractShared/include/tesseract-swift-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@
#include <stdint.h>
#include <stdlib.h>

#if defined(DEFINE_FEATURE_BIGINT)
typedef enum CBigIntSign {
#if defined(DEFINE_FEATURE_BIGINT)
CBigIntSign_Minus,
#endif
#if defined(DEFINE_FEATURE_BIGINT)
CBigIntSign_NoSign,
#endif
#if defined(DEFINE_FEATURE_BIGINT)
CBigIntSign_Plus,
#endif
} CBigIntSign;
#endif

enum CErrorCode
#ifdef __cplusplus
Expand Down Expand Up @@ -88,10 +96,12 @@ typedef struct CArray_u32 {
uintptr_t len;
} CArray_u32;

#if defined(DEFINE_FEATURE_BIGINT)
typedef struct CBigInt {
enum CBigIntSign sign;
struct CArray_u32 data;
} CBigInt;
#endif

typedef struct CAnyDropPtr {
SyncPtr_Void ptr;
Expand Down Expand Up @@ -187,21 +197,6 @@ typedef struct CFuture_CData {

typedef struct CFuture_CData CFutureData;

typedef void (*CFutureOnCompleteCallback_CBigInt)(SyncPtr_Void context,
struct CBigInt *value,
struct CError *error);

typedef struct CFuture_CBigInt {
struct CAnyDropPtr ptr;
enum COptionResponseResult (*set_on_complete)(const struct CFuture_CBigInt *future,
SyncPtr_Void context,
struct CBigInt *value,
struct CError *error,
CFutureOnCompleteCallback_CBigInt cb);
} CFuture_CBigInt;

typedef struct CFuture_CBigInt CFutureBigInt;

typedef void (*CFutureOnCompleteCallback_CAnyRustPtr)(SyncPtr_Void context,
struct CAnyRustPtr *value,
struct CError *error);
Expand Down Expand Up @@ -277,7 +272,9 @@ bool tesseract_utils_cstring_new(CStringRef cstr, struct CString *res, struct CE

void tesseract_utils_cstring_free(struct CString cstr);

#if defined(DEFINE_FEATURE_BIGINT)
void tesseract_utils_big_int_free(struct CBigInt *big_int);
#endif

#ifdef __cplusplus
} // extern "C"
Expand Down

0 comments on commit e7333e9

Please sign in to comment.