Skip to content

Commit 34e7142

Browse files
committed
fix(build): honor inherited ARM64 executable targets
1 parent 2077ea5 commit 34e7142

4 files changed

Lines changed: 33 additions & 11 deletions

File tree

‎apps/server/scripts/cli.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import { ChildProcess, ChildProcessSpawner } from "effect/process";
1111

1212
import { DEVELOPMENT_ICON_OVERRIDES } from "../../../scripts/lib/brand-assets.ts";
1313
import { findEsmImportsOfExternalPackages } from "../../../scripts/lib/cli-executable-imports.ts";
14-
import { buildLinuxArm64Sea, isLinuxArm64SeaTarget } from "../../../scripts/lib/cli-sea.ts";
14+
import {
15+
buildLinuxArm64Sea,
16+
isLinuxArm64SeaTarget,
17+
resolveCliExecutableTarget,
18+
} from "../../../scripts/lib/cli-sea.ts";
1519
import rootPackageJson from "../../../package.json" with { type: "json" };
1620
import { resolveSpawnCommand } from "@t3tools/shared/shell";
1721
import {
@@ -119,17 +123,15 @@ const buildExeCmd = Command.make(
119123
const serverDir = path.join(repoRoot, "apps/server");
120124

121125
yield* Effect.log("[cli] Building single-executable...");
126+
const target = yield* resolveCliExecutableTarget(Option.getOrUndefined(config.target));
122127
const spawnCommand = yield* resolveSpawnCommand("vp", ["pack"]);
123128
yield* runCommand(
124129
ChildProcess.make(spawnCommand.command, spawnCommand.args, {
125130
cwd: serverDir,
126131
env: {
127132
...process.env,
128133
T3CODE_PACK_EXE: "1",
129-
...Option.match(config.target, {
130-
onNone: () => ({}),
131-
onSome: (target) => ({ T3CODE_PACK_EXE_TARGET: target }),
132-
}),
134+
T3CODE_PACK_EXE_TARGET: target ?? "",
133135
},
134136
stdout: config.verbose ? "inherit" : "ignore",
135137
stderr: "inherit",
@@ -143,7 +145,6 @@ const buildExeCmd = Command.make(
143145
if (specifiers.length > 0) {
144146
return yield* new ServerCliExecutableImportError({ bundlePath, specifiers });
145147
}
146-
const target = Option.getOrUndefined(config.target)?.trim();
147148
if (yield* isLinuxArm64SeaTarget(target)) {
148149
yield* buildLinuxArm64Sea({
149150
bundlePath,

‎apps/server/vite.config.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { defineConfig, mergeConfig } from "vite-plus";
44

55
import baseConfig from "../../vite.config.ts";
66
import { loadRepoEnv } from "../../scripts/lib/public-config.ts";
7-
import { isLinuxArm64SeaTarget } from "../../scripts/lib/cli-sea.ts";
7+
import { isLinuxArm64SeaTarget, resolveCliExecutableTarget } from "../../scripts/lib/cli-sea.ts";
88
import rootPackageJson from "../../package.json" with { type: "json" };
99
import packageJson from "./package.json" with { type: "json" };
1010
import { WeightedShardSequencer } from "./src/testUtils/weightedShardSequencer.ts";
@@ -40,7 +40,7 @@ const SEA_TARGETS = {
4040
"win-arm64": { platform: "win", arch: "arm64" },
4141
"win-x64": { platform: "win", arch: "x64" },
4242
} as const;
43-
const packExecutableTarget = process.env.T3CODE_PACK_EXE_TARGET?.trim();
43+
const packExecutableTarget = Effect.runSync(resolveCliExecutableTarget());
4444
const cliNodeVersion = rootPackageJson.engines.node;
4545
if (packExecutable && !packExecutableTarget && process.versions.node !== cliNodeVersion) {
4646
throw new Error(

‎scripts/lib/cli-sea.test.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { describe, expect, it } from "@effect/vitest";
22
import * as Effect from "effect/Effect";
33
import * as HostProcess from "@t3tools/shared/HostProcess";
4-
import { isLinuxArm64SeaTarget, assertLinuxArm64PageCompatibility } from "./cli-sea.ts";
4+
import {
5+
isLinuxArm64SeaTarget,
6+
assertLinuxArm64PageCompatibility,
7+
resolveCliExecutableTarget,
8+
} from "./cli-sea.ts";
59

610
function elf(loads: Array<{ offset: bigint; address: bigint; size: bigint }>) {
711
const bytes = new Uint8Array(64 + loads.length * 56);
@@ -64,6 +68,16 @@ describe("Linux ARM64 SEA page compatibility", () => {
6468
});
6569
});
6670

71+
it.effect("uses the inherited executable target unless the CLI overrides it", () =>
72+
Effect.gen(function* () {
73+
expect(yield* resolveCliExecutableTarget()).toBe("linux-arm64");
74+
expect(yield* resolveCliExecutableTarget(" win-x64 ")).toBe("win-x64");
75+
expect(yield* resolveCliExecutableTarget("")).toBeUndefined();
76+
}).pipe(
77+
Effect.provideService(HostProcess.Environment, { T3CODE_PACK_EXE_TARGET: " linux-arm64 " }),
78+
),
79+
);
80+
6781
it.effect("selects native ARM64 and explicit cross-target builds", () =>
6882
Effect.gen(function* () {
6983
expect(

‎scripts/lib/cli-sea.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ class CliSeaBuildError extends Schema.TaggedError<CliSeaBuildError>()("CliSeaBui
1313

1414
const encodeConfig = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown));
1515

16+
export const resolveCliExecutableTarget = Effect.fn("resolveCliExecutableTarget")(function* (
17+
target?: string,
18+
) {
19+
const env = yield* HostProcess.Environment;
20+
return (target ?? env.T3CODE_PACK_EXE_TARGET)?.trim() || undefined;
21+
});
22+
1623
export const isLinuxArm64SeaTarget = Effect.fn("isLinuxArm64SeaTarget")(function* (
1724
target?: string,
1825
) {
@@ -66,7 +73,7 @@ export function assertLinuxArm64PageCompatibility(bytes: Uint8Array) {
6673
if (ranges.length === 0) throw new Error("ELF executable has no LOAD segments.");
6774
}
6875

69-
// Node 26.12.1's built-in injector relocates ARM64 segments on 4 KiB boundaries.
76+
// nodejs/node#65564: Node 26.12.1's injector relocates ARM64 segments on 4 KiB boundaries.
7077
// Keep its security-fixed runtime and blob format, but use postject's ELF layout.
7178
export const buildLinuxArm64Sea = Effect.fn("buildLinuxArm64Sea")(function* (input: {
7279
bundlePath: string;
@@ -119,7 +126,7 @@ const runSeaCommand = Effect.fn("runSeaCommand")(function* (args: Array<string>)
119126
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
120127
const child = yield* spawner.spawn(
121128
ChildProcess.make(process.execPath, args, {
122-
stdout: "ignore",
129+
stdout: "inherit",
123130
stderr: "inherit",
124131
}),
125132
);

0 commit comments

Comments
 (0)