Files
kestrove-core/scripts/build-apple.sh
T
samiandClaude Opus 5.5 86e90569f2
ci / test (push) Canceled after 0s
ci / wasm (push) Canceled after 0s
ci / deny (push) Canceled after 0s
ci / fuzz (push) Canceled after 0s
build-apple.sh: kestrove-nmh with a dSYM (App Store Connect wants one per executable)
Built with debug info, symbols extracted with dsymutil (same UUIDs), then the shipped binary stripped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-21 20:20:52 +09:00

54 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Builds KestroveCoreFFI.xcframework + Swift bindings into ../kestrove-apple/Packages/KestroveCore, and the
# universal kestrove-nmh the macOS app embeds to serve the browser extension (Packages/KestroveCore/bin).
set -euo pipefail
cd "$(dirname "$0")/.."
OUT=../kestrove-apple/Packages/KestroveCore
LIB=libkv_ffi.a
rustup target add aarch64-apple-ios aarch64-apple-ios-sim aarch64-apple-darwin x86_64-apple-darwin
# browser-bridge on every slice: the Swift bindings are generated once, so every slice must export the same API.
for t in aarch64-apple-ios aarch64-apple-ios-sim aarch64-apple-darwin x86_64-apple-darwin; do
cargo build -p kv-ffi --release --target "$t" --features browser-bridge
done
export MACOSX_DEPLOYMENT_TARGET=14.0
# The helper's bundle id (embedded Info.plist, see crates/kv-nmh/build.rs): the app's own + ".nmh".
BUNDLE_PREFIX=$(sed -n 's/^ *BUNDLE_PREFIX: *\([A-Za-z0-9.-]*\).*/\1/p' ../kestrove-apple/project.yml | head -1)
export KV_NMH_BUNDLE_ID="${BUNDLE_PREFIX:-app.kestrove}.nmh"
# With debug info and unstripped, so a dSYM can be made (App Store Connect wants one per executable).
for t in aarch64-apple-darwin x86_64-apple-darwin; do
CARGO_PROFILE_RELEASE_DEBUG=true CARGO_PROFILE_RELEASE_STRIP=false cargo build -p kv-nmh --release --target "$t"
done
cargo build -p kv-ffi --features browser-bridge # host dylib for library-mode bindgen
mkdir -p out/swift
cargo run -p kv-ffi --bin uniffi-bindgen -- generate --library target/debug/libkv_ffi.dylib --language swift --out-dir out/swift
mkdir -p out/headers
cp out/swift/kv_ffiFFI.h out/headers/
cp out/swift/kv_ffiFFI.modulemap out/headers/module.modulemap
mkdir -p out/macos
lipo -create target/aarch64-apple-darwin/release/$LIB target/x86_64-apple-darwin/release/$LIB -output out/macos/$LIB
rm -rf "$OUT/KestroveCoreFFI.xcframework"
xcodebuild -create-xcframework \
-library target/aarch64-apple-ios/release/$LIB -headers out/headers \
-library target/aarch64-apple-ios-sim/release/$LIB -headers out/headers \
-library out/macos/$LIB -headers out/headers \
-output "$OUT/KestroveCoreFFI.xcframework"
mkdir -p "$OUT/Sources/KestroveCore"
cp out/swift/kv_ffi.swift "$OUT/Sources/KestroveCore/Generated.swift"
mkdir -p "$OUT/bin"
lipo -create target/aarch64-apple-darwin/release/kestrove-nmh target/x86_64-apple-darwin/release/kestrove-nmh \
-output "$OUT/bin/kestrove-nmh"
# Symbols go to the dSYM (same UUIDs), then the shipped binary is stripped. Mac/embed-nmh.sh puts the dSYM
# into the archive.
rm -rf "$OUT/bin/kestrove-nmh.dSYM"
dsymutil "$OUT/bin/kestrove-nmh" -o "$OUT/bin/kestrove-nmh.dSYM"
strip -x "$OUT/bin/kestrove-nmh"
echo "✅ XCFramework + bindings written to $OUT"