From cfd7a4b32b46bb3ac518d98521ceb9a88c7cba76 Mon Sep 17 00:00:00 2001 From: KhooLy <73142442+KhooLy@users.noreply.github.com> Date: Mon, 20 Jul 2026 03:24:44 +0300 Subject: [PATCH] Enable rquickjs bindgen against the correct Apple SDK per target MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit rquickjs-sys has no prebuilt FFI bindings for iOS/tvOS targets, so bindgen needs the matching SDK sysroot (iphoneos/iphonesimulator/ appletvos/appletvsimulator) and clang target triple per cross-compiled target, or it silently uses the host's own headers and fails. Unverified here — no Xcode/macOS available in this environment; needs confirming on a real Mac before relying on it. --- .../scripts/build-rust-core-xcframework.sh | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/appleApp/scripts/build-rust-core-xcframework.sh b/appleApp/scripts/build-rust-core-xcframework.sh index 1f4c71f..a868895 100755 --- a/appleApp/scripts/build-rust-core-xcframework.sh +++ b/appleApp/scripts/build-rust-core-xcframework.sh @@ -13,11 +13,56 @@ else cargo_profile="debug" fi +apple_sdk_for_rust_target() { + case "$1" in + aarch64-apple-ios) echo "iphoneos" ;; + aarch64-apple-ios-sim | x86_64-apple-ios) echo "iphonesimulator" ;; + aarch64-apple-tvos) echo "appletvos" ;; + aarch64-apple-tvos-sim) echo "appletvsimulator" ;; + *) echo "" ;; + esac +} + +apple_clang_triple_for_rust_target() { + case "$1" in + aarch64-apple-ios) echo "arm64-apple-ios" ;; + aarch64-apple-ios-sim) echo "arm64-apple-ios-simulator" ;; + x86_64-apple-ios) echo "x86_64-apple-ios-simulator" ;; + aarch64-apple-tvos) echo "arm64-apple-tvos" ;; + aarch64-apple-tvos-sim) echo "arm64-apple-tvos-simulator" ;; + *) echo "" ;; + esac +} + build_rust_core() { + local rust_target="" + local prev_was_target_flag=0 + for arg in "$@"; do + if [[ "$prev_was_target_flag" == "1" ]]; then + rust_target="$arg" + break + fi + [[ "$arg" == "--target" ]] && prev_was_target_flag=1 || prev_was_target_flag=0 + done + + local bindgen_env=() + if [[ -n "$rust_target" ]]; then + local sdk clang_triple sdk_path + sdk="$(apple_sdk_for_rust_target "$rust_target")" + clang_triple="$(apple_clang_triple_for_rust_target "$rust_target")" + if [[ -n "$sdk" && -n "$clang_triple" ]]; then + sdk_path="$(xcrun --sdk "$sdk" --show-sdk-path)" + bindgen_env=( + "LIBCLANG_PATH=$(xcode-select -p)/Toolchains/XcodeDefault.xctoolchain/usr/lib" + "BINDGEN_EXTRA_CLANG_ARGS=--target=$clang_triple --sysroot=$sdk_path -isysroot $sdk_path" + ) + fi + fi + if [[ "$profile" == "Release" ]]; then - cargo build --no-default-features --features ios "$@" --release + env "${bindgen_env[@]}" cargo build --no-default-features --features ios "$@" --release else - cargo build --no-default-features --features ios "$@" + env "${bindgen_env[@]}" cargo build --no-default-features --features ios "$@" fi }