From 5c4b0007658910093158d06e264b710741570ec3 Mon Sep 17 00:00:00 2001 From: StarbirdTech <64431622+StarbirdTech@users.noreply.github.com> Date: Fri, 6 Feb 2026 03:21:12 -0500 Subject: [PATCH] build: add mobile-dev profile, fix metro watcher and NDK config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a mobile-dev Cargo profile for faster mobile development builds (parallel codegen, no LTO, opt-level 2) — available opt-in via `cargo build --profile mobile-dev`. Production builds use --release. Fix NDK host_tag to always use darwin-x86_64 on macOS since Google ships universal binaries under that path. Make aws-lc-sys cache cleaning opt-in via CLEAN_AWS_LC=1 to enable incremental iOS builds. Scope Metro file watcher to src/ and packages/ instead of the entire monorepo (avoids watching 4.5GB+ Rust target/ dirs) and fix React resolution to use workspace root where bun hoists packages. Apply tembo review feedback from #3011: fix SVG type declarations to avoid DOM dependency, add sound asset type flexibility, and add public subpath exports to ts-client. Co-Authored-By: Claude Opus 4.6 --- Cargo.toml | 10 ++++++++++ apps/mobile/metro.config.js | 19 ++++++++++++------- .../modules/sd-mobile-core/ios/build-rust.sh | 12 ++++++++---- packages/assets/types.d.ts | 6 +++--- packages/ts-client/package.json | 8 ++++++++ xtask/src/config.rs | 11 ++++------- 6 files changed, 45 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3adf18274..47a88fcdd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -143,3 +143,13 @@ lto = true # Enables link to optimizations opt-level = "s" # Optimize for binary size panic = "unwind" # Sadly we need unwind to avoid unexpected crashes on third party crates strip = true # Remove debug symbols + +# Fast mobile development profile - trades binary size for build speed +# Use with: cargo build --profile mobile-dev +# For production mobile releases, use --release instead +[profile.mobile-dev] +inherits = "release" +codegen-units = 16 # Allow parallel compilation (vs 1 in release) +lto = false # Disable link-time optimization (saves 15-20 min per arch) +opt-level = 2 # Good optimization without extreme size focus +strip = true # Still remove debug symbols diff --git a/apps/mobile/metro.config.js b/apps/mobile/metro.config.js index 587efffd2..76838cf0a 100644 --- a/apps/mobile/metro.config.js +++ b/apps/mobile/metro.config.js @@ -7,8 +7,12 @@ const workspaceRoot = path.resolve(projectRoot, "../.."); const config = getDefaultConfig(projectRoot); -// Watch entire monorepo for hot reload -config.watchFolders = [workspaceRoot]; +// Watch only relevant directories for hot reload (not entire monorepo) +// This avoids watching Rust target/ dirs (4.5GB+) and other build artifacts +config.watchFolders = [ + path.resolve(projectRoot, "src"), + path.resolve(workspaceRoot, "packages"), +]; // Configure resolver for monorepo and SVG support config.resolver = { @@ -25,17 +29,18 @@ config.resolver = { path.resolve(workspaceRoot, "node_modules"), ], - // Exclude build outputs and prevent loading wrong React version from root + // Exclude build outputs blockList: [ /\/apps\/mobile\/ios\/build\/.*/, /\/apps\/mobile\/android\/build\/.*/, - // Block React from workspace root to force local version - new RegExp(`^${workspaceRoot}/node_modules/react/.*`), ], - // Force React resolution from mobile app's node_modules + // Dynamically resolve React/React Native from wherever the package manager installed them extraNodeModules: { - react: path.resolve(projectRoot, "node_modules/react"), + react: path.dirname(require.resolve("react/package.json", { paths: [projectRoot, workspaceRoot] })), + "react-native": path.dirname( + require.resolve("react-native/package.json", { paths: [projectRoot, workspaceRoot] }) + ), }, }; diff --git a/apps/mobile/modules/sd-mobile-core/ios/build-rust.sh b/apps/mobile/modules/sd-mobile-core/ios/build-rust.sh index e2ff82b51..76e9132b9 100755 --- a/apps/mobile/modules/sd-mobile-core/ios/build-rust.sh +++ b/apps/mobile/modules/sd-mobile-core/ios/build-rust.sh @@ -17,10 +17,14 @@ pwd export CFLAGS_aarch64_apple_ios="-fno-stack-check -fno-stack-protector" export CFLAGS_aarch64_apple_ios_sim="-fno-stack-check -fno-stack-protector" -# Clean aws-lc-sys build cache to avoid stale cmake state -echo "Cleaning aws-lc-sys build cache..." -rm -rf apps/mobile/modules/sd-mobile-core/core/target/aarch64-apple-ios/release/build/aws-lc-sys-* || true -rm -rf apps/mobile/modules/sd-mobile-core/core/target/aarch64-apple-ios-sim/release/build/aws-lc-sys-* || true +# Clean aws-lc-sys build cache if requested (fixes stale cmake state when +# switching between device/simulator or after Xcode updates) +# Usage: export CLEAN_AWS_LC=1 before building in Xcode, or: CLEAN_AWS_LC=1 bun run ios +if [ "${CLEAN_AWS_LC:-0}" = "1" ]; then + echo "Cleaning aws-lc-sys build cache..." + rm -rf target/aarch64-apple-ios/release/build/aws-lc-sys-* || true + rm -rf target/aarch64-apple-ios-sim/release/build/aws-lc-sys-* || true +fi # Run xtask to build mobile libraries cargo xtask build-mobile diff --git a/packages/assets/types.d.ts b/packages/assets/types.d.ts index b00d697b9..7306a807e 100644 --- a/packages/assets/types.d.ts +++ b/packages/assets/types.d.ts @@ -21,8 +21,8 @@ declare module "@sd/assets/images/*.jpg" { } declare module "@sd/assets/svgs/*.svg" { - import type { FC, SVGProps } from "react"; - const content: FC>; + import type { FC } from "react"; + const content: FC>; export default content; } @@ -32,7 +32,7 @@ declare module "@sd/assets/videos/*.mp4" { } declare module "@sd/assets/sounds/*.mp3" { - const value: string; + const value: number | string; // number on React Native (asset ID), string on web (URL) export default value; } diff --git a/packages/ts-client/package.json b/packages/ts-client/package.json index fd23cc876..82c3beb51 100644 --- a/packages/ts-client/package.json +++ b/packages/ts-client/package.json @@ -21,6 +21,14 @@ "types": "./src/hooks/index.ts", "default": "./src/hooks/index.ts" }, + "./hooks/useClient": { + "types": "./src/hooks/useClient.tsx", + "default": "./src/hooks/useClient.tsx" + }, + "./hooks/useNormalizedQuery": { + "types": "./src/hooks/useNormalizedQuery.ts", + "default": "./src/hooks/useNormalizedQuery.ts" + }, "./src/hooks/useClient": { "types": "./src/hooks/useClient.tsx", "default": "./src/hooks/useClient.tsx" diff --git a/xtask/src/config.rs b/xtask/src/config.rs index c39a7a797..7e8d0bcc0 100644 --- a/xtask/src/config.rs +++ b/xtask/src/config.rs @@ -120,16 +120,13 @@ pub fn generate_cargo_config( protoc, mobile_native_deps, android_ndk_home, + // Android NDK host tag - the prebuilt directory is always named darwin-x86_64 on macOS, + // but the binaries are universal (fat) binaries with native ARM64 support. + // Google kept the path name for backwards compatibility. host_tag: match system.os { Os::Windows => "windows-x86_64", Os::Linux => "linux-x86_64", - Os::MacOS => { - if cfg!(target_arch = "aarch64") { - "darwin-aarch64" - } else { - "darwin-x86_64" - } - } + Os::MacOS => "darwin-x86_64", }, is_win: matches!(system.os, Os::Windows), is_macos: matches!(system.os, Os::MacOS),