Skip to content

Commit 53c8232

Browse files
committed
Bump Bazel to 9.0.1
### What does this PR do? Upgrades the Bazel toolchain from 8.6.0 to 9.0.1. ### Motivation 9.0.1 ships two upstream fixes that directly benefit our build: - bazelbuild/bazel#28606: NPE when `--repo_env` is set to an env var that has no value — contributed by Datadog (Joseph Gette). - bazelbuild/bazel#26842: `DefaultSyscallCache` incorrectly treated `BUILD` files and `build` directories as the same entry on case-insensitive / normalizing filesystems (e.g. Linux container on a macOS host), causing spurious build failures. ### Describe how you validated your changes `bazel test //...` passes. ### Additional Notes Changes required: - `.bazelversion`: 8.6.0 → 9.0.1 - `MODULE.bazel`: - `protobuf` 29.1 → 33.4 (resolved version in Bazel 9 dep graph) - `apple_support` 1.24.1 → 1.24.2 - `libarchive` 3.8.1 → 3.8.1.bcr.2, whose transitive `bzip2` dep (pinned to 1.0.8.bcr.4 via `single_version_override`) ships a Bazel 9-compatible BUILD file with explicit `load()` statements - `gcc_toolchain`: add patch 0005 (see below) - `bazel/toolchains/mingw/toolchain.bzl`: drop `provides = [CcToolchainConfigInfo]`; `CcToolchainConfigInfo` was never imported so it evaluated to `None`, which Bazel 9 rejects - `bazel/patches/gcc-toolchain/0005-fix-bazel-9-compat.patch`: same fix for `gcc_toolchain`'s `cc_toolchain_config.bzl`; also adds explicit `cc_common` load and `cc_library` to the generated BUILD template, both required by Bazel 9
1 parent ab756a1 commit 53c8232

7 files changed

Lines changed: 226 additions & 435 deletions

File tree

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.6.0
1+
9.0.1

