diff --git a/apps/chanora_flutter/ios/chanora_bridge.podspec b/apps/chanora_flutter/ios/chanora_bridge.podspec index b547c30..e844627 100644 --- a/apps/chanora_flutter/ios/chanora_bridge.podspec +++ b/apps/chanora_flutter/ios/chanora_bridge.podspec @@ -100,6 +100,52 @@ PLIST # Runner.app/Frameworks/ with Embed & Sign automatically. s.vendored_frameworks = 'Frameworks/chanora_bridge.framework' + # Re-run the cargo build + framework wrap on every Xcode build, + # not only on `pod install`. The `prepare_command` above runs + # once per `pod install` which is too sticky — Rust source + # changes were getting silently ignored because Xcode happily + # re-bundled the stale framework. This script_phase shells out to + # cargo on every Xcode "Build" so the framework is always in sync + # with the current Rust workspace. + # + # `:execution_position => :before_compile` runs the script before + # Xcode's CompileSources phase, so by the time the linker / embed + # step sees `Frameworks/chanora_bridge.framework`, it is fresh. + s.script_phase = { + :name => 'Rebuild chanora_bridge.framework from Rust', + :script => <<-SCRIPT, + set -e + REPO_ROOT="$(cd "${PODS_TARGET_SRCROOT}/../../.." && pwd)" + BRIDGE="$REPO_ROOT/target/aarch64-apple-ios/release/libchanora_bridge.dylib" + + echo "[chanora_bridge script_phase] cargo build aarch64-apple-ios" + cd "$REPO_ROOT" + PATH="$HOME/.cargo/bin:$PATH" \\ + IPHONEOS_DEPLOYMENT_TARGET=13.0 \\ + CMAKE_POLICY_VERSION_MINIMUM=3.5 \\ + CMAKE_OSX_DEPLOYMENT_TARGET=13.0 \\ + cargo build --release --target aarch64-apple-ios -p chanora_bridge + + cd "$REPO_ROOT/apps/chanora_flutter/ios" + FW=Frameworks/chanora_bridge.framework + + # Skip the wrap step if the framework's binary is already + # up-to-date with the cargo output (fast no-op on incremental + # builds where Rust didn't change). + if [ -f "$FW/chanora_bridge" ] && [ "$FW/chanora_bridge" -nt "$BRIDGE" ]; then + echo "[chanora_bridge script_phase] framework already up-to-date" + exit 0 + fi + + mkdir -p "$FW" + cp "$BRIDGE" "$FW/chanora_bridge" + install_name_tool -id "@rpath/chanora_bridge.framework/chanora_bridge" \\ + "$FW/chanora_bridge" + echo "[chanora_bridge script_phase] framework refreshed" + SCRIPT + :execution_position => :before_compile, + } + # The pod has no Objective-C sources; it's purely a framework # carrier. Suppress CocoaPods's source-file warning. s.source_files = 'Frameworks/chanora_bridge.framework/Headers/*.h'