From da878905322825932a6231966c944fee8f48cfd1 Mon Sep 17 00:00:00 2001 From: Ashcon Partovi Date: Thu, 29 May 2025 16:07:35 -0700 Subject: [PATCH] ci: Fix build image step with zig (#20023) --- .buildkite/ci.mjs | 36 ++++++++++++++++++++++-------------- scripts/bootstrap.ps1 | 2 +- scripts/bootstrap.sh | 2 +- scripts/utils.mjs | 36 ++++++++++++++++++++++++++++++++---- 4 files changed, 56 insertions(+), 20 deletions(-) diff --git a/.buildkite/ci.mjs b/.buildkite/ci.mjs index e1d1678671..71eb3b5003 100755 --- a/.buildkite/ci.mjs +++ b/.buildkite/ci.mjs @@ -309,6 +309,19 @@ function getCppAgent(platform, options) { }); } +/** + * @returns {Platform} + */ +function getZigPlatform() { + return { + os: "linux", + arch: "aarch64", + abi: "musl", + distro: "alpine", + release: "3.21", + }; +} + /** * @param {Platform} platform * @param {PipelineOptions} options @@ -322,19 +335,9 @@ function getZigAgent(platform, options) { // queue: "build-zig", // }; - return getEc2Agent( - { - os: "linux", - arch: "aarch64", - abi: "musl", - distro: "alpine", - release: "3.21", - }, - options, - { - instanceType: "r8g.large", - }, - ); + return getEc2Agent(getZigPlatform(), options, { + instanceType: "r8g.large", + }); } /** @@ -1105,6 +1108,11 @@ async function getPipeline(options = {}) { steps.push( ...relevantBuildPlatforms.map(target => { const imageKey = getImageKey(target); + const zigImageKey = getImageKey(getZigPlatform()); + const dependsOn = imagePlatforms.has(zigImageKey) ? [`${zigImageKey}-build-image`] : []; + if (imagePlatforms.has(imageKey)) { + dependsOn.push(`${imageKey}-build-image`); + } return getStepWithDependsOn( { @@ -1114,7 +1122,7 @@ async function getPipeline(options = {}) { ? [getBuildBunStep(target, options)] : [getBuildCppStep(target, options), getBuildZigStep(target, options), getLinkBunStep(target, options)], }, - imagePlatforms.has(imageKey) ? `${imageKey}-build-image` : undefined, + ...dependsOn, ); }), ); diff --git a/scripts/bootstrap.ps1 b/scripts/bootstrap.ps1 index 0947531d23..10e7756f32 100755 --- a/scripts/bootstrap.ps1 +++ b/scripts/bootstrap.ps1 @@ -1,4 +1,4 @@ -# Version: 7 +# Version: 8 # A script that installs the dependencies needed to build and test Bun. # This should work on Windows 10 or newer with PowerShell. diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index 0e706800bf..16ea4089d5 100755 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -1,5 +1,5 @@ #!/bin/sh -# Version: 10 +# Version: 11 # A script that installs the dependencies needed to build and test Bun. # This should work on macOS and Linux with a POSIX shell. diff --git a/scripts/utils.mjs b/scripts/utils.mjs index 7f3e518124..09e3596922 100755 --- a/scripts/utils.mjs +++ b/scripts/utils.mjs @@ -290,7 +290,7 @@ export async function spawn(command, options = {}) { if (exitCode !== 0 && isWindows) { const exitReason = getWindowsExitReason(exitCode); if (exitReason) { - exitCode = exitReason; + signalCode = exitReason; } } @@ -386,7 +386,7 @@ export function spawnSync(command, options = {}) { if (exitCode !== 0 && isWindows) { const exitReason = getWindowsExitReason(exitCode); if (exitReason) { - exitCode = exitReason; + signalCode = exitReason; } } @@ -442,9 +442,37 @@ export function spawnSyncSafe(command, options = {}) { * @returns {string | undefined} */ export function getWindowsExitReason(exitCode) { - const ntStatusPath = "C:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.22621.0\\shared\\ntstatus.h"; - const nthStatus = readFile(ntStatusPath, { cache: true }); + const windowsKitPath = "C:\\Program Files (x86)\\Windows Kits"; + if (!existsSync(windowsKitPath)) { + return; + } + const windowsKitPaths = readdirSync(windowsKitPath) + .filter(filename => isFinite(parseInt(filename))) + .sort((a, b) => parseInt(b) - parseInt(a)); + + let ntStatusPath; + for (const windowsKitPath of windowsKitPaths) { + const includePath = `${windowsKitPath}\\Include`; + if (!existsSync(includePath)) { + continue; + } + + const windowsSdkPaths = readdirSync(includePath).sort(); + for (const windowsSdkPath of windowsSdkPaths) { + const statusPath = `${includePath}\\${windowsSdkPath}\\shared\\ntstatus.h`; + if (existsSync(statusPath)) { + ntStatusPath = statusPath; + break; + } + } + } + + if (!ntStatusPath) { + return; + } + + const nthStatus = readFile(ntStatusPath, { cache: true }); const match = nthStatus.match(new RegExp(`(STATUS_\\w+).*0x${exitCode?.toString(16)}`, "i")); if (match) { const [, exitReason] = match;