import { spawnSync } from "node:child_process"; import { fileURLToPath } from "node:url"; import path from "node:path"; const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); const hostArch = process.arch === "arm64" ? "arm64" : "x64"; const targetArchs = ["arm64", "x64"]; function run(command, args, options = {}) { const result = spawnSync(command, args, { cwd: rootDir, stdio: "inherit", env: process.env, ...options, }); if (result.status !== 0) { process.exit(result.status ?? 1); } } function getElectrobunCommand(targetArch) { const electrobunArgs = ["electrobun", "build", "--env=stable"]; if (targetArch === hostArch) { return { command: "bun", args: electrobunArgs }; } if (hostArch === "arm64" && targetArch === "x64") { return { command: "arch", args: ["-x86_64", "bun", ...electrobunArgs] }; } if (hostArch === "x64" && targetArch === "arm64") { return { command: "arch", args: ["-arm64", "bun", ...electrobunArgs] }; } return null; } run("bun", ["run", "build"]); for (const targetArch of targetArchs) { const invocation = getElectrobunCommand(targetArch); if (!invocation) { console.warn( `Skipping macOS ${targetArch} build: unsupported cross-compile from ${hostArch}.`, ); continue; } console.log(`\n=== Building macOS ${targetArch} ===\n`); run(invocation.command, invocation.args); }