History

don't detach server

Rhys Sullivan committed 7 months ago

Commit a73cc4b1 parent 3f4bd392 files · +40 −2Browse files

Unified · Split

2 files
  1. apps/cli/src/build.ts +32 −0
  2. apps/cli/src/main.ts +8 −2
apps/cli/src/build.ts+32−0
@@ -76,6 +76,30 @@ const binaryName = (t: Target) => · 75 unmodified lines
76const isCurrentPlatform = (t: Target) =>76const isCurrentPlatform = (t: Target) =>
77 t.os === process.platform && t.arch === process.arch && !t.abi;77 t.os === process.platform && t.arch === process.arch && !t.abi;
78 78
79/** Resolve the platform-specific secure-exec-v8 binary for a given target. */
80const resolveSecureExecV8 = (t: Target): string | null => {
81 const platformMap: Record<string, string> = {
82 "darwin-arm64": "@secure-exec/v8-darwin-arm64",
83 "darwin-x64": "@secure-exec/v8-darwin-x64",
84 "linux-arm64": "@secure-exec/v8-linux-arm64-gnu",
85 "linux-x64": "@secure-exec/v8-linux-x64-gnu",
86 };
87 const key = `${t.os}-${t.arch}`;
88 const pkg = platformMap[key];
89 if (!pkg) return null;
90 try {
91 // Resolve from @secure-exec/v8 which has these as optional deps
92 const req = createRequire(join(repoRoot, "node_modules", "secure-exec", "package.json"));
93 const pkgJson = req.resolve(`${pkg}/package.json`);
94 return join(dirname(pkgJson), "secure-exec-v8");
95 } catch {
96 // Try bun's flat node_modules layout
97 const bunPath = join(repoRoot, `node_modules/.bun/${pkg.replace("/", "+")}@0.2.1/node_modules/${pkg}/secure-exec-v8`);
98 if (existsSync(bunPath)) return bunPath;
99 return null;
100 }
101};
102
79// ---------------------------------------------------------------------------103// ---------------------------------------------------------------------------
80// Build web app104// Build web app
81// ---------------------------------------------------------------------------105// ---------------------------------------------------------------------------
@@ -231,6 +255,14 @@ const buildBinaries = async (targets: Target[]) => { · 149 unmodified lines
231 // Copy QuickJS WASM next to binary — loaded at runtime by the server255 // Copy QuickJS WASM next to binary — loaded at runtime by the server
232 await cp(quickJsWasmPath, join(binDir, "emscripten-module.wasm"));256 await cp(quickJsWasmPath, join(binDir, "emscripten-module.wasm"));
233 257
258 // Copy secure-exec-v8 binary next to executor — needed for code execution
259 const secureExecBin = resolveSecureExecV8(target);
260 if (secureExecBin && existsSync(secureExecBin)) {
261 const destName = target.os === "win32" ? "secure-exec-v8.exe" : "secure-exec-v8";
262 await cp(secureExecBin, join(binDir, destName));
263 await chmod(join(binDir, destName), 0o755);
264 }
265
234 // Smoke test on current platform266 // Smoke test on current platform
235 if (isCurrentPlatform(target)) {267 if (isCurrentPlatform(target)) {
236 const bin = join(binDir, binaryName(target));268 const bin = join(binDir, binaryName(target));
apps/cli/src/main.ts+8−2
@@ -1,6 +1,12 @@
1// Pre-load QuickJS WASM for compiled binaries — must run before server imports1// Ensure binaries next to the executor (e.g. secure-exec-v8) are on $PATH
2import { dirname, join } from "node:path";2import { dirname, join } from "node:path";
3const wasmOnDisk = join(dirname(process.execPath), "emscripten-module.wasm");3const execDir = dirname(process.execPath);
4if (process.env.PATH && !process.env.PATH.includes(execDir)) {
5 process.env.PATH = `${execDir}:${process.env.PATH}`;
6}
7
8// Pre-load QuickJS WASM for compiled binaries — must run before server imports
9const wasmOnDisk = join(execDir, "emscripten-module.wasm");
4if (typeof Bun !== "undefined" && await Bun.file(wasmOnDisk).exists()) {10if (typeof Bun !== "undefined" && await Bun.file(wasmOnDisk).exists()) {
5 const { setQuickJSModule } = await import("@executor/runtime-quickjs");11 const { setQuickJSModule } = await import("@executor/runtime-quickjs");
6 const { newQuickJSWASMModule } = await import("quickjs-emscripten");12 const { newQuickJSWASMModule } = await import("quickjs-emscripten");