MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / buildBinaries

Function buildBinaries

apps/cli/src/build.ts:368–521  ·  view source on GitHub ↗
(targets: Target[], mode: BuildMode)

Source from the content-addressed store, hash-verified

366const EMBEDDED_MIGRATIONS_STUB = `const migrations: Record<string, string> | null = null;\n\nexport default migrations;\n`;
367
368const buildBinaries = async (targets: Target[], mode: BuildMode) => {
369 const meta = await readMetadata();
370 const binaries: Record<string, string> = {};
371 const embeddedWebUIPath = join(cliRoot, "src/embedded-web-ui.gen.ts");
372 const embeddedMigrationsPath = join(webRoot, "src/db/embedded-migrations.gen.ts");
373
374 await rm(distDir, { recursive: true, force: true });
375
376 // Cross-platform builds need every target's optional native packages
377 // (e.g. @napi-rs/keyring-darwin-arm64) so we can copy the right .node next
378 // to each target's executor. `bun install --frozen-lockfile --cpu=* --os=*`
379 // extracts them all without modifying the lockfile.
380 const needsCrossPlatform = targets.some((t) => !isCurrentPlatform(t));
381 if (needsCrossPlatform) {
382 console.log("Installing optional native deps for all platforms...");
383 const proc = Bun.spawn(["bun", "install", "--frozen-lockfile", "--cpu=*", "--os=*"], {
384 cwd: repoRoot,
385 stdio: ["ignore", "inherit", "inherit"],
386 });
387 if ((await proc.exited) !== 0) {
388 throw new Error("bun install --cpu=* --os=* failed");
389 }
390 }
391
392 console.log(`Generating embedded web UI bundle (${mode})...`);
393 const embeddedWebUI = await createEmbeddedWebUISource(mode);
394 await writeFile(embeddedWebUIPath, `${embeddedWebUI}\n`);
395
396 console.log("Generating embedded drizzle migrations...");
397 const embeddedMigrations = await createEmbeddedMigrationsSource();
398 await writeFile(embeddedMigrationsPath, `${embeddedMigrations}\n`);
399
400 const quickJsWasmPath = resolveQuickJsWasmPath();
401 const onePasswordCoreWasmPath = resolveOnePasswordCoreWasmPath();
402 const workerBundlerDistPath = resolveWorkerBundlerDistPath();
403 const packedWorkerBundlerSource = await createPackedWorkerBundlerSource(workerBundlerDistPath);
404
405 try {
406 for (const target of targets) {
407 const name = targetPackageName(target);
408 const outDir = join(distDir, name);
409 const binDir = join(outDir, "bin");
410 await mkdir(binDir, { recursive: true });
411
412 console.log(`Building ${name}...`);
413
414 await Bun.build({
415 entrypoints: [join(cliRoot, "src/main.ts")],
416 minify: mode === "production",
417 compile: {
418 target: bunTarget(target),
419 outfile: join(binDir, binaryName(target)),
420 },
421 });
422
423 // Copy QuickJS WASM next to binary — loaded at runtime by the server
424 await cp(quickJsWasmPath, join(binDir, "emscripten-module.wasm"));
425

Callers 1

build.tsFile · 0.85

Calls 15

readMetadataFunction · 0.85
isCurrentPlatformFunction · 0.85
resolveQuickJsWasmPathFunction · 0.85
targetPackageNameFunction · 0.85
bunTargetFunction · 0.85
binaryNameFunction · 0.85
resolveKeyringNativeFunction · 0.85

Tested by

no test coverage detected