Merge pull request #3012 from StarbirdTech/build/mobile-build-improvements

build: add mobile-dev profile, fix metro watcher and NDK config
This commit is contained in:
Jamie Pine
2026-02-06 00:40:13 -08:00
committed by GitHub
6 changed files with 45 additions and 21 deletions

View File

@@ -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

View File

@@ -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] })
),
},
};

View File

@@ -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

View File

@@ -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<SVGProps<SVGSVGElement>>;
import type { FC } from "react";
const content: FC<Record<string, unknown>>;
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;
}

View File

@@ -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"

View File

@@ -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),