Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(ios): isolate Xcode native tools from Nix builds (#7637)

Peter Chinmandf813317b881
diff --git a/apps/web/justfile b/apps/web/justfile
index cc5fa1f84c..7005674673 100644
--- a/apps/web/justfile
+++ b/apps/web/justfile
@@ -12,20 +12,14 @@ android-build *ARGS:
# beforeDevCommand's environment, and the --config merge points the webview's
# devUrl at the same port.
ios-dev: ios-prepare
- #!/usr/bin/env bash
- set -euo pipefail
- PORT="${PORT:-3000}"
- cd tauri/src-tauri && cargo tauri ios dev --open \
- --config "{\"build\":{\"devUrl\":\"http://localhost:${PORT}\"}}" \
- -- --no-default-features
+ bash scripts/ios-dev.sh
-# iOS: prod-facing build, with bundle auto-update turned off, for testing locally on actual iPhone
-ios-build-no-update: ios-prepare
- cd tauri/src-tauri && cargo tauri ios build --open -- --no-default-features
+# Compatibility alias for `just ios-build --no-update`.
+ios-build-no-update: (ios-build "--no-update")
-# iOS: build for release
-ios-build: ios-prepare
- cd tauri/src-tauri && cargo tauri ios build --open
+# iOS: build for release; --no-update disables automatic bundle updates.
+ios-build *ARGS: ios-prepare
+ bash scripts/ios-build.sh "$@"
# iOS: arm64 Simulator .app for the Appetize PR preview (the `ios_preview`
# workflow). Simulator builds need no signing, and --no-default-features keeps
@@ -43,6 +37,7 @@ ios-build-sim prebuilt="false": ios-prepare
#!/usr/bin/env bash
set -euo pipefail
if [ "{{prebuilt}}" != "true" ]; then just build-tauri-dev; fi
+ export TMPDIR="$(/usr/bin/getconf DARWIN_USER_TEMP_DIR)"
# frontendDist is restated because this override replaces the build table:
# dropping it silently produces an app with an empty assets/ and no
# index.html, which installs and launches to a black screen.
@@ -72,6 +67,12 @@ dev-tauri: ensure-cache-wasm
printf development > tauri/src-tauri/.macro-tauri-env
bun run --bun dev
+# iOS prepares WASM before switching to Apple's native compiler and linker.
+[private]
+dev-tauri-prepared:
+ printf development > tauri/src-tauri/.macro-tauri-env
+ bun run --bun dev:server
+
# List available local service names
local-services:
@sed -n "s/.*'\([a-z][-a-z]*\)':.*/\1/p" src/lib/core/constant/servers.ts | sort -u
diff --git a/apps/web/package.json b/apps/web/package.json
index a6246871a9..b14c6ee532 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -4,7 +4,9 @@
"private": true,
"type": "module",
"scripts": {
- "dev": "just ensure-cache-wasm && just ensure-agent-fold-wasm && just ensure-database-sql-wasm && just ensure-pptx-engine-wasm && just ensure-docx-engine-wasm && just ensure-fig-engine-wasm && just ensure-psd-engine-wasm && just ensure-ai-engine-wasm && vite -c vite.config.ts",
+ "dev": "bun run dev:prepare && bun run dev:server",
+ "dev:prepare": "just ensure-cache-wasm && just ensure-agent-fold-wasm && just ensure-database-sql-wasm && just ensure-pptx-engine-wasm && just ensure-docx-engine-wasm && just ensure-fig-engine-wasm && just ensure-psd-engine-wasm && just ensure-ai-engine-wasm",
+ "dev:server": "vite -c vite.config.ts",
"build": "vite build -c vite.config.ts && bun run postbuild:semver && bun run postbuild:bundle-manifest",
"postbuild:semver": "echo $npm_package_version+$(git rev-parse --short HEAD) > ./dist/semver.txt",
"postbuild:bundle-manifest": "bun ./scripts/write-bundle-manifest.mjs",
diff --git a/apps/web/scripts/ios-build.sh b/apps/web/scripts/ios-build.sh
new file mode 100644
index 0000000000..40efd3ae4e
--- /dev/null
+++ b/apps/web/scripts/ios-build.sh
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+no_update=false
+for arg in "$@"; do
+ case "$arg" in
+ --no-update) no_update=true ;;
+ -h|--help) echo "Usage: just ios-build [--no-update]"; exit 0 ;;
+ *) echo "Unknown option: $arg. Usage: just ios-build [--no-update]" >&2; exit 2 ;;
+ esac
+done
+set --
+if [[ "$no_update" == true ]]; then
+ set -- -- --no-default-features
+fi
+
+script_dir="$(\cd "$(dirname "$0")" && pwd)"
+\cd "$script_dir/.."
+
+source "$script_dir/ios-native-env.sh"
+ios_resolve_toolchain aarch64-apple-ios
+
+# The web/WASM build keeps its original toolchain. Switch to Apple tools only
+# for the native build, and skip Tauri's hook because it has already run here.
+just build-tauri
+
+ios_activate_toolchain
+
+\cd tauri/src-tauri
+exec "$ios_cargo" tauri ios build --open \
+ --config '{"build":{"beforeBuildCommand":"","frontendDist":"../../dist"}}' "$@"
diff --git a/apps/web/scripts/ios-dev.sh b/apps/web/scripts/ios-dev.sh
new file mode 100644
index 0000000000..2a8e3cfd99
--- /dev/null
+++ b/apps/web/scripts/ios-dev.sh
@@ -0,0 +1,18 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+script_dir="$(\cd "$(dirname "$0")" && pwd)"
+\cd "$script_dir/.."
+source "$script_dir/ios-native-env.sh"
+ios_resolve_toolchain aarch64-apple-ios-sim
+
+# WASM preparation needs the original Nix environment. Tauri owns the Vite
+# process through beforeDevCommand, so it still stops with the dev session.
+bun run dev:prepare
+ios_activate_toolchain
+export PORT="${PORT:-3000}"
+
+\cd tauri/src-tauri
+exec "$ios_cargo" tauri ios dev --open \
+ --config "{\"build\":{\"devUrl\":\"http://localhost:${PORT}\",\"beforeDevCommand\":{\"script\":\"just dev-tauri-prepared\",\"cwd\":\"../..\"}}}" \
+ -- --no-default-features
diff --git a/apps/web/scripts/ios-native-env.sh b/apps/web/scripts/ios-native-env.sh
new file mode 100644
index 0000000000..d25b6a31b7
--- /dev/null
+++ b/apps/web/scripts/ios-native-env.sh
@@ -0,0 +1,51 @@
+#!/usr/bin/env bash
+# Source this helper before frontend preparation, then activate only for native work.
+
+ios_resolve_toolchain() {
+ # Nix's DEVELOPER_DIR can point at its macOS-only SDK. Honor an explicit
+ # Xcode selection, otherwise use the system selection without Nix's override.
+ ios_developer_dir="${DEVELOPER_DIR:-}"
+ case "$ios_developer_dir" in
+ ""|/nix/store/*)
+ ios_developer_dir="$(/usr/bin/env -u DEVELOPER_DIR /usr/bin/xcode-select -p)"
+ ;;
+ esac
+ if [[ ! -d "$ios_developer_dir/Platforms/iPhoneOS.platform" ]]; then
+ echo "iOS builds require full Xcode; select it with xcode-select or DEVELOPER_DIR." >&2
+ exit 1
+ fi
+ ios_cc="$(DEVELOPER_DIR="$ios_developer_dir" /usr/bin/xcrun --sdk iphoneos --find clang)"
+ ios_cxx="$(DEVELOPER_DIR="$ios_developer_dir" /usr/bin/xcrun --sdk iphoneos --find clang++)"
+
+ # Keep the selected Rust toolchain, including Nix's pinned Fenix toolchain.
+ # Its iOS standard libraries are declared in the root rust-toolchain.toml;
+ # Nix's rustup shim cannot install it into an already-running dev shell.
+ ios_cargo="$(command -v cargo)"
+ ios_rustc="$(command -v "${RUSTC:-${CARGO_BUILD_RUSTC:-rustc}}")"
+ ios_rust_target="${1:?Rust target is required}"
+ ios_rust_libdir="$("$ios_rustc" --print target-libdir --target "$ios_rust_target")"
+ if ! compgen -G "$ios_rust_libdir/libstd-*.rlib" > /dev/null; then
+ echo "The active Rust toolchain is missing $ios_rust_target: $ios_rust_libdir" >&2
+ echo "Re-enter nix develop to load the updated rust-toolchain.toml, or install the target with rustup if building outside Nix." >&2
+ exit 1
+ fi
+}
+
+ios_activate_toolchain() {
+ export DEVELOPER_DIR="$ios_developer_dir"
+ export CC="$ios_cc" CXX="$ios_cxx"
+ export CC_aarch64_apple_ios="$ios_cc" CXX_aarch64_apple_ios="$ios_cxx"
+ export CC_aarch64_apple_ios_sim="$ios_cc" CXX_aarch64_apple_ios_sim="$ios_cxx"
+ # Tauri forwards PATH to the Xcode build via its options server, but not CC/CXX.
+ # cargo-mobile also sets CC=clang, so absolute compiler variables alone do not
+ # protect builds launched with --open. Include Apple's linker and Xcode tools.
+ export PATH="$(dirname "$ios_cc"):$DEVELOPER_DIR/usr/bin:$(dirname "$ios_cargo"):/usr/bin:$PATH"
+ # CARGO_BUILD_* is forwarded through Tauri's options server to Xcode. Keep
+ # explicit compiler overrides consistent with the selected Cargo toolchain.
+ export RUSTC="$ios_rustc" CARGO_BUILD_RUSTC="$ios_rustc"
+ unset SDKROOT MACOSX_DEPLOYMENT_TARGET NIX_CFLAGS_COMPILE NIX_LDFLAGS
+ # Tauri locates its options server via a file in TMPDIR before it can restore
+ # the CLI environment. Xcode can retain a previous nix develop shell's TMPDIR.
+ # Use the same per-user directory as the Xcode build phase.
+ export TMPDIR="$(/usr/bin/getconf DARWIN_USER_TEMP_DIR)"
+}
diff --git a/apps/web/tauri/src-tauri/README.md b/apps/web/tauri/src-tauri/README.md
index e5d1bd854b..66f449eeff 100644
--- a/apps/web/tauri/src-tauri/README.md
+++ b/apps/web/tauri/src-tauri/README.md
@@ -24,6 +24,14 @@ single `vite.config.ts`.
You can override the dev server host for devices/emulators by exporting
`TAURI_DEV_HOST` before running `cargo tauri …`.
+From `apps/web`, use `just ios-dev` (or `PORT=3001 just ios-dev`) to open Xcode
+with the native toolchain configured. It prepares WASM with the original shell
+environment, then uses the same Xcode compiler/linker setup as `just ios-build`.
+This also applies to macOS build scripts and proc macros compiled for the host;
+mixing Nix's linker with Xcode's SDK can fail with `library not found for -liconv`.
+Tauri starts and manages the Vite server after preparation. Keep `just ios-dev`
+running while building in Xcode, and restart it after changing these scripts.
+
Default native logging keeps Turso at `warn`, including Debug builds: its
per-record/page debug spans are expensive through iOS OS activity logging.
Application and Tao debug logs remain enabled in Debug builds. An explicit
@@ -104,6 +112,32 @@ The `beforeBuildCommand` is `just build-tauri`, which runs `bun run build` and
emits the frontend into `dist`. Tauri then packages that output
according to `tauri.conf.json`.
+From `apps/web`, use `just ios-build` for a release build or
+`just ios-build --no-update` to disable automatic bundle updates.
+`just ios-build-no-update` remains a compatibility alias. Both modes build the
+frontend with the current shell's toolchain, then select Xcode's compiler,
+linker, and tools for the native build and the opened Xcode session. This avoids
+Nix's macOS compiler wrapper injecting `-mmacos-version-min` into an iOS build.
+The system `xcode-select` selection is used unless `DEVELOPER_DIR` explicitly
+selects an Xcode installation. Keep the recipe running while building in Xcode
+so Tauri's options server can supply the build configuration and tool paths.
+The native build keeps the selected Rust toolchain and forwards its compiler
+to Xcode. Both device and simulator targets are declared in the root
+`rust-toolchain.toml`, which also defines Nix's pinned Fenix toolchain. Re-enter
+`nix develop` after pulling target changes; Nix's `rustup` shim cannot install
+targets into an existing shell. The launcher fails early if the device standard
+library is missing. These are local Xcode build recipes; reproducible release
+builds also require a pinned Xcode/SDK environment.
+
+The iOS recipes and Xcode's Rust build phase both set `TMPDIR` to macOS's
+per-user temporary directory (`getconf DARWIN_USER_TEMP_DIR`). Tauri CLI finds
+its options server there before restoring the build environment. Inheriting
+Nix's shell-specific `TMPDIR` can leave Xcode connecting to a stale server after
+restarting `nix develop`, even while the new CLI process is running. Keep the
+build phase in `gen/apple/project.yml` and the generated project in sync.
+For direct `cargo tauri ios` invocations from Nix, first run
+`export TMPDIR="$(/usr/bin/getconf DARWIN_USER_TEMP_DIR)"` as well.
+
The Rust library emits `staticlib` for iOS and `cdylib` for Android. Cargo emits
both outputs on iOS, but Xcode links only the static archive into the app.
CallKit's Swift package is part of Xcode's dependency graph, so `build.rs` permits
diff --git a/apps/web/tauri/src-tauri/gen/apple/app.xcodeproj/project.pbxproj b/apps/web/tauri/src-tauri/gen/apple/app.xcodeproj/project.pbxproj
index 3770349cf6..ca576f2713 100644
--- a/apps/web/tauri/src-tauri/gen/apple/app.xcodeproj/project.pbxproj
+++ b/apps/web/tauri/src-tauri/gen/apple/app.xcodeproj/project.pbxproj
@@ -414,7 +414,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
- shellScript = "export PATH=\"$PATH:$HOME/.cargo/bin\" && cargo tauri ios xcode-script -v --platform ${PLATFORM_DISPLAY_NAME:?} --sdk-root ${SDKROOT:?} --framework-search-paths \"${FRAMEWORK_SEARCH_PATHS:?}\" --header-search-paths \"${HEADER_SEARCH_PATHS:?}\" --gcc-preprocessor-definitions \"${GCC_PREPROCESSOR_DEFINITIONS:-}\" --configuration ${CONFIGURATION:?} ${FORCE_COLOR} ${ARCHS:?}";
+ shellScript = "export TMPDIR=\"$(/usr/bin/getconf DARWIN_USER_TEMP_DIR)\" && export PATH=\"$PATH:$HOME/.cargo/bin\" && cargo tauri ios xcode-script -v --platform ${PLATFORM_DISPLAY_NAME:?} --sdk-root ${SDKROOT:?} --framework-search-paths \"${FRAMEWORK_SEARCH_PATHS:?}\" --header-search-paths \"${HEADER_SEARCH_PATHS:?}\" --gcc-preprocessor-definitions \"${GCC_PREPROCESSOR_DEFINITIONS:-}\" --configuration ${CONFIGURATION:?} ${FORCE_COLOR} ${ARCHS:?}";
};
/* End PBXShellScriptBuildPhase section */
diff --git a/apps/web/tauri/src-tauri/gen/apple/project.yml b/apps/web/tauri/src-tauri/gen/apple/project.yml
index 209643a5fe..f5c922375e 100644
--- a/apps/web/tauri/src-tauri/gen/apple/project.yml
+++ b/apps/web/tauri/src-tauri/gen/apple/project.yml
@@ -126,7 +126,7 @@ targets:
- sdk: UIKit.framework
- sdk: WebKit.framework
preBuildScripts:
- - script: export PATH="$PATH:$HOME/.cargo/bin" && cargo tauri ios xcode-script -v --platform ${PLATFORM_DISPLAY_NAME:?} --sdk-root ${SDKROOT:?} --framework-search-paths "${FRAMEWORK_SEARCH_PATHS:?}" --header-search-paths "${HEADER_SEARCH_PATHS:?}" --gcc-preprocessor-definitions "${GCC_PREPROCESSOR_DEFINITIONS:-}" --configuration ${CONFIGURATION:?} ${FORCE_COLOR} ${ARCHS:?}
+ - script: export TMPDIR="$(/usr/bin/getconf DARWIN_USER_TEMP_DIR)" && export PATH="$PATH:$HOME/.cargo/bin" && cargo tauri ios xcode-script -v --platform ${PLATFORM_DISPLAY_NAME:?} --sdk-root ${SDKROOT:?} --framework-search-paths "${FRAMEWORK_SEARCH_PATHS:?}" --header-search-paths "${HEADER_SEARCH_PATHS:?}" --gcc-preprocessor-definitions "${GCC_PREPROCESSOR_DEFINITIONS:-}" --configuration ${CONFIGURATION:?} ${FORCE_COLOR} ${ARCHS:?}
name: Build Rust Code
basedOnDependencyAnalysis: false
outputFiles:
diff --git a/nix-support/node_modules-hashes.json b/nix-support/node_modules-hashes.json
index 073ecd4cba..6839c2ba30 100644
--- a/nix-support/node_modules-hashes.json
+++ b/nix-support/node_modules-hashes.json
@@ -1,6 +1,6 @@
{
"nodeModules": {
- "aarch64-darwin": "sha256-YiP+wyya4oBzCkpI1oSUTejEkDzwI9WBnRhknUHWpP0=",
- "x86_64-linux": "sha256-OQsCo5YuMw3rX+wuDd1dXbht+wgUyBYAFiXCDcY3iOE="
+ "aarch64-darwin": "sha256-tjUS6Z66ykQJ+FmBB+TYmrxbur3wu7f5iJbnaZNVieA=",
+ "x86_64-linux": "sha256-egI40KcIhudsvS0EkjSMOi0gnAy6cKwG/vfxi7W8Wow="
}
}
diff --git a/rust-toolchain.toml b/rust-toolchain.toml
index ba277d9173..7f73f5851c 100644
--- a/rust-toolchain.toml
+++ b/rust-toolchain.toml
@@ -14,11 +14,12 @@ targets = [
# whatever distro they have, so it must not link a host libc.
"aarch64-unknown-linux-musl",
"x86_64-unknown-linux-musl",
- # The arm64 iOS Simulator slice for the Appetize PR preview
- # (see `ios_preview`). It has to live here rather than in the workflow: the
+ # Physical iOS devices and the arm64 Simulator (including ios_preview).
+ # These must live here rather than in a build script: the
# Nix dev shell's `rustup` is a shim whose `target add` silently exits 0, so
# installing it from a CI step would appear to succeed and then fail at link
# time.
+ "aarch64-apple-ios",
"aarch64-apple-ios-sim",
# Signed Android APKs in the production release workflow.
"aarch64-linux-android",