Skip to content

Commit 77ff1d7

Browse files
authored
Merge pull request #3012 from StarbirdTech/build/mobile-build-improvements
build: add mobile-dev profile, fix metro watcher and NDK config
2 parents 2a2901e + 5c4b000 commit 77ff1d7

6 files changed

Lines changed: 45 additions & 21 deletions

File tree

Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,13 @@ lto = true # Enables link to optimizations
143143
opt-level = "s" # Optimize for binary size
144144
panic = "unwind" # Sadly we need unwind to avoid unexpected crashes on third party crates
145145
strip = true # Remove debug symbols
146+
147+
# Fast mobile development profile - trades binary size for build speed
148+
# Use with: cargo build --profile mobile-dev
149+
# For production mobile releases, use --release instead
150+
[profile.mobile-dev]
151+
inherits = "release"
152+
codegen-units = 16 # Allow parallel compilation (vs 1 in release)
153+
lto = false # Disable link-time optimization (saves 15-20 min per arch)
154+
opt-level = 2 # Good optimization without extreme size focus
155+
strip = true # Still remove debug symbols

apps/mobile/metro.config.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ const workspaceRoot = path.resolve(projectRoot, "../..");
77

88
const config = getDefaultConfig(projectRoot);
99

10-
// Watch entire monorepo for hot reload
11-
config.watchFolders = [workspaceRoot];
10+
// Watch only relevant directories for hot reload (not entire monorepo)
11+
// This avoids watching Rust target/ dirs (4.5GB+) and other build artifacts
12+
config.watchFolders = [
13+
path.resolve(projectRoot, "src"),
14+
path.resolve(workspaceRoot, "packages"),
15+
];
1216

1317
// Configure resolver for monorepo and SVG support
1418
config.resolver = {
@@ -25,17 +29,18 @@ config.resolver = {
2529
path.resolve(workspaceRoot, "node_modules"),
2630
],
2731

28-
// Exclude build outputs and prevent loading wrong React version from root
32+
// Exclude build outputs
2933
blockList: [
3034
/\/apps\/mobile\/ios\/build\/.*/,
3135
/\/apps\/mobile\/android\/build\/.*/,
32-
// Block React from workspace root to force local version
33-
new RegExp(`^${workspaceRoot}/node_modules/react/.*`),
3436
],
3537

36-
// Force React resolution from mobile app's node_modules
38+
// Dynamically resolve React/React Native from wherever the package manager installed them
3739
extraNodeModules: {
38-
react: path.resolve(projectRoot, "node_modules/react"),
40+
react: path.dirname(require.resolve("react/package.json", { paths: [projectRoot, workspaceRoot] })),
41+
"react-native": path.dirname(
42+
require.resolve("react-native/package.json", { paths: [projectRoot, workspaceRoot] })
43+
),
3944
},
4045
};
4146

apps/mobile/modules/sd-mobile-core/ios/build-rust.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,14 @@ pwd
1717
export CFLAGS_aarch64_apple_ios="-fno-stack-check -fno-stack-protector"
1818
export CFLAGS_aarch64_apple_ios_sim="-fno-stack-check -fno-stack-protector"
1919

20-
# Clean aws-lc-sys build cache to avoid stale cmake state
21-
echo "Cleaning aws-lc-sys build cache..."
22-
rm -rf apps/mobile/modules/sd-mobile-core/core/target/aarch64-apple-ios/release/build/aws-lc-sys-* || true
23-
rm -rf apps/mobile/modules/sd-mobile-core/core/target/aarch64-apple-ios-sim/release/build/aws-lc-sys-* || true
20+
# Clean aws-lc-sys build cache if requested (fixes stale cmake state when
21+
# switching between device/simulator or after Xcode updates)
22+
# Usage: export CLEAN_AWS_LC=1 before building in Xcode, or: CLEAN_AWS_LC=1 bun run ios
23+
if [ "${CLEAN_AWS_LC:-0}" = "1" ]; then
24+
echo "Cleaning aws-lc-sys build cache..."
25+
rm -rf target/aarch64-apple-ios/release/build/aws-lc-sys-* || true
26+
rm -rf target/aarch64-apple-ios-sim/release/build/aws-lc-sys-* || true
27+
fi
2428

2529
# Run xtask to build mobile libraries
2630
cargo xtask build-mobile

packages/assets/types.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ declare module "@sd/assets/images/*.jpg" {
2121
}
2222

2323
declare module "@sd/assets/svgs/*.svg" {
24-
import type { FC, SVGProps } from "react";
25-
const content: FC<SVGProps<SVGSVGElement>>;
24+
import type { FC } from "react";
25+
const content: FC<Record<string, unknown>>;
2626
export default content;
2727
}
2828

@@ -32,7 +32,7 @@ declare module "@sd/assets/videos/*.mp4" {
3232
}
3333

3434
declare module "@sd/assets/sounds/*.mp3" {
35-
const value: string;
35+
const value: number | string; // number on React Native (asset ID), string on web (URL)
3636
export default value;
3737
}
3838

packages/ts-client/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@
2121
"types": "./src/hooks/index.ts",
2222
"default": "./src/hooks/index.ts"
2323
},
24+
"./hooks/useClient": {
25+
"types": "./src/hooks/useClient.tsx",
26+
"default": "./src/hooks/useClient.tsx"
27+
},
28+
"./hooks/useNormalizedQuery": {
29+
"types": "./src/hooks/useNormalizedQuery.ts",
30+
"default": "./src/hooks/useNormalizedQuery.ts"
31+
},
2432
"./src/hooks/useClient": {
2533
"types": "./src/hooks/useClient.tsx",
2634
"default": "./src/hooks/useClient.tsx"

xtask/src/config.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,13 @@ pub fn generate_cargo_config(
120120
protoc,
121121
mobile_native_deps,
122122
android_ndk_home,
123+
// Android NDK host tag - the prebuilt directory is always named darwin-x86_64 on macOS,
124+
// but the binaries are universal (fat) binaries with native ARM64 support.
125+
// Google kept the path name for backwards compatibility.
123126
host_tag: match system.os {
124127
Os::Windows => "windows-x86_64",
125128
Os::Linux => "linux-x86_64",
126-
Os::MacOS => {
127-
if cfg!(target_arch = "aarch64") {
128-
"darwin-aarch64"
129-
} else {
130-
"darwin-x86_64"
131-
}
132-
}
129+
Os::MacOS => "darwin-x86_64",
133130
},
134131
is_win: matches!(system.os, Os::Windows),
135132
is_macos: matches!(system.os, Os::MacOS),

0 commit comments

Comments
 (0)