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
7676 const isCurrentPlatform = (t: Target) =>
7777 t.os === process.platform && t.arch === process.arch && !t.abi;
7878
79+/** Resolve the platform-specific secure-exec-v8 binary for a given target. */
80+const 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+
79103 // ---------------------------------------------------------------------------
80104 // Build web app
81105 // ---------------------------------------------------------------------------
@@ -231,6 +255,14 @@ const buildBinaries = async (targets: Target[]) => { · 149 unmodified lines
231255 // Copy QuickJS WASM next to binary — loaded at runtime by the server
232256 await cp(quickJsWasmPath, join(binDir, "emscripten-module.wasm"));
233257
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+
234266 // Smoke test on current platform
235267 if (isCurrentPlatform(target)) {
236268 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 imports
1+// Ensure binaries next to the executor (e.g. secure-exec-v8) are on $PATH
22 import { dirname, join } from "node:path";
3−const wasmOnDisk = join(dirname(process.execPath), "emscripten-module.wasm");
3+const execDir = dirname(process.execPath);
4+if (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
9+const wasmOnDisk = join(execDir, "emscripten-module.wasm");
410 if (typeof Bun !== "undefined" && await Bun.file(wasmOnDisk).exists()) {
511 const { setQuickJSModule } = await import("@executor/runtime-quickjs");
612 const { newQuickJSWASMModule } = await import("quickjs-emscripten");