From 79a728d4f7c8d2f31eecbadfd3f2db573e213e9b Mon Sep 17 00:00:00 2001 From: KhooLy <73142442+KhooLy@users.noreply.github.com> Date: Mon, 13 Jul 2026 02:36:38 +0300 Subject: [PATCH] Add iOS build target for fluxa_core MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Phase 0 of the fluxa-android KMP/CMP migration needs an xcframework + Swift UniFFI bindings for fluxa_core. Adds an "ios" feature (full-api + uniffi-bindings, no jni/dolby_vision, mirroring the existing "desktop" feature), a staticlib crate-type for xcframework embedding, a [bindings.swift] uniffi.toml section, and a macOS-only build script that produces FluxaCore.xcframework for aarch64-apple-ios and aarch64-apple-ios-sim. Verified on Linux: `cargo check --target aarch64-apple-ios --features ios` and the aarch64-apple-ios-sim equivalent both compile cleanly, so the crate itself has no Android/JNI-only code leaking into the iOS feature set. Actual linking/xcframework packaging needs a Mac with Xcode — untested here. --- Cargo.toml | 3 +- scripts/build-ios-xcframework.sh | 51 ++++++++++++++++++++++++++++++++ uniffi.toml | 4 +++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100755 scripts/build-ios-xcframework.sh 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"