Skip to content
TypeScript

fix(mobile): mobile:install builds on a cache miss for pooled devices, iOS on EAS (#25390)

Julius Marminge91f47a1a27c2
diff --git a/apps/mobile/eas.json b/apps/mobile/eas.json
index 15ae4a15ba4..f694fc8d6ef 100644
--- a/apps/mobile/eas.json
+++ b/apps/mobile/eas.json
@@ -18,6 +18,13 @@
"image": "macos-tahoe-26.6-xcode-27.1"
}
},
+ "development-simulator": {
+ "extends": "development",
+ "ios": {
+ "simulator": true,
+ "image": "macos-tahoe-26.6-xcode-27.1"
+ }
+ },
"preview": {
"corepack": true,
"env": {
diff --git a/apps/mobile/modules/t3-terminal/T3TerminalNative.podspec b/apps/mobile/modules/t3-terminal/T3TerminalNative.podspec
index 2d40f977697..a4123a55503 100644
--- a/apps/mobile/modules/t3-terminal/T3TerminalNative.podspec
+++ b/apps/mobile/modules/t3-terminal/T3TerminalNative.podspec
@@ -14,6 +14,10 @@ Pod::Spec.new do |s|
s.source = { :path => '.' }
s.source_files = 'ios/**/*.{h,m,mm,swift}'
s.vendored_frameworks = 'Vendor/libghostty/GhosttyKit.xcframework'
+ # libghostty has no x86_64 simulator slice, so a simulator build for every
+ # architecture (EAS's generic destination) fails to resolve GhosttyKit.
+ s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'x86_64' }
+ s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'x86_64' }
s.frameworks = 'IOSurface', 'Metal', 'MetalKit', 'QuartzCore', 'UIKit'
s.libraries = 'c++', 'z'
s.swift_version = '5.9'
diff --git a/scripts/mobile-native-client.ts b/scripts/mobile-native-client.ts
index 9af54e71eb7..99f9997db7c 100644
--- a/scripts/mobile-native-client.ts
+++ b/scripts/mobile-native-client.ts
@@ -420,6 +420,11 @@ const decodeUpload = Schema.decodeUnknownEffect(
]),
);
const decodePart = Schema.decodeUnknownEffect(Schema.Struct({ etag: Schema.String }));
+const decodeEasBuilds = Schema.decodeUnknownEffect(
+ Schema.fromJsonString(
+ Schema.Array(Schema.Struct({ artifacts: Schema.Struct({ buildUrl: Schema.String }) })),
+ ),
+);
interface RemoteCache {
readonly url: string;
@@ -621,6 +626,57 @@ const publish = Effect.fn("nativeClient.publish")(function* (staging: string, ta
yield* fs.rename(staging, target);
});
+const easCli = "[email protected]";
+
+/** Xcode builds iOS locally; without it (Linux, or a Mac with no Xcode) EAS builds in the cloud. */
+const hasXcode = Effect.gen(function* () {
+ if ((yield* HostProcess.Platform) !== "darwin") return false;
+ return yield* command("xcrun", ["--find", "xcodebuild"]).pipe(
+ Effect.as(true),
+ Effect.orElseSucceed(() => false),
+ );
+});
+
+/** Without Xcode, EAS builds the same simulator client from this checkout. */
+const buildIosOnEas = Effect.fn("nativeClient.buildIosOnEas")(function* (staging: string) {
+ const fs = yield* FileSystem.FileSystem;
+ const path = yield* Path.Path;
+ // Fail before any work when neither builder is available.
+ yield* command("npx", ["-y", easCli, "whoami"]).pipe(
+ Effect.mapError(
+ () =>
+ new NativeClientError({
+ message:
+ "iOS builds need Xcode on macOS, or an EAS login (`npx eas-cli login`, or EXPO_TOKEN) to build in the cloud.",
+ }),
+ ),
+ );
+ yield* Console.error("No Xcode here; building the iOS simulator client on EAS (10-30 min).");
+ const [build] = yield* decodeEasBuilds(
+ yield* command("npx", [
+ "-y",
+ easCli,
+ "build",
+ "--platform",
+ "ios",
+ "--profile",
+ "development-simulator",
+ "--non-interactive",
+ "--wait",
+ "--json",
+ ]),
+ );
+ if (!build) return yield* new NativeClientError({ message: "EAS returned no build." });
+ const archive = path.join(staging, "eas-build.tar.gz");
+ yield* command("curl", ["-fsSL", "--retry", "3", "-o", archive, build.artifacts.buildUrl]);
+ yield* command("tar", ["-xzf", archive, "-C", staging]);
+ yield* fs.remove(archive);
+ const app = (yield* fs.readDirectory(staging)).find((name) => name.endsWith(".app"));
+ if (!app) return yield* new NativeClientError({ message: "The EAS build archive has no .app." });
+ if (app !== artifactNames.ios)
+ yield* fs.rename(path.join(staging, app), path.join(staging, artifactNames.ios));
+});
+
const build = Effect.fn("nativeClient.build")(function* (
platform: NativePlatform,
abi: string | null,
@@ -640,13 +696,17 @@ const build = Effect.fn("nativeClient.build")(function* (
["exec", "expo", "prebuild", "--clean", "--platform", platform, "--no-install"],
true,
).pipe(Effect.asVoid);
- yield* platform === "android" ? prebuildAndroid(mobile, prebuild) : prebuild;
+ const onEas = platform === "ios" && !(yield* hasXcode);
+ if (platform === "android") yield* prebuildAndroid(mobile, prebuild);
+ else if (!onEas) yield* prebuild;
const staging = yield* fs.makeTempDirectory({
directory: path.dirname(target),
prefix: ".build-",
});
yield* Effect.gen(function* () {
- if (platform === "ios") {
+ if (onEas) {
+ yield* buildIosOnEas(staging);
+ } else if (platform === "ios") {
const output = yield* fs.makeTempDirectoryScoped({ prefix: "t3-native-client-" });
yield* command("pod", ["install"], true, path.join(mobile, "ios"));
// One device-independent arm64 simulator build installs on every iPhone and iPad simulator.
@@ -738,7 +798,6 @@ export const resolveArtifact = Effect.fn("nativeClient.resolveArtifact")(functio
platform: NativePlatform,
abi: string | null,
fingerprint: string,
- allowBuild = true,
) {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
@@ -767,10 +826,6 @@ export const resolveArtifact = Effect.fn("nativeClient.resolveArtifact")(functio
return { ...artifact, source: "remote" as const, buildMs: yield* readBuildMs(directory) };
}
}
- if (!allowBuild)
- return yield* new NativeClientError({
- message: `No shared build of ${key} yet. Run \`vp run mobile:install ${platform}\` once on a machine with a local ${platform === "ios" ? "simulator" : "emulator"} of this checkout; it builds the client and shares it.`,
- });
const log = yield* BuildLog;
yield* Console.error(
`No cached client for ${key}. Building it once for every machine (5-15 min)${log ? `. Log: ${log}` : ""}`,
@@ -865,7 +920,8 @@ const reportTelemetry = Effect.fn("nativeClient.reportTelemetry")(
/**
* Install into an agent-device session the caller already opened (a device pool, a cloud
- * provider, or a local device), using the shared cache only; such hosts cannot build.
+ * provider, or a local device). A cache miss builds here, as for a local device: the device
+ * only runs the client.
*/
const installIntoSession = Effect.fn("nativeClient.installIntoSession")(function* (
home: string,
@@ -890,8 +946,8 @@ const installIntoSession = Effect.fn("nativeClient.installIntoSession")(function
const source = yield* sharedSource(home, key);
// The session's host downloads the client itself; uploading a 166 MB APK through a
// gateway from here takes minutes and can outlast the remote install timeout.
- const fetched = source
- ? yield* command(
+ const downloadOnDevice = source
+ ? command(
node,
[
agentDevice,
@@ -912,13 +968,16 @@ const installIntoSession = Effect.fn("nativeClient.installIntoSession")(function
),
),
)
- : false;
+ : Effect.succeed(false);
+ const fetched = yield* downloadOnDevice;
const artifact = fetched
? { source: "remote" as const, buildMs: 0 }
: yield* Effect.gen(function* () {
- const local = yield* resolveArtifact(home, platform, deviceAbi, current, false).pipe(
+ const local = yield* resolveArtifact(home, platform, deviceAbi, current).pipe(
Effect.tapError(() => reportTelemetry(home, task, "failed", 0)),
);
+ // A build just shared the client, so the device can fetch it now too.
+ if (local.source === "build" && (yield* downloadOnDevice)) return local;
yield* Console.error(`Installing into agent-device session ${session}...`);
yield* command(
node,
@@ -985,6 +1044,11 @@ const main = Command.make(
Flag.withDescription("With --session, open the dev client against this Metro URL."),
Flag.optional,
),
+ prepare: Flag.Boolean("prepare").pipe(
+ Flag.withDescription(
+ "Fetch or build the client for this checkout without a device (Android: for --abi). Run it before leasing a device: a build can outlast the lease.",
+ ),
+ ),
},
Effect.fn("nativeClient.main")(function* ({
mode,
@@ -993,8 +1057,32 @@ const main = Command.make(
session,
abi: sessionAbi,
metro,
+ prepare,
}) {
const started = yield* Clock.currentTimeMillis;
+ if (prepare) {
+ if (mode !== "ensure" || Option.isSome(requested) || Option.isSome(session))
+ return yield* new NativeClientError({
+ message: "--prepare needs no device; use it with ensure and no device id or --session.",
+ });
+ const environment = yield* HostProcess.Environment;
+ const home = environment.HOME ?? environment.USERPROFILE;
+ if (!home)
+ return yield* new NativeClientError({ message: "HOME or USERPROFILE must be set." });
+ const current = yield* fingerprint(platform);
+ const artifact = yield* resolveArtifact(
+ home,
+ platform,
+ platform === "android" ? sessionAbi : null,
+ current,
+ );
+ yield* Console.error(
+ `Client ready for ${platform} (${artifact.source}); lease a device and install.`,
+ );
+ return yield* Console.log(
+ yield* encodeOutput({ status: "ready", source: artifact.source, fingerprint: current }),
+ );
+ }
if (Option.isSome(session)) {
if (mode !== "ensure" || Option.isSome(requested))
return yield* new NativeClientError({