diff --git a/Cargo.toml b/Cargo.toml index 3c9f967..1b4d2ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ version = "0.1.0" edition = "2021" [lib] -crate-type = ["cdylib", "rlib"] +crate-type = ["cdylib", "staticlib", "rlib"] [lints] workspace = true @@ -51,6 +51,7 @@ native = [ "uniffi-bindings", ] desktop = ["full-api"] +ios = ["full-api", "uniffi-bindings"] full-api = [] streaming-shared = [] uniffi-bindings = ["dep:uniffi", "full-api"] diff --git a/scripts/build-ios-xcframework.sh b/scripts/build-ios-xcframework.sh new file mode 100755 index 0000000..c450b74 --- /dev/null +++ b/scripts/build-ios-xcframework.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +set -euo pipefail + +if [[ "$(uname)" != "Darwin" ]]; then + echo "error: this script requires macOS with Xcode command line tools installed" >&2 + exit 1 +fi + +if ! command -v xcodebuild >/dev/null 2>&1; then + echo "error: xcodebuild not found — install Xcode" >&2 + exit 1 +fi + +cd "$(dirname "$0")/.." + +TARGETS=(aarch64-apple-ios aarch64-apple-ios-sim) + +for target in "${TARGETS[@]}"; do + rustup target add "$target" +done + +for target in "${TARGETS[@]}"; do + cargo build --release --target "$target" --no-default-features --features ios --lib +done + +BINDINGS_DIR="target/uniffi-swift" +rm -rf "$BINDINGS_DIR" +mkdir -p "$BINDINGS_DIR" + +cargo run --features uniffi-cli --bin uniffi-bindgen generate \ + --library "target/aarch64-apple-ios/release/libfluxa_core.a" \ + --language swift \ + --config uniffi.toml \ + --out-dir "$BINDINGS_DIR" + +HEADERS_DIR="$BINDINGS_DIR/Headers" +mkdir -p "$HEADERS_DIR" +mv "$BINDINGS_DIR"/*.h "$HEADERS_DIR"/ +mv "$BINDINGS_DIR"/*.modulemap "$HEADERS_DIR/module.modulemap" + +XCFRAMEWORK_OUT="build/ios/FluxaCore.xcframework" +rm -rf "build/ios" +mkdir -p "build/ios" + +xcodebuild -create-xcframework \ + -library "target/aarch64-apple-ios/release/libfluxa_core.a" -headers "$HEADERS_DIR" \ + -library "target/aarch64-apple-ios-sim/release/libfluxa_core.a" -headers "$HEADERS_DIR" \ + -output "$XCFRAMEWORK_OUT" + +echo "xcframework: $XCFRAMEWORK_OUT" +echo "Swift bindings: $BINDINGS_DIR"/*.swift diff --git a/uniffi.toml b/uniffi.toml index 132a956..0c1845b 100644 --- a/uniffi.toml +++ b/uniffi.toml @@ -3,3 +3,7 @@ package_name = "com.fluxa.core.uniffi" android = true cdylib_name = "fluxa_core" kotlin_target_version = "2.3.0" + +[bindings.swift] +module_name = "FluxaCore" +cdylib_name = "fluxa_core"