From 3a810da66c5ffc3656f122e78b077c9cd8219244 Mon Sep 17 00:00:00 2001 From: Marko Vejnovic Date: Fri, 7 Nov 2025 14:33:26 -0800 Subject: [PATCH] build(ENG-21466): Fix `sccache` not caching across builds (#24423) --- scripts/bootstrap.ps1 | 32 ++++++++++++++++++++++++++++ scripts/bootstrap.sh | 21 +++++++++++++++++- scripts/build.mjs | 3 ++- test/js/node/path/browserify.test.js | 19 +++++++++++------ 4 files changed, 66 insertions(+), 9 deletions(-) diff --git a/scripts/bootstrap.ps1 b/scripts/bootstrap.ps1 index 9c406456fb..5164112d74 100755 --- a/scripts/bootstrap.ps1 +++ b/scripts/bootstrap.ps1 @@ -256,6 +256,30 @@ function Install-Tailscale { Install-Package tailscale } +function Create-Buildkite-Environment-Hooks { + param ( + [Parameter(Mandatory = $true)] + [string]$BuildkiteHome + ) + + Write-Output "Creating Buildkite environment hooks..." + $hooksDir = Join-Path $BuildkiteHome "hooks" + + if (-not (Test-Path $hooksDir)) { + New-Item -Path $hooksDir -ItemType Directory -Force | Out-Null + } + + $environmentHook = Join-Path $hooksDir "environment.ps1" + $buildPath = Join-Path $BuildkiteHome "build" + + @" +# Buildkite environment hook +`$env:BUILDKITE_BUILD_CHECKOUT_PATH = "$buildPath" +"@ | Set-Content -Path $environmentHook -Encoding UTF8 + + Write-Output "Environment hook created at $environmentHook" +} + function Install-Buildkite { if (Which buildkite-agent) { return @@ -266,6 +290,14 @@ function Install-Buildkite { $installScript = Download-File "https://raw.githubusercontent.com/buildkite/agent/main/install.ps1" Execute-Script $installScript Refresh-Path + + if ($CI) { + $buildkiteHome = "C:\buildkite-agent" + if (-not (Test-Path $buildkiteHome)) { + New-Item -Path $buildkiteHome -ItemType Directory -Force | Out-Null + } + Create-Buildkite-Environment-Hooks -BuildkiteHome $buildkiteHome + } } function Install-Build-Essentials { diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index f878589169..f42885d79a 100755 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -1,5 +1,5 @@ #!/bin/sh -# Version: 19 +# Version: 20 # A script that installs the dependencies needed to build and test Bun. # This should work on macOS and Linux with a POSIX shell. @@ -1391,6 +1391,25 @@ create_buildkite_user() { for file in $buildkite_files; do create_file "$file" done + + local opts=$- + set -ef + + # I do not want to use create_file because it creates directories with 777 + # permissions and files with 664 permissions. This is dumb, for obvious + # reasons. + local hook_dir="${home}/hooks" + mkdir -p -m 755 "${hook_dir}"; + cat < "${hook_dir}/environment" +#!/bin/sh +set -efu + +export BUILDKITE_BUILD_CHECKOUT_PATH=${home}/build +EOF + execute_sudo chown -R "$user:$group" "$hook_dir" + execute_sudo chmod 744 "${hook_dir}/environment" + + set +ef -"$opts" } install_buildkite() { diff --git a/scripts/build.mjs b/scripts/build.mjs index e902b85fe9..de1f40d5a7 100755 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -103,7 +103,8 @@ async function build(args) { await startGroup("CMake Build", () => spawn("cmake", buildArgs, { env })); - if (isCI) { + const target = buildOptions["--target"] || buildOptions["-t"]; + if (isCI && target === "build-cpp") { await startGroup("sccache stats", () => { spawn("sccache", ["--show-stats"], { env }); }); diff --git a/test/js/node/path/browserify.test.js b/test/js/node/path/browserify.test.js index a1838f127c..9b53caa26c 100644 --- a/test/js/node/path/browserify.test.js +++ b/test/js/node/path/browserify.test.js @@ -469,7 +469,12 @@ describe("browserify path tests", () => { const failures = []; const cwd = process.cwd(); const cwdParent = path.dirname(cwd); - const parentIsRoot = isWindows ? cwdParent.match(/^[A-Z]:\\$/) : cwdParent === "/"; + const parentIsRoot = (levels = 1) => { + const dir = Array(levels) + .fill() + .reduce(wd => path.dirname(wd), cwd); + return isWindows ? dir.match(/^[a-zA-Z]:\\$/) : dir === "/"; + }; const relativeTests = [ [ @@ -529,19 +534,19 @@ describe("browserify path tests", () => { ["/webp4ck-hot-middleware", "/webpack/buildin/module.js", "../webpack/buildin/module.js"], ["/webpack-hot-middleware", "/webp4ck/buildin/module.js", "../webp4ck/buildin/module.js"], ["/var/webpack-hot-middleware", "/var/webpack/buildin/module.js", "../webpack/buildin/module.js"], - ["/app/node_modules/pkg", "../static", `../../..${parentIsRoot ? "" : path.posix.resolve("../")}/static`], + ["/app/node_modules/pkg", "../static", `../../..${parentIsRoot() ? "" : path.posix.resolve("../")}/static`], [ "/app/node_modules/pkg", "../../static", - `../../..${parentIsRoot ? "" : path.posix.resolve("../../")}/static`, + `../../..${parentIsRoot(2) ? "" : path.posix.resolve("../../")}/static`, ], - ["/app", "../static", `..${parentIsRoot ? "" : path.posix.resolve("../")}/static`], + ["/app", "../static", `..${parentIsRoot() ? "" : path.posix.resolve("../")}/static`], ["/app", "../".repeat(64) + "static", "../static"], [".", "../static", cwd == "/" ? "static" : "../static"], - ["/", "../static", parentIsRoot ? "static" : `${path.posix.resolve("../")}/static`.slice(1)], + ["/", "../static", parentIsRoot() ? "static" : `${path.posix.resolve("../")}/static`.slice(1)], ["../", "../", ""], - ["../", "../../", parentIsRoot ? "" : ".."], - ["../../", "../", parentIsRoot ? "" : path.basename(cwdParent)], + ["../", "../../", parentIsRoot() ? "" : ".."], + ["../../", "../", parentIsRoot() ? "" : path.basename(cwdParent)], ["../../", "../../", ""], ], ],