-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·44 lines (35 loc) · 1.98 KB
/
build.sh
File metadata and controls
executable file
·44 lines (35 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env bash
set -euo pipefail
# --- paths matching your tree ---
CRATE_DIR="native_rust_lib" # contains Cargo.toml
CRATE_NAME="native_rust_lib"
HEADERS_DIR="$(pwd)/headers/" # should contain native_rust_lib.h AND module.modulemap
OUT_DIR="$(pwd)/modules/rust-module/ios/Frameworks" # final *.xcframework goes here
# --- sanity checks ---
[ -f "$CRATE_DIR/Cargo.toml" ] || { echo "❌ $CRATE_DIR/Cargo.toml not found"; exit 1; }
[ -f "$HEADERS_DIR/native_rust_lib.h" ] || { echo "❌ $HEADERS_DIR/native_rust_lib.h not found"; exit 1; }
[ -f "$HEADERS_DIR/module.modulemap" ] || { echo "❌ $HEADERS_DIR/module.modulemap not found"; exit 1; }
# --- toolchains ---
rustup target add aarch64-apple-ios aarch64-apple-ios-sim x86_64-apple-ios >/dev/null || true
# --- build (from repo root using manifest path) ---
cargo build --manifest-path "$CRATE_DIR/Cargo.toml" --release --target aarch64-apple-ios
cargo build --manifest-path "$CRATE_DIR/Cargo.toml" --release --target aarch64-apple-ios-sim
cargo build --manifest-path "$CRATE_DIR/Cargo.toml" --release --target x86_64-apple-ios
# --- locate libs ---
LIB_DEV="$CRATE_DIR/target/aarch64-apple-ios/release/lib${CRATE_NAME}.a"
LIB_SIM_ARM64="$CRATE_DIR/target/aarch64-apple-ios-sim/release/lib${CRATE_NAME}.a"
LIB_SIM_X64="$CRATE_DIR/target/x86_64-apple-ios/release/lib${CRATE_NAME}.a"
# --- universal simulator (arm64 + x86_64) ---
UNIVERSAL_SIM_LIB="$CRATE_DIR/target/universal-sim/lib${CRATE_NAME}.a"
mkdir -p "$(dirname "$UNIVERSAL_SIM_LIB")"
lipo -create -output "$UNIVERSAL_SIM_LIB" "$LIB_SIM_ARM64" "$LIB_SIM_X64"
# --- package xcframework ---
rm -rf "$OUT_DIR/${CRATE_NAME}.xcframework"
mkdir -p "$OUT_DIR"
xcodebuild -create-xcframework \
-library "$LIB_DEV" -headers "$HEADERS_DIR" \
-library "$UNIVERSAL_SIM_LIB" -headers "$HEADERS_DIR" \
-output "$OUT_DIR/${CRATE_NAME}.xcframework"
echo "✅ Created $OUT_DIR/${CRATE_NAME}.xcframework"
rm -rf "$CRATE_DIR/target"
echo "✅ Cleaned up target directory"