Compare commits

...

2 Commits

Author SHA1 Message Date
8b8475d11d Add Windows installer files to MSI build process
Some checks failed
farmcontrol/farmcontrol-server/pipeline/head There was a failure building this commit
- Updated the farmcontrol-server.wxs file to include SetupArchive and SetupMetadata files for the MSI packaging.
- Modified the build-windows-msi.ps1 script to accept new parameters for SetupArchive and SetupMetadata, enhancing the MSI build process.
- Refactored the finalize-desktop-artifacts script to find and handle multiple Windows installer files, ensuring proper artifact publication.
2026-08-01 20:04:14 +01:00
90da336696 Update macOS build process and enhance artifact finalization
- Replaced the macOS build command in package.json to use a new script for better architecture handling.
- Added a new script for building macOS applications that supports both arm64 and x64 architectures.
- Enhanced the finalize-desktop-artifacts script to improve artifact discovery and cleanup, ensuring proper handling of macOS DMG and app bundles.
- Updated functions to streamline the process of finding and publishing artifacts, improving overall reliability.
2026-08-01 20:01:55 +01:00
5 changed files with 166 additions and 56 deletions

View File

@ -14,7 +14,7 @@
"build:server": "bun run scripts/build-server.mjs",
"build:renderer": "vite build src/app",
"build:app": "bun run build && electrobun build --env=stable",
"build:app:mac": "bun run build && electrobun build --env=stable",
"build:app:mac": "bun scripts/build-macos.mjs",
"build:linux": "bun run cleanBuild && bun run build:server && bun run build:linux-binary && bun run build:linux-packages",
"build:linux-binary": "bun scripts/build-linux-binary.mjs",
"build:linux-packages": "bash scripts/build-linux-packages.sh",

View File

@ -26,6 +26,8 @@
<DirectoryRef Id="INSTALLFOLDER">
<Component Id="SetupComponent" Guid="*">
<File Id="SetupExe" Source="$(var.SetupExe)" KeyPath="yes" />
<File Id="SetupArchive" Source="$(var.SetupArchive)" />
<File Id="SetupMetadata" Source="$(var.SetupMetadata)" />
</Component>
</DirectoryRef>

53
scripts/build-macos.mjs Normal file
View File

@ -0,0 +1,53 @@
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);
}

View File

