From 2f30e1983578691295a69408bc122ad5da4dae0d Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Thu, 1 Aug 2024 18:04:17 -0700 Subject: [PATCH 1/5] Disable LTO on Windows and macOS in BuildKite --- .buildkite/scripts/env.sh | 3 ++- CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.buildkite/scripts/env.sh b/.buildkite/scripts/env.sh index b09f799bf68e0b..91a6b76c73d311 100755 --- a/.buildkite/scripts/env.sh +++ b/.buildkite/scripts/env.sh @@ -86,7 +86,8 @@ function export_environment() { else export CPU_TARGET="haswell" fi - if [[ "$BUILDKITE_STEP_KEY" == *"nolto"* ]]; then + # LTO is disabled on Windows and macOS. + if [[ "$BUILDKITE_STEP_KEY" == *"nolto"* ]] || [[ "$BUILDKITE_STEP_KEY" == *"darwin"* ]] || [[ "$BUILDKITE_STEP_KEY" == *"windows"* ]]; then export USE_LTO="OFF" else export USE_LTO="ON" diff --git a/CMakeLists.txt b/CMakeLists.txt index f85c2c72a3b172..58b3faf1a19ca1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -334,7 +334,7 @@ option(USE_LTO "Enable Link-Time Optimization" ${DEFAULT_LTO}) if(APPLE AND USE_LTO) set(USE_LTO OFF) - message(WARNING "Link-Time Optimization is not supported on macOS because it requires -fuse-ld=lld and lld causes many segfaults on macOS (likely related to stack size)") + message(FATAL_ERROR "Link-Time Optimization is not supported on macOS because it requires -fuse-ld=lld and lld causes many segfaults on macOS (likely related to stack size)") endif() if(WIN32 AND USE_LTO) From c6d508972f789be900558d1989b194140271112d Mon Sep 17 00:00:00 2001 From: Ashcon Partovi Date: Thu, 1 Aug 2024 18:18:56 -0700 Subject: [PATCH 2/5] Deflake some build issues * Disable sccache on Windows * Add workaround for EBUSY/UNKNOWN spawn errors --- .buildkite/ci.yml | 20 +++++++++++---- .buildkite/scripts/env.sh | 11 +++------ CMakeLists.txt | 2 +- scripts/env.ps1 | 7 ++++-- scripts/runner.node.mjs | 51 ++++++++++++++++++++------------------- 5 files changed, 51 insertions(+), 40 deletions(-) diff --git a/.buildkite/ci.yml b/.buildkite/ci.yml index b7aa6f29b23cb2..529cca2e5fe710 100644 --- a/.buildkite/ci.yml +++ b/.buildkite/ci.yml @@ -622,8 +622,9 @@ steps: - "build\\bun-deps\\*.lib" env: SCCACHE_DIR: "$$HOME\\.cache\\sccache" - ZIG_LOCAL_CACHE_DIR: "$$HOME\\.cache\\zig-cache" + CCACHE_DIR: "$$HOME\\.cache\\ccache" SCCACHE_IGNORE_SERVER_IO_ERROR: "1" + CCACHE_DISABLE: "1" command: - ".\\scripts\\all-dependencies.ps1" @@ -646,6 +647,11 @@ steps: # HACK: See scripts/build-bun-cpp.ps1 # - "build\\bun-cpp-objects.a" - "build\\bun-cpp-objects.a.*" + env: + SCCACHE_DIR: "$$HOME\\.cache\\sccache" + CCACHE_DIR: "$$HOME\\.cache\\ccache" + SCCACHE_IGNORE_SERVER_IO_ERROR: "1" + CCACHE_DISABLE: "1" command: - ".\\scripts\\build-bun-cpp.ps1" @@ -665,8 +671,9 @@ steps: - "features.json" env: SCCACHE_DIR: "$$HOME\\.cache\\sccache" - ZIG_LOCAL_CACHE_DIR: "$$HOME\\.cache\\zig-cache" + CCACHE_DIR: "$$HOME\\.cache\\ccache" SCCACHE_IGNORE_SERVER_IO_ERROR: "1" + CCACHE_DISABLE: "1" command: - ".\\scripts\\buildkite-link-bun.ps1" @@ -709,8 +716,9 @@ steps: - "build\\bun-deps\\*.lib" env: SCCACHE_DIR: "$$HOME\\.cache\\sccache" - ZIG_LOCAL_CACHE_DIR: "$$HOME\\.cache\\zig-cache" + CCACHE_DIR: "$$HOME\\.cache\\ccache" SCCACHE_IGNORE_SERVER_IO_ERROR: "1" + CCACHE_DISABLE: "1" USE_BASELINE_BUILD: "1" command: - ".\\scripts\\all-dependencies.ps1" @@ -736,8 +744,9 @@ steps: - "build\\bun-cpp-objects.a.*" env: SCCACHE_DIR: "$$HOME\\.cache\\sccache" - ZIG_LOCAL_CACHE_DIR: "$$HOME\\.cache\\zig-cache" + CCACHE_DIR: "$$HOME\\.cache\\ccache" SCCACHE_IGNORE_SERVER_IO_ERROR: "1" + CCACHE_DISABLE: "1" USE_BASELINE_BUILD: "1" command: - ".\\scripts\\build-bun-cpp.ps1" @@ -758,8 +767,9 @@ steps: - "features.json" env: SCCACHE_DIR: "$$HOME\\.cache\\sccache" - ZIG_LOCAL_CACHE_DIR: "$$HOME\\.cache\\zig-cache" + CCACHE_DIR: "$$HOME\\.cache\\ccache" SCCACHE_IGNORE_SERVER_IO_ERROR: "1" + CCACHE_DISABLE: "1" USE_BASELINE_BUILD: "1" command: - ".\\scripts\\buildkite-link-bun.ps1 -Baseline $$True" diff --git a/.buildkite/scripts/env.sh b/.buildkite/scripts/env.sh index 91a6b76c73d311..73e982e90b5486 100755 --- a/.buildkite/scripts/env.sh +++ b/.buildkite/scripts/env.sh @@ -78,6 +78,7 @@ function export_environment() { export CCACHE_DIR="$HOME/.cache/ccache/$BUILDKITE_STEP_KEY" export SCCACHE_DIR="$HOME/.cache/sccache/$BUILDKITE_STEP_KEY" export ZIG_LOCAL_CACHE_DIR="$HOME/.cache/zig-cache/$BUILDKITE_STEP_KEY" + export ZIG_GLOBAL_CACHE_DIR="$HOME/.cache/zig-cache/$BUILDKITE_STEP_KEY" export BUN_DEPS_CACHE_DIR="$HOME/.cache/bun-deps/$BUILDKITE_STEP_KEY" if [ "$(assert_arch)" == "aarch64" ]; then export CPU_TARGET="native" @@ -86,12 +87,6 @@ function export_environment() { else export CPU_TARGET="haswell" fi - # LTO is disabled on Windows and macOS. - if [[ "$BUILDKITE_STEP_KEY" == *"nolto"* ]] || [[ "$BUILDKITE_STEP_KEY" == *"darwin"* ]] || [[ "$BUILDKITE_STEP_KEY" == *"windows"* ]]; then - export USE_LTO="OFF" - else - export USE_LTO="ON" - fi if $(buildkite-agent meta-data exists release &> /dev/null); then export CMAKE_BUILD_TYPE="$(buildkite-agent meta-data get release)" else @@ -107,11 +102,13 @@ function export_environment() { else export USE_DEBUG_JSC="OFF" fi - if [ "$BUILDKITE_CLEAN_CHECKOUT" == "true" ]; then + if [ "$BUILDKITE_CLEAN_CHECKOUT" == "true" || "$BUILDKITE_BRANCH" == "main" ]; then rm -rf "$CCACHE_DIR" rm -rf "$SCCACHE_DIR" rm -rf "$ZIG_LOCAL_CACHE_DIR" + rm -rf "$ZIG_GLOBAL_CACHE_DIR" rm -rf "$BUN_DEPS_CACHE_DIR" + export CCACHE_RECACHE="1" fi } diff --git a/CMakeLists.txt b/CMakeLists.txt index 58b3faf1a19ca1..d3ff0e8ad172d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -487,7 +487,7 @@ if(USE_UNIFIED_SOURCES) endif() # CCache -find_program(CCACHE_PROGRAM sccache) +# find_program(CCACHE_PROGRAM sccache) find_program(CCACHE_PROGRAM ccache) if(CCACHE_PROGRAM) diff --git a/scripts/env.ps1 b/scripts/env.ps1 index 472065da119d58..3203ad8ec40299 100755 --- a/scripts/env.ps1 +++ b/scripts/env.ps1 @@ -35,7 +35,7 @@ $BUN_DEPS_DIR = if ($env:BUN_DEPS_DIR) { $env:BUN_DEPS_DIR } else { Join-Path $B $BUN_DEPS_OUT_DIR = if ($env:BUN_DEPS_OUT_DIR) { $env:BUN_DEPS_OUT_DIR } else { Join-Path $BUN_BASE_DIR 'build\bun-deps' } $CPUS = if ($env:CPUS) { $env:CPUS } else { (Get-CimInstance -Class Win32_Processor).NumberOfCores } -$Lto = if ($env:USE_LTO) { $env:USE_LTO -eq "1" } else { $True } +$Lto = if ($env:USE_LTO) { $env:USE_LTO -eq "1" } else { $False } $Baseline = if ($env:USE_BASELINE_BUILD) { $env:USE_BASELINE_BUILD -eq "1" } elseif ($env:BUILDKITE_STEP_KEY -match "baseline") { @@ -103,7 +103,10 @@ if ($Lto) { $CMAKE_FLAGS += "-DUSE_LTO=ON" } -if (Get-Command sccache -ErrorAction SilentlyContinue) { +if (Get-Command ccache -ErrorAction SilentlyContinue) { + $CMAKE_FLAGS += "-DCMAKE_C_COMPILER_LAUNCHER=ccache" + $CMAKE_FLAGS += "-DCMAKE_CXX_COMPILER_LAUNCHER=ccache" +} elseif (Get-Command sccache -ErrorAction SilentlyContinue) { # Continue with local compiler if sccache has an error $env:SCCACHE_IGNORE_SERVER_IO_ERROR = "1" diff --git a/scripts/runner.node.mjs b/scripts/runner.node.mjs index 282de4abeafb37..f28a38365cfd16 100755 --- a/scripts/runner.node.mjs +++ b/scripts/runner.node.mjs @@ -134,36 +134,37 @@ async function printInfo() { async function runTests() { let execPath; if (options["step"]) { - execPath = await getExecPathFromBuildKite(options["step"]); + downloadLoop: for (let i = 0; i < 10; i++) { + execPath = await getExecPathFromBuildKite(options["step"]); + for (let j = 0; j < 10; j++) { + const { error } = spawnSync(execPath, ["--version"], { + encoding: "utf-8", + timeout: spawnTimeout, + env: { + PATH: process.env.PATH, + BUN_DEBUG_QUIET_LOGS: 1, + }, + }); + if (!error) { + break; + } + const { code } = error; + if (code === "EBUSY") { + console.log("Bun appears to be busy, retrying..."); + continue; + } + if (code === "UNKNOWN") { + console.log("Bun appears to be corrupted, downloading again..."); + rmSync(execPath, { force: true }); + continue downloadLoop; + } + } + } } else { execPath = getExecPath(options["exec-path"]); } console.log("Bun:", execPath); - for (let i = 0; i < 10; i++) { - try { - const { error } = spawnSync(execPath, ["--version"], { - encoding: "utf-8", - timeout: spawnTimeout, - env: { - PATH: process.env.PATH, - BUN_DEBUG_QUIET_LOGS: 1, - }, - }); - if (!error) { - break; - } - throw error; - } catch (error) { - const { code } = error; - if (code === "EBUSY" || code === "UNKNOWN") { - console.log(`Bun appears to be busy, retrying... [code: ${code}]`); - await new Promise(resolve => setTimeout(resolve, 1000 * (i + 1))); - continue; - } - } - } - const revision = getRevision(execPath); console.log("Revision:", revision); From de64683b2279b3f4434e349f2a017aef8d9309c0 Mon Sep 17 00:00:00 2001 From: Ashcon Partovi Date: Thu, 1 Aug 2024 18:22:52 -0700 Subject: [PATCH 3/5] Fix ccache environment variable --- .buildkite/ci.yml | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/.buildkite/ci.yml b/.buildkite/ci.yml index 529cca2e5fe710..742b19c8ecf0fb 100644 --- a/.buildkite/ci.yml +++ b/.buildkite/ci.yml @@ -621,9 +621,6 @@ steps: artifact_paths: - "build\\bun-deps\\*.lib" env: - SCCACHE_DIR: "$$HOME\\.cache\\sccache" - CCACHE_DIR: "$$HOME\\.cache\\ccache" - SCCACHE_IGNORE_SERVER_IO_ERROR: "1" CCACHE_DISABLE: "1" command: - ".\\scripts\\all-dependencies.ps1" @@ -648,9 +645,6 @@ steps: # - "build\\bun-cpp-objects.a" - "build\\bun-cpp-objects.a.*" env: - SCCACHE_DIR: "$$HOME\\.cache\\sccache" - CCACHE_DIR: "$$HOME\\.cache\\ccache" - SCCACHE_IGNORE_SERVER_IO_ERROR: "1" CCACHE_DISABLE: "1" command: - ".\\scripts\\build-bun-cpp.ps1" @@ -670,9 +664,6 @@ steps: - "bun-windows-x64-profile.zip" - "features.json" env: - SCCACHE_DIR: "$$HOME\\.cache\\sccache" - CCACHE_DIR: "$$HOME\\.cache\\ccache" - SCCACHE_IGNORE_SERVER_IO_ERROR: "1" CCACHE_DISABLE: "1" command: - ".\\scripts\\buildkite-link-bun.ps1" @@ -715,9 +706,6 @@ steps: artifact_paths: - "build\\bun-deps\\*.lib" env: - SCCACHE_DIR: "$$HOME\\.cache\\sccache" - CCACHE_DIR: "$$HOME\\.cache\\ccache" - SCCACHE_IGNORE_SERVER_IO_ERROR: "1" CCACHE_DISABLE: "1" USE_BASELINE_BUILD: "1" command: @@ -743,9 +731,6 @@ steps: # - "build\\bun-cpp-objects.a" - "build\\bun-cpp-objects.a.*" env: - SCCACHE_DIR: "$$HOME\\.cache\\sccache" - CCACHE_DIR: "$$HOME\\.cache\\ccache" - SCCACHE_IGNORE_SERVER_IO_ERROR: "1" CCACHE_DISABLE: "1" USE_BASELINE_BUILD: "1" command: @@ -766,9 +751,6 @@ steps: - "bun-windows-x64-baseline-profile.zip" - "features.json" env: - SCCACHE_DIR: "$$HOME\\.cache\\sccache" - CCACHE_DIR: "$$HOME\\.cache\\ccache" - SCCACHE_IGNORE_SERVER_IO_ERROR: "1" CCACHE_DISABLE: "1" USE_BASELINE_BUILD: "1" command: From f25599a6e863a122a1c771f9fc6d6c46937bfb00 Mon Sep 17 00:00:00 2001 From: Ashcon Partovi Date: Thu, 1 Aug 2024 18:29:06 -0700 Subject: [PATCH 4/5] Fix LTO setting on Linux --- .buildkite/scripts/env.sh | 3 +++ Dockerfile | 2 +- scripts/env.sh | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.buildkite/scripts/env.sh b/.buildkite/scripts/env.sh index 73e982e90b5486..d67296af185e42 100755 --- a/.buildkite/scripts/env.sh +++ b/.buildkite/scripts/env.sh @@ -80,6 +80,9 @@ function export_environment() { export ZIG_LOCAL_CACHE_DIR="$HOME/.cache/zig-cache/$BUILDKITE_STEP_KEY" export ZIG_GLOBAL_CACHE_DIR="$HOME/.cache/zig-cache/$BUILDKITE_STEP_KEY" export BUN_DEPS_CACHE_DIR="$HOME/.cache/bun-deps/$BUILDKITE_STEP_KEY" + if [ "$(assert_os)" == "darwin" ]; then + export USE_LTO="ON" + fi if [ "$(assert_arch)" == "aarch64" ]; then export CPU_TARGET="native" elif [[ "$BUILDKITE_STEP_KEY" == *"baseline"* ]]; then diff --git a/Dockerfile b/Dockerfile index 7b707f03e259ed..aaece20d3609ee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,7 +52,7 @@ ENV CI 1 ENV CPU_TARGET=${CPU_TARGET} ENV BUILDARCH=${BUILDARCH} ENV BUN_DEPS_OUT_DIR=${BUN_DEPS_OUT_DIR} -ENV BUN_ENABLE_LTO 1 +ENV USE_LTO 1 ENV LC_CTYPE=en_US.UTF-8 ENV LC_ALL=en_US.UTF-8 diff --git a/scripts/env.sh b/scripts/env.sh index 617c1c75ed38dd..e0ca4ccf39a6c5 100755 --- a/scripts/env.sh +++ b/scripts/env.sh @@ -60,7 +60,7 @@ export CXXFLAGS='-O3 -fno-exceptions -fno-rtti -fvisibility=hidden -fvisibility- # Add flags for LTO # We cannot enable LTO on macOS for dependencies because it requires -fuse-ld=lld and lld causes many segfaults on macOS (likely related to stack size) -if [ "$BUN_ENABLE_LTO" == "1" ]; then +if [ "$USE_LTO" == "1" ] || [ "$USE_LTO" == "ON" ]; then export CFLAGS="$CFLAGS -flto=full " export CXXFLAGS="$CXXFLAGS -flto=full -fwhole-program-vtables -fforce-emit-vtables " export LDFLAGS="$LDFLAGS -flto=full -fwhole-program-vtables -fforce-emit-vtables " From deb6ff5e6c034b8c59180b3b6896e4c0ef1a98b1 Mon Sep 17 00:00:00 2001 From: Ashcon Partovi Date: Thu, 1 Aug 2024 18:30:14 -0700 Subject: [PATCH 5/5] Fix typo --- .buildkite/scripts/env.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.buildkite/scripts/env.sh b/.buildkite/scripts/env.sh index d67296af185e42..fcea58e949bb81 100755 --- a/.buildkite/scripts/env.sh +++ b/.buildkite/scripts/env.sh @@ -80,7 +80,7 @@ function export_environment() { export ZIG_LOCAL_CACHE_DIR="$HOME/.cache/zig-cache/$BUILDKITE_STEP_KEY" export ZIG_GLOBAL_CACHE_DIR="$HOME/.cache/zig-cache/$BUILDKITE_STEP_KEY" export BUN_DEPS_CACHE_DIR="$HOME/.cache/bun-deps/$BUILDKITE_STEP_KEY" - if [ "$(assert_os)" == "darwin" ]; then + if [ "$(assert_os)" == "linux" ]; then export USE_LTO="ON" fi if [ "$(assert_arch)" == "aarch64" ]; then