Skip to content

Commit d842671

Browse files
committed
update
1 parent 40fd71b commit d842671

4 files changed

Lines changed: 76 additions & 12 deletions

File tree

CodeApp/Managers/TerminalInstance.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ private struct WasmerDisplayFrame {
1515
let stride: UInt32
1616
let format: UInt32
1717
let data: UnsafePointer<UInt8>?
18-
let dataLen: Int
18+
let dataLen: UInt
1919
let frameID: UInt64
2020
}
2121

2222
private typealias WasmerDisplayFrameCallback =
2323
@convention(c) (
24-
UnsafePointer<WasmerDisplayFrame>?,
24+
UnsafeRawPointer?,
2525
UnsafeMutableRawPointer?
2626
) -> Void
2727

@@ -43,11 +43,11 @@ private func wasmer_display_enqueue_input_event(
4343

4444
private let protonDisplayFrameCallback: WasmerDisplayFrameCallback = { framePointer, userData in
4545
guard let framePointer, let userData else { return }
46-
let frame = framePointer.pointee
46+
let frame = framePointer.bindMemory(to: WasmerDisplayFrame.self, capacity: 1).pointee
4747
guard frame.format == 1, let data = frame.data, frame.dataLen > 0 else { return }
4848

4949
let terminal = Unmanaged<TerminalInstance>.fromOpaque(userData).takeUnretainedValue()
50-
let copiedFrame = Data(bytes: data, count: frame.dataLen)
50+
let copiedFrame = Data(bytes: data, count: Int(frame.dataLen))
5151
terminal.presentProtonFrame(
5252
width: Int(frame.width),
5353
height: Int(frame.height),
@@ -318,7 +318,7 @@ class TerminalInstance: NSObject, WKScriptMessageHandler, WKNavigationDelegate,
318318
_ = wasmer_display_enqueue_input_event(eventType, code, x, y, value, modifiers)
319319
}
320320

321-
private func presentProtonFrame(
321+
fileprivate func presentProtonFrame(
322322
width: Int,
323323
height: Int,
324324
stride: Int,
41.3 MB
Binary file not shown.

wasmer-ios/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@ wasmer-derive = { path = "./wasmer/lib/derive" }
3232
opt-level = "z" # Optimize for size
3333
lto = false # Avoid iOS staticlib bitcode/LTO duplicate-symbol issues
3434
codegen-units = 1 # Better optimization
35-
strip = true # Strip symbols
35+
debug = 0 # Do not emit debug info into archive members
36+
incremental = false # Keep release builds deterministic and compact
37+
panic = "abort" # Remove unwinding tables from the iOS static library
38+
strip = "symbols" # Strip symbols where rustc can do so directly

wasmer-ios/build_xcframework.sh

Lines changed: 67 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,63 @@ fi
5050

5151
export 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
54111
export 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
61118
echo "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
67124
echo "Cleaning previous builds..."
@@ -72,17 +129,20 @@ rm -rf target/universal-sim/release/libwasmer_ios.a
72129
# Build for iOS device (ARM64)
73130
echo "Building for iOS device (aarch64-apple-ios)..."
74131
export 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)
78136
echo "Building for iOS Simulator ARM64 (aarch64-apple-ios-sim)..."
79137
export 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)
83142
echo "Building for iOS Simulator x86_64 (x86_64-apple-ios)..."
84143
export 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)
88148
echo "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
96157
echo "Creating XCFramework..."

0 commit comments

Comments
 (0)