From ed3839e21bb29cd1a7313cf83ee3e609ce6a970b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C5=82az=CC=87ej=20Pankowski?= <86720177+pblazej@users.noreply.github.com> Date: Fri, 17 Oct 2025 11:33:21 +0200 Subject: [PATCH 1/7] Initial xcframework script --- livekit-uniffi/swift.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 livekit-uniffi/swift.sh diff --git a/livekit-uniffi/swift.sh b/livekit-uniffi/swift.sh new file mode 100755 index 000000000..9a3576403 --- /dev/null +++ b/livekit-uniffi/swift.sh @@ -0,0 +1,31 @@ +#!/bin/bash +set -e + +cargo build --release + +cargo run --bin uniffi-bindgen generate \ + --library ../target/release/liblivekit_uniffi.dylib \ + --language swift \ + --out-dir "generated/swift" + +mv ./generated/swift/livekit_uniffiFFI.modulemap ./generated/swift/module.modulemap + +rustup target add aarch64-apple-darwin +rustup target add x86_64-apple-darwin +rustup target add aarch64-apple-ios +rustup target add aarch64-apple-ios-sim +rustup target add x86_64-apple-ios + +cargo build --release --target aarch64-apple-darwin +cargo build --release --target x86_64-apple-darwin +cargo build --release --target aarch64-apple-ios +cargo build --release --target aarch64-apple-ios-sim +cargo build --release --target x86_64-apple-ios + +# Combine iOS Simulator here + +xcodebuild -create-xcframework \ + -library ../target/aarch64-apple-ios-sim/release/liblivekit_uniffi.a -headers ./generated/swift \ + -library ../target/aarch64-apple-ios/release/liblivekit_uniffi.a -headers ./generated/swift \ + -library ../target/aarch64-apple-darwin/release/liblivekit_uniffi.a -headers ./generated/swift \ + -output "../target/LiveKitFFI.xcframework" From 0afa891427c62a5557c72d102ac8e473319faf63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C5=82az=CC=87ej=20Pankowski?= <86720177+pblazej@users.noreply.github.com> Date: Fri, 17 Oct 2025 11:45:01 +0200 Subject: [PATCH 2/7] Lipo --- livekit-uniffi/swift.sh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/livekit-uniffi/swift.sh b/livekit-uniffi/swift.sh index 9a3576403..b80f475e4 100755 --- a/livekit-uniffi/swift.sh +++ b/livekit-uniffi/swift.sh @@ -22,10 +22,22 @@ cargo build --release --target aarch64-apple-ios cargo build --release --target aarch64-apple-ios-sim cargo build --release --target x86_64-apple-ios -# Combine iOS Simulator here +mkdir -p ../target/ios-simulator/release +lipo -create \ + ../target/aarch64-apple-ios-sim/release/liblivekit_uniffi.a \ + ../target/x86_64-apple-ios/release/liblivekit_uniffi.a \ + -output ../target/ios-simulator/release/liblivekit_uniffi.a + +mkdir -p ../target/macos/release +lipo -create \ + ../target/aarch64-apple-darwin/release/liblivekit_uniffi.a \ + ../target/x86_64-apple-darwin/release/liblivekit_uniffi.a \ + -output ../target/macos/release/liblivekit_uniffi.a + +rm -rf ../target/LiveKitFFI.xcframework xcodebuild -create-xcframework \ - -library ../target/aarch64-apple-ios-sim/release/liblivekit_uniffi.a -headers ./generated/swift \ -library ../target/aarch64-apple-ios/release/liblivekit_uniffi.a -headers ./generated/swift \ - -library ../target/aarch64-apple-darwin/release/liblivekit_uniffi.a -headers ./generated/swift \ + -library ../target/ios-simulator/release/liblivekit_uniffi.a -headers ./generated/swift \ + -library ../target/macos/release/liblivekit_uniffi.a -headers ./generated/swift \ -output "../target/LiveKitFFI.xcframework" From 4d175284f6f448d997cb0917979b307525f8c514 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C5=82az=CC=87ej=20Pankowski?= <86720177+pblazej@users.noreply.github.com> Date: Fri, 17 Oct 2025 11:48:15 +0200 Subject: [PATCH 3/7] Catalyst --- livekit-uniffi/swift.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/livekit-uniffi/swift.sh b/livekit-uniffi/swift.sh index b80f475e4..61e3dfba8 100755 --- a/livekit-uniffi/swift.sh +++ b/livekit-uniffi/swift.sh @@ -15,12 +15,16 @@ rustup target add x86_64-apple-darwin rustup target add aarch64-apple-ios rustup target add aarch64-apple-ios-sim rustup target add x86_64-apple-ios +rustup target add aarch64-apple-ios-macabi +rustup target add x86_64-apple-ios-macabi cargo build --release --target aarch64-apple-darwin cargo build --release --target x86_64-apple-darwin cargo build --release --target aarch64-apple-ios cargo build --release --target aarch64-apple-ios-sim cargo build --release --target x86_64-apple-ios +cargo build --release --target aarch64-apple-ios-macabi +cargo build --release --target x86_64-apple-ios-macabi mkdir -p ../target/ios-simulator/release lipo -create \ @@ -34,10 +38,17 @@ lipo -create \ ../target/x86_64-apple-darwin/release/liblivekit_uniffi.a \ -output ../target/macos/release/liblivekit_uniffi.a +mkdir -p ../target/ios-macabi/release +lipo -create \ + ../target/aarch64-apple-ios-macabi/release/liblivekit_uniffi.a \ + ../target/x86_64-apple-ios-macabi/release/liblivekit_uniffi.a \ + -output ../target/ios-macabi/release/liblivekit_uniffi.a + rm -rf ../target/LiveKitFFI.xcframework xcodebuild -create-xcframework \ -library ../target/aarch64-apple-ios/release/liblivekit_uniffi.a -headers ./generated/swift \ -library ../target/ios-simulator/release/liblivekit_uniffi.a -headers ./generated/swift \ -library ../target/macos/release/liblivekit_uniffi.a -headers ./generated/swift \ + -library ../target/ios-macabi/release/liblivekit_uniffi.a -headers ./generated/swift \ -output "../target/LiveKitFFI.xcframework" From 1d023a7e86a9bbcdbbdc4e88612d745c15827f49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C5=82az=CC=87ej=20Pankowski?= <86720177+pblazej@users.noreply.github.com> Date: Fri, 17 Oct 2025 11:56:04 +0200 Subject: [PATCH 4/7] tvOS, visionOS --- livekit-uniffi/swift.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/livekit-uniffi/swift.sh b/livekit-uniffi/swift.sh index 61e3dfba8..0cb762db0 100755 --- a/livekit-uniffi/swift.sh +++ b/livekit-uniffi/swift.sh @@ -26,6 +26,12 @@ cargo build --release --target x86_64-apple-ios cargo build --release --target aarch64-apple-ios-macabi cargo build --release --target x86_64-apple-ios-macabi +# Tier 3 targets: tvOS, visionOS +cargo +nightly build -Zbuild-std=std,panic_abort --release --target=aarch64-apple-tvos +cargo +nightly build -Zbuild-std=std,panic_abort --release --target=aarch64-apple-visionos +cargo +nightly build -Zbuild-std=std,panic_abort --release --target=aarch64-apple-tvos-sim +cargo +nightly build -Zbuild-std=std,panic_abort --release --target=aarch64-apple-visionos-sim + mkdir -p ../target/ios-simulator/release lipo -create \ ../target/aarch64-apple-ios-sim/release/liblivekit_uniffi.a \ @@ -51,4 +57,8 @@ xcodebuild -create-xcframework \ -library ../target/ios-simulator/release/liblivekit_uniffi.a -headers ./generated/swift \ -library ../target/macos/release/liblivekit_uniffi.a -headers ./generated/swift \ -library ../target/ios-macabi/release/liblivekit_uniffi.a -headers ./generated/swift \ + -library ../target/aarch64-apple-tvos/release/liblivekit_uniffi.a -headers ./generated/swift \ + -library ../target/aarch64-apple-visionos/release/liblivekit_uniffi.a -headers ./generated/swift \ + -library ../target/aarch64-apple-tvos-sim/release/liblivekit_uniffi.a -headers ./generated/swift \ + -library ../target/aarch64-apple-visionos-sim/release/liblivekit_uniffi.a -headers ./generated/swift \ -output "../target/LiveKitFFI.xcframework" From d3502391c48e7314b6532f4c4a1acff59ae75710 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C5=82az=CC=87ej=20Pankowski?= <86720177+pblazej@users.noreply.github.com> Date: Fri, 17 Oct 2025 11:59:39 +0200 Subject: [PATCH 5/7] Loopify --- livekit-uniffi/swift.sh | 98 +++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 42 deletions(-) diff --git a/livekit-uniffi/swift.sh b/livekit-uniffi/swift.sh index 0cb762db0..618707ad8 100755 --- a/livekit-uniffi/swift.sh +++ b/livekit-uniffi/swift.sh @@ -8,57 +8,71 @@ cargo run --bin uniffi-bindgen generate \ --language swift \ --out-dir "generated/swift" +# Required for xcframework mv ./generated/swift/livekit_uniffiFFI.modulemap ./generated/swift/module.modulemap -rustup target add aarch64-apple-darwin -rustup target add x86_64-apple-darwin -rustup target add aarch64-apple-ios -rustup target add aarch64-apple-ios-sim -rustup target add x86_64-apple-ios -rustup target add aarch64-apple-ios-macabi -rustup target add x86_64-apple-ios-macabi +RUSTUP_TARGETS=( + aarch64-apple-darwin + x86_64-apple-darwin + aarch64-apple-ios + aarch64-apple-ios-sim + x86_64-apple-ios + aarch64-apple-ios-macabi + x86_64-apple-ios-macabi +) -cargo build --release --target aarch64-apple-darwin -cargo build --release --target x86_64-apple-darwin -cargo build --release --target aarch64-apple-ios -cargo build --release --target aarch64-apple-ios-sim -cargo build --release --target x86_64-apple-ios -cargo build --release --target aarch64-apple-ios-macabi -cargo build --release --target x86_64-apple-ios-macabi +TIER3_TARGETS=( + aarch64-apple-tvos + aarch64-apple-visionos + aarch64-apple-tvos-sim + aarch64-apple-visionos-sim +) -# Tier 3 targets: tvOS, visionOS -cargo +nightly build -Zbuild-std=std,panic_abort --release --target=aarch64-apple-tvos -cargo +nightly build -Zbuild-std=std,panic_abort --release --target=aarch64-apple-visionos -cargo +nightly build -Zbuild-std=std,panic_abort --release --target=aarch64-apple-tvos-sim -cargo +nightly build -Zbuild-std=std,panic_abort --release --target=aarch64-apple-visionos-sim +for target in "${RUSTUP_TARGETS[@]}"; do + rustup target add "$target" +done -mkdir -p ../target/ios-simulator/release -lipo -create \ - ../target/aarch64-apple-ios-sim/release/liblivekit_uniffi.a \ - ../target/x86_64-apple-ios/release/liblivekit_uniffi.a \ - -output ../target/ios-simulator/release/liblivekit_uniffi.a +for target in "${RUSTUP_TARGETS[@]}"; do + cargo build --release --target "$target" +done -mkdir -p ../target/macos/release -lipo -create \ - ../target/aarch64-apple-darwin/release/liblivekit_uniffi.a \ - ../target/x86_64-apple-darwin/release/liblivekit_uniffi.a \ - -output ../target/macos/release/liblivekit_uniffi.a +for target in "${TIER3_TARGETS[@]}"; do + cargo +nightly build -Zbuild-std=std,panic_abort --release --target="$target" +done -mkdir -p ../target/ios-macabi/release -lipo -create \ - ../target/aarch64-apple-ios-macabi/release/liblivekit_uniffi.a \ - ../target/x86_64-apple-ios-macabi/release/liblivekit_uniffi.a \ - -output ../target/ios-macabi/release/liblivekit_uniffi.a +UNIVERSAL_BINARIES=( + "ios-simulator:aarch64-apple-ios-sim:x86_64-apple-ios" + "macos:aarch64-apple-darwin:x86_64-apple-darwin" + "ios-macabi:aarch64-apple-ios-macabi:x86_64-apple-ios-macabi" +) + +for config in "${UNIVERSAL_BINARIES[@]}"; do + IFS=':' read -r output_dir arch1 arch2 <<< "$config" + mkdir -p "../target/${output_dir}/release" + lipo -create \ + "../target/${arch1}/release/liblivekit_uniffi.a" \ + "../target/${arch2}/release/liblivekit_uniffi.a" \ + -output "../target/${output_dir}/release/liblivekit_uniffi.a" +done rm -rf ../target/LiveKitFFI.xcframework +XCFRAMEWORK_LIBS=( + "../target/aarch64-apple-ios/release/liblivekit_uniffi.a" + "../target/ios-simulator/release/liblivekit_uniffi.a" + "../target/macos/release/liblivekit_uniffi.a" + "../target/ios-macabi/release/liblivekit_uniffi.a" + "../target/aarch64-apple-tvos/release/liblivekit_uniffi.a" + "../target/aarch64-apple-visionos/release/liblivekit_uniffi.a" + "../target/aarch64-apple-tvos-sim/release/liblivekit_uniffi.a" + "../target/aarch64-apple-visionos-sim/release/liblivekit_uniffi.a" +) + +XCFRAMEWORK_ARGS=() +for lib in "${XCFRAMEWORK_LIBS[@]}"; do + XCFRAMEWORK_ARGS+=(-library "$lib" -headers ./generated/swift) +done + xcodebuild -create-xcframework \ - -library ../target/aarch64-apple-ios/release/liblivekit_uniffi.a -headers ./generated/swift \ - -library ../target/ios-simulator/release/liblivekit_uniffi.a -headers ./generated/swift \ - -library ../target/macos/release/liblivekit_uniffi.a -headers ./generated/swift \ - -library ../target/ios-macabi/release/liblivekit_uniffi.a -headers ./generated/swift \ - -library ../target/aarch64-apple-tvos/release/liblivekit_uniffi.a -headers ./generated/swift \ - -library ../target/aarch64-apple-visionos/release/liblivekit_uniffi.a -headers ./generated/swift \ - -library ../target/aarch64-apple-tvos-sim/release/liblivekit_uniffi.a -headers ./generated/swift \ - -library ../target/aarch64-apple-visionos-sim/release/liblivekit_uniffi.a -headers ./generated/swift \ + "${XCFRAMEWORK_ARGS[@]}" \ -output "../target/LiveKitFFI.xcframework" From 0cc25b5e279ea2e3493863d84fdc7c82ac359aeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C5=82az=CC=87ej=20Pankowski?= <86720177+pblazej@users.noreply.github.com> Date: Fri, 17 Oct 2025 12:03:45 +0200 Subject: [PATCH 6/7] Const --- livekit-uniffi/swift.sh | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/livekit-uniffi/swift.sh b/livekit-uniffi/swift.sh index 618707ad8..1e86e31fa 100755 --- a/livekit-uniffi/swift.sh +++ b/livekit-uniffi/swift.sh @@ -1,15 +1,19 @@ #!/bin/bash set -e +UNIFFI_MODULE="livekit_uniffi" +LIB_NAME="lib${UNIFFI_MODULE}" +XCFRAMEWORK_NAME="LiveKitFFI" + cargo build --release cargo run --bin uniffi-bindgen generate \ - --library ../target/release/liblivekit_uniffi.dylib \ + --library "../target/release/${LIB_NAME}.dylib" \ --language swift \ --out-dir "generated/swift" # Required for xcframework -mv ./generated/swift/livekit_uniffiFFI.modulemap ./generated/swift/module.modulemap +mv ./generated/swift/${UNIFFI_MODULE}FFI.modulemap ./generated/swift/module.modulemap RUSTUP_TARGETS=( aarch64-apple-darwin @@ -50,22 +54,22 @@ for config in "${UNIVERSAL_BINARIES[@]}"; do IFS=':' read -r output_dir arch1 arch2 <<< "$config" mkdir -p "../target/${output_dir}/release" lipo -create \ - "../target/${arch1}/release/liblivekit_uniffi.a" \ - "../target/${arch2}/release/liblivekit_uniffi.a" \ - -output "../target/${output_dir}/release/liblivekit_uniffi.a" + "../target/${arch1}/release/${LIB_NAME}.a" \ + "../target/${arch2}/release/${LIB_NAME}.a" \ + -output "../target/${output_dir}/release/${LIB_NAME}.a" done -rm -rf ../target/LiveKitFFI.xcframework +rm -rf "../target/${XCFRAMEWORK_NAME}.xcframework" XCFRAMEWORK_LIBS=( - "../target/aarch64-apple-ios/release/liblivekit_uniffi.a" - "../target/ios-simulator/release/liblivekit_uniffi.a" - "../target/macos/release/liblivekit_uniffi.a" - "../target/ios-macabi/release/liblivekit_uniffi.a" - "../target/aarch64-apple-tvos/release/liblivekit_uniffi.a" - "../target/aarch64-apple-visionos/release/liblivekit_uniffi.a" - "../target/aarch64-apple-tvos-sim/release/liblivekit_uniffi.a" - "../target/aarch64-apple-visionos-sim/release/liblivekit_uniffi.a" + "../target/aarch64-apple-ios/release/${LIB_NAME}.a" + "../target/ios-simulator/release/${LIB_NAME}.a" + "../target/macos/release/${LIB_NAME}.a" + "../target/ios-macabi/release/${LIB_NAME}.a" + "../target/aarch64-apple-tvos/release/${LIB_NAME}.a" + "../target/aarch64-apple-visionos/release/${LIB_NAME}.a" + "../target/aarch64-apple-tvos-sim/release/${LIB_NAME}.a" + "../target/aarch64-apple-visionos-sim/release/${LIB_NAME}.a" ) XCFRAMEWORK_ARGS=() @@ -75,4 +79,4 @@ done xcodebuild -create-xcframework \ "${XCFRAMEWORK_ARGS[@]}" \ - -output "../target/LiveKitFFI.xcframework" + -output "../target/${XCFRAMEWORK_NAME}.xcframework" From 97b4b409af6d3e38f71d37e6bde7699c3aa1948a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C5=82az=CC=87ej=20Pankowski?= <86720177+pblazej@users.noreply.github.com> Date: Fri, 17 Oct 2025 14:11:07 +0200 Subject: [PATCH 7/7] Add minimal Package.swift --- livekit-uniffi/Package.swift | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 livekit-uniffi/Package.swift diff --git a/livekit-uniffi/Package.swift b/livekit-uniffi/Package.swift new file mode 100644 index 000000000..5af5626ff --- /dev/null +++ b/livekit-uniffi/Package.swift @@ -0,0 +1,36 @@ +// swift-tools-version:6.0 +// (Xcode16.0+) + +// For local testing, run ./swift.sh to generate the xcframework + +import PackageDescription + +let package = Package( + name: "LiveKitFFI", + platforms: [ + .iOS(.v13), + .macOS(.v10_15), + .macCatalyst(.v14), + .visionOS(.v2), + .tvOS(.v17), + ], + products: [ + .library( + name: "LiveKitFFI", + targets: ["LiveKitFFI"] + ) + ], + targets: [ + .binaryTarget( + name: "LiveKitFFIBinary", + path: "../target/LiveKitFFI.xcframework" + ), + .target( + name: "LiveKitFFI", + dependencies: ["LiveKitFFIBinary"], + path: "generated/swift", + sources: ["livekit_uniffi.swift"], + publicHeadersPath: "." + ) + ] +)