From 89ef848a105ececdef4f48637e12137496e253ce Mon Sep 17 00:00:00 2001 From: Felix Hanau Date: Tue, 20 Jan 2026 17:05:03 -0500 Subject: [PATCH 1/2] [build] Update to Bazel 9 --- .bazelrc | 33 +++++++++++++-------------- .bazelversion | 2 +- build/cc_ast_dump.bzl | 4 +++- build/tools/clang_tidy/clang_tidy.bzl | 6 +++++ compile_flags.txt | 4 ++-- 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/.bazelrc b/.bazelrc index 57b858d1ef0..ca2c0ca11d0 100644 --- a/.bazelrc +++ b/.bazelrc @@ -12,15 +12,11 @@ build --test_size_filters=-enormous # corresponds to small,medium,large,enormous tests (medium is default) build --test_timeout=3,15,60,240 -# As part of starlarkification, Bazel 8 removes a number of rules which now need to be imported from -# other repositories. In the long term, load() statements will be needed to import these rules. For -# now, we can still autoload the affected repositories when needed. Do this only for a remaining -# protobuf components instead of the larger default autoload set – perfetto isn't importing all -# required rules yet, but we don't want to accidentally rely on autoloading more dependencies. -common --incompatible_autoload_externally="+ProtoInfo" - -# Bazel 9 forward compatibility: Disable native repo rules. -build --incompatible_disable_native_repo_rules +# As part of starlarkification, Bazel 8 and 9 remove a number of rules which now need to be imported +# from other repositories. In the long term, load() statements will be needed to import these rules. +# For now, we can still autoload the affected repositories when needed. Do this only for a remaining +# protobuf components and rules_cc (needed with Bazel 9). +common --incompatible_autoload_externally="+ProtoInfo,+cc_binary,+cc_import,+cc_library,+cc_shared_library,+cc_test,+cc_toolchain" # bazel7 enables Build without the Bytes (BwoB) by default. This significantly speeds up builds # using the remote cache since less data needs to be fetched. @@ -34,16 +30,20 @@ import %workspace%/build/ci.bazelrc import %workspace%/build/rust_lint.bazelrc import %workspace%/build/tools/clang_tidy/clang_tidy.bazelrc -# Prevents bazel cache invalidation when switching terminals -build --incompatible_strict_action_env - -# Use compat repo mapping to avoid O(n^2) repo mapping size, speeding up bazel repo mapping phase -# and conserving space -build --incompatible_compact_repo_mapping_manifest - # Continue building locally when remote cache entries fail to materialize build --incompatible_remote_local_fallback_for_remote_cache +# TODO(soon): Flipped by default in Bazel 9, add required variables to --repo_env and enable +build --noincompatible_repo_env_ignores_action_env + +# Use -isystem for cc_library includes attribute – this prevents warnings for misbehaving external +# code. +build:linux --features=external_include_paths --host_features=external_include_paths + +# Forward compatibility with future Bazel versions: +# Disable deprecated cfg = "host" Bazel rule setting. Blocked on perfetto. +# common --incompatible_disable_starlark_host_transitions + # Our dependencies (ICU, zlib, etc.) produce a lot of these warnings, so we disable them. build --per_file_copt='external@-Wno-error' build --per_file_copt='external@-Wno-suggest-override' @@ -473,7 +473,6 @@ coverage --config=wpt-test coverage --test_size_filters=-enormous coverage --test_timeout=240,240,240,240 coverage --build_tests_only -coverage --combined_report=lcov # This config is defined internally and enabled on many machines. # Defining it as empty just so these machines can run build commands from the workerd repo diff --git a/.bazelversion b/.bazelversion index f9c71a52e2f..f7ee06693c1 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -8.5.1 +9.0.0 diff --git a/build/cc_ast_dump.bzl b/build/cc_ast_dump.bzl index cad7ec1cb16..d4c362c3b07 100644 --- a/build/cc_ast_dump.bzl +++ b/build/cc_ast_dump.bzl @@ -30,7 +30,9 @@ def _cc_ast_dump_impl(ctx): user_compile_flags = ["-Wno-unused-command-line-argument", "-Xclang", "-ast-dump=json", "-fsyntax-only"] + ctx.fragments.cpp.copts + ctx.fragments.cpp.cxxopts, include_directories = cc_info.compilation_context.includes, quote_include_directories = cc_info.compilation_context.quote_includes, - system_include_directories = cc_info.compilation_context.system_includes, + # we need to pass external_includes, but there is no equivalent parameter in + # create_compile_variables – pass alongside system_includes. + system_include_directories = depset(transitive = [cc_info.compilation_context.system_includes, cc_info.compilation_context.external_includes]), framework_include_directories = cc_info.compilation_context.framework_includes, preprocessor_defines = cc_info.compilation_context.defines, ) diff --git a/build/tools/clang_tidy/clang_tidy.bzl b/build/tools/clang_tidy/clang_tidy.bzl index 1f3310fca74..a90deb91590 100644 --- a/build/tools/clang_tidy/clang_tidy.bzl +++ b/build/tools/clang_tidy/clang_tidy.bzl @@ -57,6 +57,7 @@ def _clang_tidy_aspect_impl(target, ctx): includes = compilation_context.includes.to_list() quote_includes = compilation_context.quote_includes.to_list() system_includes = compilation_context.system_includes.to_list() + external_includes = compilation_context.external_includes.to_list() headers = compilation_context.headers # disable clang tidy if no-clang-tidy tag is defined. @@ -84,6 +85,10 @@ def _clang_tidy_aspect_impl(target, ctx): quote_includes, transitive = [dep.quote_includes for dep in deps], ) + external_includes = depset( + external_includes, + transitive = [dep.external_includes for dep in deps], + ) headers = depset( headers.to_list(), transitive = [dep.headers for dep in deps], @@ -130,6 +135,7 @@ def _clang_tidy_aspect_impl(target, ctx): args.add_all(includes, before_each = "-I") args.add_all(quote_includes, before_each = "-iquote") args.add_all(system_includes, before_each = "-isystem") + args.add_all(external_includes, before_each = "-isystem") args.add_all(toolchain_flags) diff --git a/compile_flags.txt b/compile_flags.txt index d2c4ae4588d..68e865fbfa7 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -2,7 +2,7 @@ -stdlib=libc++ -xc++ -nostdinc --Ibazel-bin/external/+_repo_rules+com_cloudflare_lol_html/_virtual_includes/lolhtml +-Ibazel-bin/external/+new_local_repository+com_cloudflare_lol_html/_virtual_includes/lolhtml -Ibazel-bin/external/perfetto+/ -Iexternal/ada-url+/ -Iexternal/abseil-cpp+/ @@ -46,7 +46,7 @@ -isystemexternal/+_repo_rules2+v8/include/cppgc -isystembazel-bin/src -isystemexternal/brotli+/c/include --isystemexternal/+_repo_rules3+com_googlesource_chromium_icu/source/common +-isystembazel-bin/external/+git_repository+com_googlesource_chromium_icu/_virtual_includes/icu/third_party/icu/source/common -isystemexternal/zlib+ -isystembazel-bin/src/rust/cxx-integration/_virtual_includes/lib.rs@cxx -isystembazel-bin/src/rust/cxx-integration-test/_virtual_includes/lib.rs@cxx From 728b465f3901c9179a9f1bcdc9f18d230ea7708e Mon Sep 17 00:00:00 2001 From: Felix Hanau Date: Fri, 23 Jan 2026 14:25:39 -0500 Subject: [PATCH 2/2] [build] Fix Rust coverage under Bazel 9 --- build/deps/build_deps.jsonc | 5 ----- build/deps/gen/build_deps.MODULE.bazel | 3 --- build/deps/rust.MODULE.bazel | 14 ++++++++++++++ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/build/deps/build_deps.jsonc b/build/deps/build_deps.jsonc index 76625ff4f38..2e5fc150bb1 100644 --- a/build/deps/build_deps.jsonc +++ b/build/deps/build_deps.jsonc @@ -41,11 +41,6 @@ "name": "rules_cc", "type": "bazel_dep" }, - // Rust - { - "name": "rules_rust", - "type": "bazel_dep" - }, // Node.js { "name": "aspect_rules_esbuild", diff --git a/build/deps/gen/build_deps.MODULE.bazel b/build/deps/gen/build_deps.MODULE.bazel index 44e6903ebe7..80e6736cd24 100644 --- a/build/deps/gen/build_deps.MODULE.bazel +++ b/build/deps/gen/build_deps.MODULE.bazel @@ -119,8 +119,5 @@ bazel_dep(name = "rules_oci", version = "2.2.7") # rules_python bazel_dep(name = "rules_python", version = "1.8.0") -# rules_rust -bazel_dep(name = "rules_rust", version = "0.68.1") - # rules_shell bazel_dep(name = "rules_shell", version = "0.6.1") diff --git a/build/deps/rust.MODULE.bazel b/build/deps/rust.MODULE.bazel index ca0f2d816a9..28e0943b275 100644 --- a/build/deps/rust.MODULE.bazel +++ b/build/deps/rust.MODULE.bazel @@ -10,6 +10,20 @@ RUST_TARGET_TRIPLES = [ "aarch64-unknown-linux-gnu", ] +# rules_rust +bazel_dep(name = "rules_rust", version = "0.68.1") + +# Under Bazel 9, Rust coverage is broken when using experimental_split_coverage_postprocessing. +# TODO(cleanup): https://github.com/bazelbuild/rules_rust/pull/3812 should fix this, we're using +# that commit for now. Switch back to regular release once resolved. +archive_override( + module_name = "rules_rust", + integrity = "sha256-dtn87CNPspDl5xEfAGEl0eQ4HBf07vpxIdMNPRHqMqM=", + strip_prefix = "bazelbuild-rules_rust-cb9d412", + type = "tgz", + url = "https://github.com/bazelbuild/rules_rust/tarball/cb9d412afdb95578bd533b60483eecb373119c36", +) + rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") rust.toolchain( allocator_library = "@rules_rust//ffi/rs:empty",