Skip to content

Commit 4bd2cad

Browse files
committed
replaced pre-built binary with automated Rust build script
Removed the committed tc_helper.framework/tc_helper binary and replaced it with an automated Xcode build phase ('Build and Embed Rust Framework') that compiles the Rust library from source on every build using cargo. - Added Frameworks/tc_helper.framework/tc_helper to macos/.gitignore - Build phase runs cargo build --release --target aarch64-apple-darwin, packages the output as a .framework, and embeds it into the app bundle - Errors with a clear message if Rust/cargo is not installed
1 parent b71efce commit 4bd2cad

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

macos/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
# Xcode-related
66
**/dgph
77
**/xcuserdata/
8+
9+
# Rust-compiled native framework (built automatically by the Xcode build phase)
10+
Frameworks/tc_helper.framework/tc_helper
-22.3 MB
Binary file not shown.

macos/Runner.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,25 +364,25 @@
364364
shellPath = /bin/sh;
365365
shellScript = "echo \"$PRODUCT_NAME.app\" > \"$PROJECT_DIR\"/Flutter/ephemeral/.app_filename && \"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh embed\n";
366366
};
367-
B47EAE0DA7514E2B9140D50B /* Embed Rust Framework */ = {
367+
B47EAE0DA7514E2B9140D50B /* Build and Embed Rust Framework */ = {
368368
isa = PBXShellScriptBuildPhase;
369+
alwaysOutOfDate = 1;
369370
buildActionMask = 2147483647;
370371
files = (
371372
);
372373
inputFileListPaths = (
373374
);
374375
inputPaths = (
375-
"$(SRCROOT)/Frameworks/tc_helper.framework/tc_helper",
376376
);
377-
name = "Embed Rust Framework";
377+
name = "Build and Embed Rust Framework";
378378
outputFileListPaths = (
379379
);
380380
outputPaths = (
381381
"$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/tc_helper.framework/tc_helper",
382382
);
383383
runOnlyForDeploymentPostprocessing = 0;
384384
shellPath = /bin/sh;
385-
shellScript = "set -e\n\n# Build the Rust library if the framework binary doesn't exist or source is newer\nRUST_DIR=\"$SRCROOT/../rust\"\nFRAMEWORK_SRC=\"$SRCROOT/Frameworks/tc_helper.framework\"\nFRAMEWORK_BIN=\"$FRAMEWORK_SRC/tc_helper\"\nRUST_LIB=\"$RUST_DIR/target/aarch64-apple-darwin/release/libtc_helper.dylib\"\n\nif [ ! -f \"$FRAMEWORK_BIN\" ] || [ \"$RUST_DIR/src/api.rs\" -nt \"$FRAMEWORK_BIN\" ]; then\n echo \"Building Rust tc_helper library...\"\n export PATH=\"$HOME/.cargo/bin:$PATH\"\n rustup target add aarch64-apple-darwin 2>/dev/null || true\n cargo build --release --target aarch64-apple-darwin --manifest-path \"$RUST_DIR/Cargo.toml\"\n mkdir -p \"$FRAMEWORK_SRC\"\n cp -f \"$RUST_LIB\" \"$FRAMEWORK_BIN\"\n install_name_tool -id \"@rpath/tc_helper.framework/tc_helper\" \"$FRAMEWORK_BIN\"\nfi\n\n# Embed the framework into the app bundle\nFRAMEWORK_DST=\"$BUILT_PRODUCTS_DIR/$FRAMEWORKS_FOLDER_PATH/tc_helper.framework\"\nmkdir -p \"$FRAMEWORK_DST\"\ncp -f \"$FRAMEWORK_BIN\" \"$FRAMEWORK_DST/tc_helper\"\ncodesign --force --sign \"$EXPANDED_CODE_SIGN_IDENTITY\" --preserve-metadata=identifier,entitlements \"$FRAMEWORK_DST/tc_helper\" 2>/dev/null || true\n";
385+
shellScript = "set -e\n\nRUST_DIR=\"$SRCROOT/../rust\"\nFRAMEWORK_DIR=\"$SRCROOT/Frameworks/tc_helper.framework\"\nRUST_LIB=\"$RUST_DIR/target/aarch64-apple-darwin/release/libtc_helper.dylib\"\n\nexport PATH=\"$HOME/.cargo/bin:$PATH\"\n\nif ! command -v cargo &>/dev/null; then\n echo 'error: cargo not found. Install Rust from https://rustup.rs' >&2\n exit 1\nfi\n\nrustup target add aarch64-apple-darwin 2>/dev/null || true\ncargo build --release --target aarch64-apple-darwin --manifest-path \"$RUST_DIR/Cargo.toml\"\n\nmkdir -p \"$FRAMEWORK_DIR\"\ncp -f \"$RUST_LIB\" \"$FRAMEWORK_DIR/tc_helper\"\ninstall_name_tool -id \"@rpath/tc_helper.framework/tc_helper\" \"$FRAMEWORK_DIR/tc_helper\"\n\nFRAMEWORK_DST=\"$BUILT_PRODUCTS_DIR/$FRAMEWORKS_FOLDER_PATH/tc_helper.framework\"\nmkdir -p \"$FRAMEWORK_DST\"\ncp -f \"$FRAMEWORK_DIR/tc_helper\" \"$FRAMEWORK_DST/tc_helper\"\ncodesign --force --sign \"$EXPANDED_CODE_SIGN_IDENTITY\" --preserve-metadata=identifier,entitlements \"$FRAMEWORK_DST/tc_helper\" 2>/dev/null || true\n";
386386
};
387387
33CC111E2044C6BF0003C045 /* ShellScript */ = {
388388
isa = PBXShellScriptBuildPhase;

0 commit comments

Comments
 (0)