MODULE.bazel

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,15 @@ archive_override(
4242
bazel_dep(name = "bazel_lib", version = "3.2.2")
4343
bazel_dep(name = "bazel_skylib", version = "1.9.0")
4444
bazel_dep(name = "gazelle", version = "0.47.0")
45-
bazel_dep(name = "libarchive", version = "3.8.1")
45+
bazel_dep(name = "libarchive", version = "3.8.1.bcr.2")
46+
47+
single_version_override(
48+
module_name = "bzip2",
49+
version = "1.0.8.bcr.4",
50+
)
51+
4652
bazel_dep(name = "platforms", version = "1.0.0")
47-
bazel_dep(name = "protobuf", version = "29.1")
53+
bazel_dep(name = "protobuf", version = "33.4")
4854
single_version_override(
4955
module_name = "protobuf",
5056
patch_strip = 1,
@@ -333,6 +339,6 @@ include("//deps:go.MODULE.bazel")
333339
# This enables cross-compilation for macOS x86_64 on Apple Silicon.
334340
# Simply add --platforms=@apple_support//platforms:macos_x86_64
335341
# to the build command to enable it.
336-
bazel_dep(name = "apple_support", version = "1.24.1")
342+
bazel_dep(name = "apple_support", version = "1.24.2")
337343

338344
use_repo_rule("//bazel/tools:bazelisk_check.bzl", "bazelisk_check")(name = "bazelisk_check")

MODULE.bazel.lock

Lines changed: 174 additions & 425 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
diff --git a/foreign_cc/private/framework.bzl b/foreign_cc/private/framework.bzl
2+
index 58307bc..af1d671 100644
3+
--- a/foreign_cc/private/framework.bzl
4+
+++ b/foreign_cc/private/framework.bzl
5+
@@ -9,2 +9,3 @@ load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
6+
load("@rules_cc//cc:defs.bzl", "CcInfo", "cc_common")
7+
+load("@rules_cc//cc/common:cc_shared_library_info.bzl", "CcSharedLibraryInfo")
8+
load("//foreign_cc:providers.bzl", "ForeignCcArtifactInfo", "ForeignCcDepsInfo")
9+
@@ -969,6 +970,3 @@ def _define_inputs(attrs):
10+
for dynamic_dep in attrs.dynamic_deps:
11+
- if not bazel_features.globals.CcSharedLibraryInfo:
12+
- fail("CcSharedLibraryInfo is only available in Bazel 7 or greater")
13+
-
14+
- linker_input = dynamic_dep[bazel_features.globals.CcSharedLibraryInfo].linker_input
15+
+ linker_input = dynamic_dep[CcSharedLibraryInfo].linker_input
16+
bazel_libs += _collect_shared_libs(linker_input)

deps/repos.MODULE.bazel

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ http_archive(
7777
# - bazel-contrib/rules_foreign_cc#1451: out_data_dirs in output groups
7878
# - bazel-contrib/rules_foreign_cc#1465: resource_set integration (fixes overcommitting)
7979
# - bazel-contrib/rules_foreign_cc#1470: -isystem forwarding to configure scripts
80-
# Patch 0002 is still carried locally (bazel-contrib/rules_foreign_cc#1452 not yet merged).
80+
# Patches carried locally (not yet merged upstream):
81+
# - 0002: bazel-contrib/rules_foreign_cc#1452
82+
# - 0003: bazel-contrib/rules_foreign_cc#1491
83+
# - 0004: bazel-contrib/rules_foreign_cc#1493
8184
bazel_dep(name = "rules_foreign_cc", version = "0.15.1")
8285
git_override(
8386
module_name = "rules_foreign_cc",
@@ -86,6 +89,7 @@ git_override(
8689
patches = [
8790
"//bazel/patches:rules_foreign_cc/0002-configure_make-provide-DY-LD_LIBRARY_PATH-based-on-t.patch",
8891
"//bazel/patches:rules_foreign_cc/0003-pass-j-flag-directly-on-make-command-line.patch",
92+
"//bazel/patches:rules_foreign_cc/0004-fix-CcSharedLibraryInfo.patch",
8993
],
9094
remote = "https://github.com/bazel-contrib/rules_foreign_cc",
9195
)

tools/bazel

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ if [ ! -d "${XDG_CACHE_HOME:-}" ]; then
2121
fi
2222

2323
# Ensure `bazel` & managed toolchains honor `XDG_CACHE_HOME` as per https://wiki.archlinux.org/title/XDG_Base_Directory
24+
args=("$@")
2425
if [ -n "${XDG_CACHE_HOME:-}" ]; then
2526
if [[ "$XDG_CACHE_HOME" != /* ]]; then
2627
>&2 echo "🔴 XDG_CACHE_HOME ($XDG_CACHE_HOME) must denote an absolute path!"
@@ -29,9 +30,11 @@ if [ -n "${XDG_CACHE_HOME:-}" ]; then
2930
unset GOCACHE # https://pkg.go.dev/cmd/go#hdr-Build_and_test_caching
3031
export GOMODCACHE="$XDG_CACHE_HOME"/go/mod # https://wiki.archlinux.org/title/XDG_Base_Directory#Partial
3132
unset PIP_CACHE_DIR # https://pip.pypa.io/en/stable/topics/caching/#default-paths
32-
if [[ -n "${CI:-}" && -z "${GITHUB_ACTIONS:-}" ]]; then
33-
exec "$BAZEL_REAL" ${1:+"$1" --config=ci} "${@:2}"
33+
if [[ $# -gt 0 ]]; then
34+
[[ -n "${CI:-}" && -z "${GITHUB_ACTIONS:-}" ]] && args=("${args[0]}" --config=ci "${args[@]:1}")
35+
# Avoid `ERROR: The repo contents cache is inside the main repo. This can cause spurious failures.`
36+
[[ "$XDG_CACHE_HOME" == "$(dirname "$(dirname "$0")")"/* ]] && args=("${args[0]}" --repo_contents_cache= "${args[@]:1}")
3437
fi
3538
fi
3639

37-
exec "$BAZEL_REAL" "$@"
40+
exec "$BAZEL_REAL" "${args[@]}"

tools/bazel.bat

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ if defined XDG_CACHE_HOME (
4141
set "XDG_CACHE_HOME=%~dp0..\.cache"
4242
)
4343

44+
:: Build args (mirrors Linux args array), injecting --repo_contents_cache= when cache is inside workspace
45+
:: Avoid `ERROR: The repo contents cache is inside the main repo. This can cause spurious failures.`
46+
set "args=%*"
47+
for %%i in ("%~dp0..") do call set "xdg_stripped=%%%%XDG_CACHE_HOME:%%~fi\=%%%%"
48+
if "!xdg_stripped!" neq "!XDG_CACHE_HOME!" if not "%~1"=="" (
49+
if "%~2"=="" (
50+
set "args=%~1 --repo_contents_cache="
51+
) else (
52+
call set "args=%%args:*%~1 =%%"
53+
set "args=%~1 --repo_contents_cache= !args!"
54+
)
55+
)
56+
4457
:: Check legacy max path length of 260 characters got lifted, or fail with instructions
4558
set "more_than_260_chars=!XDG_CACHE_HOME!\more-than-260-chars"
4659
for /l %%i in (1,1,26) do set "more_than_260_chars=!more_than_260_chars!\123456789"
@@ -56,7 +69,7 @@ if not exist "!more_than_260_chars!" (
5669

5770
:: Not in CI nor GitHub Actions: simply execute `bazel` - done
5871
if defined CI if not defined GITHUB_ACTIONS goto :ci_config
59-
"%BAZEL_REAL%" !bazel_home_startup_option! %*
72+
"%BAZEL_REAL%" !bazel_home_startup_option! !args!
6073
exit /b !errorlevel!
6174
:ci_config
6275

@@ -72,7 +85,7 @@ exit /b !errorlevel!
7285
>&2 powershell -NoProfile -Command "Get-Process bazel,java -ErrorAction SilentlyContinue | Select-Object 🟡,ProcessName,StartTime"
7386

7487
:: Payload: execute `bazel` and remember exit status
75-
"%BAZEL_REAL%" %*
88+
"%BAZEL_REAL%" !args!
7689
set bazel_exit=!errorlevel!
7790

7891
:: Diagnostics: dump logs on non-trivial failures (https://bazel.build/run/scripts#exit-codes)

0 commit comments

Comments
 (0)