From c3452fbc9681f212582828cf1b6b866cdeb700ef Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Thu, 5 Feb 2026 15:52:52 +0100 Subject: [PATCH] Bazel 9 upgrade: migrate to rules_cc/rules_java explicit imports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bazel 9 removes native.cc_* and native.java_* rules from Starlark. These now return stub functions that fail at analysis time. The autoload mechanism (--incompatible_autoload_externally) that would automatically redirect these is disabled in Bazel 9 (bazelbuild/bazel#23043), so all usages must be converted to explicit loads from rules_cc and rules_java. Similarly, providers like CcInfo and APIs like cc_common are no longer available as globals and must be explicitly imported from their new locations. Version updates: - .bazelversion: 8.4.2 → 9.0.0 - MODULE.bazel: Added rules_cc 0.2.16, rules_java 9.0.3 dependencies - MODULE.bazel: Added Python 3.12 toolchain registration (rules_python 1.x requires explicit toolchain setup, no longer auto-registers) Bazelrc changes: - Removed --incompatible_strict_action_env (now default, flag removed in Bazel 9) - Removed --legacy_external_runfiles (now default false, flag removed) - Added +@rules_cc,+@rules_java,+@rules_shell to autoload for graceful migration BUILD/bzl migrations: - swift/rules.bzl: Added cc_binary, cc_library, CcInfo imports; changed native.cc_binary → cc_binary, native.cc_library → cc_library - misc/bazel/cmake/cmake.bzl: Added CcInfo import (used in provider returns) - misc/bazel/internal/zipmerge/BUILD.bazel: Added cc_binary, cc_library, cc_test - shared/cpp/BUILD.bazel, swift/logging/BUILD.bazel: Added cc_library load - javascript/extractor/test/.../BUILD.bazel: Added java_test load C++ runfiles API migration: - zipmerge_test.cpp: Bazel 9 moves the C++ runfiles library from @bazel_tools//tools/cpp/runfiles to @rules_cc//cc/runfiles. Updated include path and namespace accordingly. --- .bazelrc | 2 +- .bazelversion | 2 +- MODULE.bazel | 17 ++++++++++++++--- javascript/extractor/BUILD.bazel | 1 + .../com/semmle/js/extractor/test/BUILD.bazel | 2 ++ misc/bazel/cmake/cmake.bzl | 2 ++ misc/bazel/internal/zipmerge/BUILD.bazel | 4 +++- misc/bazel/internal/zipmerge/zipmerge_test.cpp | 4 ++-- .../registry/modules/rules_nodejs/metadata.json | 4 +--- shared/cpp/BUILD.bazel | 2 ++ swift/logging/BUILD.bazel | 2 ++ swift/rules.bzl | 6 ++++-- 12 files changed, 35 insertions(+), 13 deletions(-) diff --git a/.bazelrc b/.bazelrc index 679eeec77a32..eb9b1a793217 100644 --- a/.bazelrc +++ b/.bazelrc @@ -34,7 +34,7 @@ common --@rules_dotnet//dotnet/settings:strict_deps=false common --@rules_rust//rust/toolchain/channel=nightly # Reduce this eventually to empty, once we've fixed all our usages of java, and https://github.com/bazel-contrib/rules_go/issues/4193 is fixed -common --incompatible_autoload_externally="+@rules_java,+@rules_shell" +common --incompatible_autoload_externally="+@rules_cc,+@rules_java,+@rules_shell" build --java_language_version=17 build --tool_java_language_version=17 diff --git a/.bazelversion b/.bazelversion index e7fdef7e2e63..f7ee06693c17 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -8.4.2 +9.0.0 diff --git a/MODULE.bazel b/MODULE.bazel index b24546d4a3c1..f58a935db19d 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -15,9 +15,11 @@ local_path_override( # see https://registry.bazel.build/ for a list of available packages bazel_dep(name = "platforms", version = "1.0.0") -bazel_dep(name = "rules_go", version = "0.56.1") +bazel_dep(name = "rules_cc", version = "0.2.16") +bazel_dep(name = "rules_go", version = "0.59.0") +bazel_dep(name = "rules_java", version = "9.0.3") bazel_dep(name = "rules_pkg", version = "1.0.1") -bazel_dep(name = "rules_nodejs", version = "6.2.0-codeql.1") +bazel_dep(name = "rules_nodejs", version = "6.7.3") bazel_dep(name = "rules_python", version = "0.40.0") bazel_dep(name = "rules_shell", version = "0.5.0") bazel_dep(name = "bazel_skylib", version = "1.8.1") @@ -25,7 +27,7 @@ bazel_dep(name = "abseil-cpp", version = "20240116.1", repo_name = "absl") bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "json") bazel_dep(name = "fmt", version = "12.1.0-codeql.1") bazel_dep(name = "rules_kotlin", version = "2.2.0-codeql.1") -bazel_dep(name = "gazelle", version = "0.40.0") +bazel_dep(name = "gazelle", version = "0.47.0") bazel_dep(name = "rules_dotnet", version = "0.21.5-codeql.1") bazel_dep(name = "googletest", version = "1.14.0.bcr.1") bazel_dep(name = "rules_rust", version = "0.66.0") @@ -188,6 +190,15 @@ pip.parse( ) use_repo(pip, "codegen_deps") +python = use_extension("@rules_python//python/extensions:python.bzl", "python") +python.toolchain( + is_default = True, + python_version = "3.12", +) +use_repo(python, "python_3_12", "python_versions") + +register_toolchains("@python_versions//3.12:all") + swift_deps = use_extension("//swift/third_party:load.bzl", "swift_deps") # following list can be kept in sync with `bazel mod tidy` diff --git a/javascript/extractor/BUILD.bazel b/javascript/extractor/BUILD.bazel index 360dc9370f94..363ea42864fd 100644 --- a/javascript/extractor/BUILD.bazel +++ b/javascript/extractor/BUILD.bazel @@ -1,3 +1,4 @@ +load("@rules_java//java:defs.bzl", "java_library") load("@rules_pkg//pkg:mappings.bzl", "pkg_files") load("@semmle_code//:common.bzl", "codeql_fat_jar", "codeql_java_project") diff --git a/javascript/extractor/test/com/semmle/js/extractor/test/BUILD.bazel b/javascript/extractor/test/com/semmle/js/extractor/test/BUILD.bazel index 1bad97bb7cc8..2d6a5d01c660 100644 --- a/javascript/extractor/test/com/semmle/js/extractor/test/BUILD.bazel +++ b/javascript/extractor/test/com/semmle/js/extractor/test/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_java//java:defs.bzl", "java_test") + java_test( name = "test", srcs = glob(["**/*.java"]), diff --git a/misc/bazel/cmake/cmake.bzl b/misc/bazel/cmake/cmake.bzl index d98a480c69cd..8235b249a2e4 100644 --- a/misc/bazel/cmake/cmake.bzl +++ b/misc/bazel/cmake/cmake.bzl @@ -1,3 +1,5 @@ +load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") + CmakeInfo = provider( fields = { "name": "", diff --git a/misc/bazel/internal/zipmerge/BUILD.bazel b/misc/bazel/internal/zipmerge/BUILD.bazel index 07cbb34ce978..4b2723d6c64a 100644 --- a/misc/bazel/internal/zipmerge/BUILD.bazel +++ b/misc/bazel/internal/zipmerge/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") + cc_library( name = "lib", srcs = [ @@ -28,7 +30,7 @@ cc_test( linkstatic = True, # required to build the test in the internal repo deps = [ ":lib", - "@bazel_tools//tools/cpp/runfiles", "@googletest//:gtest_main", + "@rules_cc//cc/runfiles", ], ) diff --git a/misc/bazel/internal/zipmerge/zipmerge_test.cpp b/misc/bazel/internal/zipmerge/zipmerge_test.cpp index 65278a679f5b..616365c7cbdb 100644 --- a/misc/bazel/internal/zipmerge/zipmerge_test.cpp +++ b/misc/bazel/internal/zipmerge/zipmerge_test.cpp @@ -9,9 +9,9 @@ #include #include -#include "tools/cpp/runfiles/runfiles.h" +#include "rules_cc/cc/runfiles/runfiles.h" -using bazel::tools::cpp::runfiles::Runfiles; +using rules_cc::cc::runfiles::Runfiles; using namespace std::string_literals; namespace fs = std::filesystem; diff --git a/misc/bazel/registry/modules/rules_nodejs/metadata.json b/misc/bazel/registry/modules/rules_nodejs/metadata.json index 2b3827d48289..8d7ba88dceec 100644 --- a/misc/bazel/registry/modules/rules_nodejs/metadata.json +++ b/misc/bazel/registry/modules/rules_nodejs/metadata.json @@ -1,5 +1,3 @@ { "versions": [ - "6.2.0-codeql.1" - ] -} + "6.2.0-codeql.1" diff --git a/shared/cpp/BUILD.bazel b/shared/cpp/BUILD.bazel index 5debed90086c..f78c4ede92fa 100644 --- a/shared/cpp/BUILD.bazel +++ b/shared/cpp/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + cc_library( name = "extractor_shared", srcs = glob(["*.cpp"]), diff --git a/swift/logging/BUILD.bazel b/swift/logging/BUILD.bazel index 1d6192b3c13a..e72a7071d069 100644 --- a/swift/logging/BUILD.bazel +++ b/swift/logging/BUILD.bazel @@ -1,3 +1,5 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") + cc_library( name = "logging", srcs = glob(["*.cpp"]), diff --git a/swift/rules.bzl b/swift/rules.bzl index cb16ca4382ad..f0fde7e71401 100644 --- a/swift/rules.bzl +++ b/swift/rules.bzl @@ -1,3 +1,5 @@ +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") +load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") load("//misc/bazel:os.bzl", "os_select") # TODO: make a shared library with the internal repos for transitions @@ -124,7 +126,7 @@ def _wrap_cc(rule, kwargs): ) def swift_cc_binary(**kwargs): - _wrap_cc(native.cc_binary, kwargs) + _wrap_cc(cc_binary, kwargs) def swift_cc_library(**kwargs): - _wrap_cc(native.cc_library, kwargs) + _wrap_cc(cc_library, kwargs)