farmcontrol-server/scripts/build-macos.mjs
Tom Butcher 8741a2c6fd
Some checks failed
farmcontrol/farmcontrol-server/pipeline/head There was a failure building this commit
Enhance build configuration and scripts
- Updated electrobun.config.ts to include environment-based settings for stability and external dependencies.
- Refactored package.json scripts for improved build processes and streamlined commands.
- Added new build scripts for Linux and renderer, while removing the obsolete build-server script.
- Enhanced pre-build validation to ensure required files are present and added logging for better visibility.
- Updated clean-build script to remove additional artifact directories for thorough cleanup.
2026-08-01 21:13:51 +01:00

56 lines
1.5 KiB
JavaScript

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 getElectrobunInvocation(targetArch) {
const electrobunArgs = ["electrobun", "build", "--env=stable"];
const env = {
...process.env,
ELECTROBUN_ARCH: targetArch,
};
if (targetArch === hostArch) {
return { command: "bun", args: electrobunArgs, env };
}
if (hostArch === "arm64" && targetArch === "x64") {
return { command: "arch", args: ["-x86_64", "bun", ...electrobunArgs], env };
}
if (hostArch === "x64" && targetArch === "arm64") {
return { command: "arch", args: ["-arm64", "bun", ...electrobunArgs], env };
}
return null;
}
for (const targetArch of targetArchs) {
const invocation = getElectrobunInvocation(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, { env: invocation.env });
}