Some checks failed
farmcontrol/farmcontrol-server/pipeline/head There was a failure building this commit
- Introduced a new runBuild function in Jenkinsfile to streamline build command execution across different environments. - Updated package.json to use a new cleanBuild script for improved build cleanup. - Enhanced build-macos.mjs to support architecture-specific builds with better cross-compilation handling. - Added a new clean-build.mjs script for efficient removal of build artifacts.
58 lines
1.5 KiB
JavaScript
58 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;
|
|
}
|
|
|
|
run("bun", ["run", "build"]);
|
|
|
|
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 });
|
|
}
|