Skip to content

Commit c3452fb

Browse files
committed
Bazel 9 upgrade: migrate to rules_cc/rules_java explicit imports
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.
1 parent 05bef12 commit c3452fb

File tree

12 files changed

+35
-13
lines changed

12 files changed

+35
-13
lines changed

.bazelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ common --@rules_dotnet//dotnet/settings:strict_deps=false
3434
common --@rules_rust//rust/toolchain/channel=nightly
3535

3636
# 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
37-
common --incompatible_autoload_externally="+@rules_java,+@rules_shell"
37+
common --incompatible_autoload_externally="+@rules_cc,+@rules_java,+@rules_shell"
3838

3939
build --java_language_version=17
4040
build --tool_java_language_version=17

.bazelversion

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.4.2
1+
9.0.0

MODULE.bazel

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,19 @@ local_path_override(
1515
# see https://registry.bazel.build/ for a list of available packages
1616

1717
bazel_dep(name = "platforms", version = "1.0.0")
18-
bazel_dep(name = "rules_go", version = "0.56.1")
18+
bazel_dep(name = "rules_cc", version = "0.2.16")
19+
bazel_dep(name = "rules_go", version = "0.59.0")
20+
bazel_dep(name = "rules_java", version = "9.0.3")
1921
bazel_dep(name = "rules_pkg", version = "1.0.1")
20-
bazel_dep(name = "rules_nodejs", version = "6.2.0-codeql.1")
22+
bazel_dep(name = "rules_nodejs", version = "6.7.3")
2123
bazel_dep(name = "rules_python", version = "0.40.0")
2224
bazel_dep(name = "rules_shell", version = "0.5.0")
2325
bazel_dep(name = "bazel_skylib", version = "1.8.1")
2426
bazel_dep(name = "abseil-cpp", version = "20240116.1", repo_name = "absl")
2527
bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "json")
2628
bazel_dep(name = "fmt", version = "12.1.0-codeql.1")
2729
bazel_dep(name = "rules_kotlin", version = "2.2.0-codeql.1")
28-
bazel_dep(name = "gazelle", version = "0.40.0")
30+
bazel_dep(name = "gazelle", version = "0.47.0")
2931
bazel_dep(name = "rules_dotnet", version = "0.21.5-codeql.1")
3032
bazel_dep(name = "googletest", version = "1.14.0.bcr.1")
3133
bazel_dep(name = "rules_rust", version = "0.66.0")
@@ -188,6 +190,15 @@ pip.parse(
188190
)
189191
use_repo(pip, "codegen_deps")
190192

193+
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
194+
python.toolchain(
195+
is_default = True,
196+
python_version = "3.12",
197+
)
198+
use_repo(python, "python_3_12", "python_versions")
199+
200+
register_toolchains("@python_versions//3.12:all")
201+
191202
swift_deps = use_extension("//swift/third_party:load.bzl", "swift_deps")
192203

193204
# following list can be kept in sync with `bazel mod tidy`

javascript/extractor/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("@rules_java//java:defs.bzl", "java_library")
12
load("@rules_pkg//pkg:mappings.bzl", "pkg_files")
23
load("@semmle_code//:common.bzl", "codeql_fat_jar", "codeql_java_project")
34

javascript/extractor/test/com/semmle/js/extractor/test/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("@rules_java//java:defs.bzl", "java_test")
2+
13
java_test(
24
name = "test",
35
srcs = glob(["**/*.java"]),

misc/bazel/cmake/cmake.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
2+
13
CmakeInfo = provider(
24
fields = {
35
"name": "",

misc/bazel/internal/zipmerge/BUILD.bazel

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
2+
13
cc_library(
24
name = "lib",
35
srcs = [
@@ -28,7 +30,7 @@ cc_test(
2830
linkstatic = True, # required to build the test in the internal repo
2931
deps = [
3032
":lib",
31-
"@bazel_tools//tools/cpp/runfiles",
3233
"@googletest//:gtest_main",
34+
"@rules_cc//cc/runfiles",
3335
],
3436
)

misc/bazel/internal/zipmerge/zipmerge_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
#include <gtest/gtest.h>
1111
#include <gmock/gmock.h>
12-
#include "tools/cpp/runfiles/runfiles.h"
12+
#include "rules_cc/cc/runfiles/runfiles.h"
1313

14-
using bazel::tools::cpp::runfiles::Runfiles;
14+
using rules_cc::cc::runfiles::Runfiles;
1515
using namespace std::string_literals;
1616
namespace fs = std::filesystem;
1717

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
{
22
"versions": [
3-
"6.2.0-codeql.1"
4-
]
5-
}
3+
"6.2.0-codeql.1"

shared/cpp/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_library")
2+
13
cc_library(
24
name = "extractor_shared",
35
srcs = glob(["*.cpp"]),

0 commit comments

Comments
 (0)