@ -2,6 +2,12 @@ param(
[Parameter(Mandatory = $true)]
[string]$SetupExe,
[Parameter(Mandatory = $true)]
[string]$SetupArchive,
[Parameter(Mandatory = $true)]
[string]$SetupMetadata,
[Parameter(Mandatory = $true)]
[string]$OutputMsi,
@ -34,6 +40,14 @@ function Find-WixTool($toolName) {
throw "Could not find $toolName. Install WiX Toolset v3.11 or v3.14 on the Windows build agent."
}
function ConvertTo-WixVersion([string]$rawVersion) {
$parts = $rawVersion.Split('.')
while ($parts.Count -lt 4) {
$parts += '0'
}
return ($parts[0..3] -join '.')
}
$rootDir = Split-Path -Parent $PSScriptRoot
$wxsPath = Join-Path $rootDir "packaging/windows/farmcontrol-server.wxs"
$workDir = Join-Path $env:TEMP "farmcontrol-server-msi"
@ -44,28 +58,22 @@ if (Test-Path $workDir) {
}
New-Item -ItemType Directory -Path $workDir | Out-Null
function ConvertTo-WixVersion([string]$rawVersion) {
$parts = $rawVersion.Split('.')
while ($parts.Count -lt 4) {
$parts += '0'
}
return ($parts[0..3] -join '.')
}
$candle = Find-WixTool "candle"
$light = Find-WixTool "light"
$wixVersion = ConvertTo-WixVersion $Version
$setupExePath = (Resolve-Path -LiteralPath $SetupExe).Path
$setupArchivePath = (Resolve-Path -LiteralPath $SetupArchive).Path
$setupMetadataPath = (Resolve-Path -LiteralPath $SetupMetadata).Path
# Quote -d defines so PowerShell passes them as single args to candle.exe.
# Unquoted -dVersion=$Version is parsed incorrectly; paths with spaces also break.
$candleArgs = @(
'-nologo'
'-out'
$wixObj
"-dVersion=$wixVersion"
"-dSetupExe=$setupExePath"
"-dSetupArchive=$setupArchivePath"
"-dSetupMetadata=$setupMetadataPath"
$wxsPath
)

View File

@ -23,6 +23,7 @@ const packageJson = JSON.parse(
const version = getReleaseVersion(packageJson);
const artifactDir = path.join(rootDir, "app_dist");
const identifier = "com.tombutcher.farmcontrolserver";
const artifactPrefix = `farmcontrol-server-${version}-`;
function walkFiles(dir) {
const files = [];
@ -49,29 +50,43 @@ function findByExtension(root, extension) {
);
}
function findMacAppBundle() {
const buildDir = path.join(rootDir, "build");
if (!existsSync(buildDir)) {
function findMacAppBundle(arch) {
const platformDir = path.join(rootDir, "build", `stable-macos-${arch}`);
if (!existsSync(platformDir)) {
return null;
}
for (const entry of readdirSync(buildDir)) {
if (!entry.startsWith("stable-macos-")) {
continue;
}
const platformDir = path.join(buildDir, entry);
for (const child of readdirSync(platformDir)) {
if (child.endsWith(".app")) {
return path.join(platformDir, child);
}
for (const child of readdirSync(platformDir)) {
if (child.endsWith(".app")) {
return path.join(platformDir, child);
}
}
return null;
}
function findWindowsSetupExe() {
function findMacDmgSource(arch) {
const prefixedArtifact = walkFiles(artifactDir).find(
(filePath) =>
filePath.includes(`stable-macos-${arch}`) &&
filePath.toLowerCase().endsWith(".dmg"),
);
if (prefixedArtifact) {
return prefixedArtifact;
}
const buildDmg = findByExtension(
path.join(rootDir, "build", `stable-macos-${arch}`),
".dmg",
);
if (buildDmg) {
return buildDmg;
}
return findByExtension(artifactDir, ".dmg");
}
function findWindowsInstallerFiles() {
const buildDir = path.join(rootDir, "build");
if (!existsSync(buildDir)) {
return null;
@ -83,20 +98,33 @@ function findWindowsSetupExe() {
}
const platformDir = path.join(buildDir, entry);
const setupExe = walkFiles(platformDir).find((filePath) =>
filePath.toLowerCase().endsWith("-setup.exe"),
const files = walkFiles(platformDir);
const setupExe = files.find((filePath) =>
/-setup\.exe$/i.test(filePath),
);
if (setupExe) {
return setupExe;
const setupArchive = files.find((filePath) =>
/-setup\.tar\.zst$/i.test(filePath),
);
const setupMetadata = files.find((filePath) =>
/-setup\.metadata\.json$/i.test(filePath),
);
const setupZip = files.find((filePath) =>
/-setup\.zip$/i.test(filePath),
);
if (setupExe && setupArchive && setupMetadata) {
return { setupExe, setupArchive, setupMetadata, setupZip };
}
}
return findByExtension(buildDir, "-Setup.exe");
return null;
}
function publishArtifact(sourcePath, arch, ext) {
if (!sourcePath || !existsSync(sourcePath)) {
throw new Error(`Missing source artifact for ${arch}.${ext}: ${sourcePath ?? "not found"}`);
throw new Error(
`Missing source artifact for ${arch}.${ext}: ${sourcePath ?? "not found"}`,
);
}
mkdirSync(artifactDir, { recursive: true });
@ -109,17 +137,24 @@ function publishArtifact(sourcePath, arch, ext) {
return destination;
}
function cleanArtifactDir(keepNames) {
function cleanStagingArtifacts(keepNames) {
if (!existsSync(artifactDir)) {
return;
}
for (const entry of readdirSync(artifactDir)) {
if (keepNames.includes(entry)) {
if (keepNames.includes(entry) || entry.startsWith(artifactPrefix)) {
continue;
}
rmSync(path.join(artifactDir, entry), { recursive: true, force: true });
if (
entry.includes("stable-macos-") ||
entry.includes("stable-win-") ||
entry.endsWith("-update.json") ||
entry.endsWith(".tar.gz")
) {
rmSync(path.join(artifactDir, entry), { recursive: true, force: true });
}
}
}
@ -153,7 +188,7 @@ function buildMacPkg(appBundlePath, arch) {
return pkgPath;
}
function buildWindowsMsi(setupExePath, arch) {
function buildWindowsMsi(installerFiles, arch) {
const scriptPath = path.join(rootDir, "scripts/build-windows-msi.ps1");
const msiPath = path.join(
artifactDir,
@ -179,7 +214,11 @@ function buildWindowsMsi(setupExePath, arch) {
"-File",
scriptPath,
"-SetupExe",
setupExePath,
installerFiles.setupExe,
"-SetupArchive",
installerFiles.setupArchive,
"-SetupMetadata",
installerFiles.setupMetadata,
"-OutputMsi",
msiPath,
"-Version",
@ -196,36 +235,44 @@ function buildWindowsMsi(setupExePath, arch) {
return msiPath;
}
const published = [];
if (process.platform === "darwin") {
const arch = getReleaseArch();
const dmgSource =
findByExtension(artifactDir, ".dmg") ?? findByExtension(path.join(rootDir, "build"), ".dmg");
const appBundle = findMacAppBundle();
const buildArch = getReleaseArch(
process.env.ELECTROBUN_ARCH || process.arch,
);
const dmgSource = findMacDmgSource(buildArch);
const appBundle = findMacAppBundle(buildArch);
if (!dmgSource) {
throw new Error("Could not find a macOS DMG artifact to publish");
}
if (!appBundle) {
throw new Error("Could not find a macOS .app bundle to build a PKG");
if (!dmgSource || !appBundle) {
console.log(
`finalize-desktop-artifacts: no macOS ${buildArch} release artifacts found, skipping`,
);
process.exit(0);
}
published.push(publishArtifact(dmgSource, arch, "dmg"));
published.push(buildMacPkg(appBundle, arch));
const published = [
publishArtifact(dmgSource, buildArch, "dmg"),
buildMacPkg(appBundle, buildArch),
];
cleanStagingArtifacts(published.map((filePath) => path.basename(filePath)));
} else if (process.platform === "win32") {
const arch = "x64";
const setupExe = findWindowsSetupExe();
const installerFiles = findWindowsInstallerFiles();
if (!setupExe) {
throw new Error("Could not find the Windows setup executable to publish");
if (!installerFiles) {
throw new Error(
"Could not find the Windows installer files (setup exe, archive, and metadata)",
);
}
published.push(publishArtifact(setupExe, arch, "exe"));
published.push(buildWindowsMsi(setupExe, arch));
const published = [buildWindowsMsi(installerFiles, arch)];
if (installerFiles.setupZip) {
published.push(publishArtifact(installerFiles.setupZip, arch, "zip"));
}
cleanStagingArtifacts(published.map((filePath) => path.basename(filePath)));
} else {
console.log("finalize-desktop-artifacts: skipping unsupported platform", process.platform);
process.exit(0);
}
cleanArtifactDir(published.map((filePath) => path.basename(filePath)));