5050
5151export PATH=" $( dirname " $CARGO_BIN " ) :$( dirname " $RUSTUP_BIN " ) :/opt/homebrew/opt/llvm/bin:/opt/homebrew/bin:$PATH "
5252
53+ RUST_TOOLCHAIN=" ${WASMER_IOS_TOOLCHAIN:- } "
54+ if [ -n " $RUST_TOOLCHAIN " ]; then
55+ echo " Using Rust toolchain override: $RUST_TOOLCHAIN "
56+ fi
57+
58+ RUSTFLAGS_BASE=" -C debuginfo=0 -C strip=symbols -C embed-bitcode=no -C link-dead-code=no"
59+ if [ " ${WASMER_IOS_Z_SMALL:- 0} " = " 1" ]; then
60+ if [ " $RUST_TOOLCHAIN " != " nightly" ] && [[ " $RUST_TOOLCHAIN " != nightly-* ]]; then
61+ echo " WASMER_IOS_Z_SMALL=1 requires WASMER_IOS_TOOLCHAIN=nightly or a nightly-* toolchain."
62+ exit 1
63+ fi
64+ if ! " $RUSTUP_BIN " run " $RUST_TOOLCHAIN " rustc -Z help 2> /dev/null | grep -qE ' ^[[:space:]]+-Z[[:space:]]+small[=[:space:]]' ; then
65+ echo " The selected nightly toolchain does not support -Zsmall."
66+ echo " Use WASMER_IOS_RUSTFLAGS for supported nightly size flags instead."
67+ exit 1
68+ fi
69+ RUSTFLAGS_BASE=" $RUSTFLAGS_BASE -Zsmall"
70+ fi
71+ export RUSTFLAGS=" ${RUSTFLAGS:- } $RUSTFLAGS_BASE ${WASMER_IOS_RUSTFLAGS:- } "
72+ echo " RUSTFLAGS: $RUSTFLAGS "
73+
74+ cargo_build () {
75+ if [ -n " $RUST_TOOLCHAIN " ]; then
76+ " $RUSTUP_BIN " run " $RUST_TOOLCHAIN " cargo build " $@ "
77+ else
78+ " $CARGO_BIN " build " $@ "
79+ fi
80+ }
81+
82+ rustup_target_add () {
83+ if [ -n " $RUST_TOOLCHAIN " ]; then
84+ " $RUSTUP_BIN " target add --toolchain " $RUST_TOOLCHAIN " " $@ "
85+ else
86+ " $RUSTUP_BIN " target add " $@ "
87+ fi
88+ }
89+
90+ strip_static_library () {
91+ local library=" $1 "
92+ local strip_bin
93+ strip_bin=" $(
94+ command -v llvm-strip 2> /dev/null || \
95+ xcrun -find llvm-strip 2> /dev/null || \
96+ xcrun -find strip 2> /dev/null || \
97+ command -v strip 2> /dev/null || \
98+ true
99+ ) "
100+ if [ -z " $strip_bin " ]; then
101+ echo " warning: strip not found; leaving $library unstripped"
102+ return 0
103+ fi
104+
105+ " $strip_bin " -S -x " $library " 2> /dev/null || \
106+ " $strip_bin " -S " $library " 2> /dev/null || \
107+ echo " warning: could not strip $library "
108+ }
109+
53110# Setup LLVM for bindgen
54111export LLVM_CONFIG_PATH=" ${LLVM_CONFIG_PATH:-/ opt/ homebrew/ opt/ llvm/ bin/ llvm-config} "
55112
@@ -59,9 +116,9 @@ SIM_SDK=$(xcrun --sdk iphonesimulator --show-sdk-path)
59116
60117# Install iOS targets if not already installed
61118echo " Installing Rust iOS targets..."
62- " $RUSTUP_BIN " target add aarch64-apple-ios
63- " $RUSTUP_BIN " target add aarch64-apple-ios-sim
64- " $RUSTUP_BIN " target add x86_64-apple-ios
119+ rustup_target_add aarch64-apple-ios
120+ rustup_target_add aarch64-apple-ios-sim
121+ rustup_target_add x86_64-apple-ios
65122
66123# Clean previous builds
67124echo " Cleaning previous builds..."
@@ -72,17 +129,20 @@ rm -rf target/universal-sim/release/libwasmer_ios.a
72129# Build for iOS device (ARM64)
73130echo " Building for iOS device (aarch64-apple-ios)..."
74131export BINDGEN_EXTRA_CLANG_ARGS=" --target=arm64-apple-ios -isysroot $IOS_SDK "
75- " $CARGO_BIN " build --release --target aarch64-apple-ios
132+ cargo_build --release --target aarch64-apple-ios
133+ strip_static_library target/aarch64-apple-ios/release/libwasmer_ios.a
76134
77135# Build for iOS Simulator (ARM64 - Apple Silicon Macs)
78136echo " Building for iOS Simulator ARM64 (aarch64-apple-ios-sim)..."
79137export BINDGEN_EXTRA_CLANG_ARGS=" --target=arm64-apple-ios-simulator -isysroot $SIM_SDK "
80- " $CARGO_BIN " build --release --target aarch64-apple-ios-sim
138+ cargo_build --release --target aarch64-apple-ios-sim
139+ strip_static_library target/aarch64-apple-ios-sim/release/libwasmer_ios.a
81140
82141# Build for iOS Simulator (x86_64 - Intel Macs)
83142echo " Building for iOS Simulator x86_64 (x86_64-apple-ios)..."
84143export BINDGEN_EXTRA_CLANG_ARGS=" --target=x86_64-apple-ios-simulator -isysroot $SIM_SDK "
85- " $CARGO_BIN " build --release --target x86_64-apple-ios
144+ cargo_build --release --target x86_64-apple-ios
145+ strip_static_library target/x86_64-apple-ios/release/libwasmer_ios.a
86146
87147# Create lipo binary for simulator (combine arm64-sim and x86_64)
88148echo " Creating universal simulator library..."
@@ -91,6 +151,7 @@ lipo -create \
91151 target/aarch64-apple-ios-sim/release/libwasmer_ios.a \
92152 target/x86_64-apple-ios/release/libwasmer_ios.a \
93153 -output target/universal-sim/release/libwasmer_ios.a
154+ strip_static_library target/universal-sim/release/libwasmer_ios.a
94155
95156# Create XCFramework
96157echo " Creating XCFramework..."
0 commit comments