-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Upgrade Bazel to 9.0.0 #21276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Upgrade Bazel to 9.0.0 #21276
Conversation
c3452fb to
2483b89
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR upgrades Bazel from version 8.4.2 to 9.0.0, a major version upgrade that removes native.cc_* and native.java_* rules from Starlark scope, requiring explicit imports from rules_cc and rules_java.
Changes:
- Upgrade Bazel to 9.0.0 and add new module dependencies (rules_cc 0.2.16, rules_java 9.0.3)
- Update related dependencies for Bazel 9 compatibility (rules_go, gazelle, rules_nodejs, rules_kotlin)
- Add explicit load() statements for cc_* and java_* rules across .bzl and BUILD files
- Migrate C++ runfiles API from @bazel_tools to @rules_cc
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| .bazelversion | Upgrade Bazel version from 8.4.2 to 9.0.0 |
| .bazelrc | Add @rules_cc to incompatible_autoload_externally flag and disable Android SDK auto-detection |
| MODULE.bazel | Add rules_cc and rules_java dependencies, update rules_go/gazelle/rules_nodejs/rules_kotlin versions, register Python 3.12 toolchain |
| swift/rules.bzl | Add load() for cc_binary, cc_library, CcInfo; replace native.cc_* calls |
| swift/logging/BUILD.bazel | Add load() for cc_library from rules_cc |
| shared/cpp/BUILD.bazel | Add load() for cc_library from rules_cc |
| misc/bazel/cmake/cmake.bzl | Add load() for CcInfo from rules_cc |
| misc/bazel/internal/zipmerge/BUILD.bazel | Add load() for cc_* rules; migrate runfiles dependency from @bazel_tools to @rules_cc |
| misc/bazel/internal/zipmerge/zipmerge_test.cpp | Update runfiles include path and namespace from bazel::tools to rules_cc::cc |
| misc/codegen/BUILD.bazel | Add dbscheme, ql, and rust template filegroups to data dependencies |
| misc/codegen/templates/BUILD.bazel | Create filegroups for dbscheme, ql, and rust templates |
| javascript/extractor/BUILD.bazel | Add load() for java_library from rules_java |
| javascript/extractor/test/com/semmle/js/extractor/test/BUILD.bazel | Add load() for java_test from rules_java |
| misc/bazel/registry/modules/rules_kotlin/metadata.json | Add rules_kotlin 2.2.2-codeql.1 to versions list |
| misc/bazel/registry/modules/rules_kotlin/2.2.2-codeql.1/* | Add new rules_kotlin version with patches and MODULE.bazel configuration |
| misc/bazel/registry/modules/rules_kotlin/2.2.0-codeql.1/source.json | Reorder patches (cosmetic change for consistency) |
| misc/bazel/registry/modules/rules_nodejs/metadata.json | Fix malformed JSON (critical issue - file is incomplete after changes) |
| "6.2.0-codeql.1" | ||
| ] | ||
| } | ||
| "6.2.0-codeql.1" |
Copilot
AI
Feb 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The JSON file is malformed after the changes. Line 3 should be part of a complete JSON array, but it's missing the closing bracket and brace. The file should be:
{
"versions": [
"6.2.0-codeql.1"
]
}
The diff shows lines being removed but line 3 appears incomplete in the result.
| "6.2.0-codeql.1" | |
| "6.2.0-codeql.1" | |
| ] | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. This commit seems to break the JSON file, and does not fix anything. I don't see a "trailing comma after last array element" in the file to begin with.
d6c316f to
a76c0b5
Compare
Bazel 9 removes native.cc_* and native.java_* rules from Starlark, requiring explicit imports from rules_cc and rules_java.
Add explicit dependencies required for Bazel 9: - rules_cc 0.2.16: provides cc_binary, cc_library, cc_test - rules_java 9.0.3: provides java_* rules Also update related dependencies: - rules_go: 0.56.1 → 0.59.0 (compatibility with Bazel 9) - gazelle: 0.40.0 → 0.47.0 (compatibility with rules_go 0.59.0) - rules_nodejs: 6.2.0-codeql.1 → 6.7.3 (upstream version)
rules_python 1.x requires explicit toolchain setup and no longer auto-registers toolchains. Register Python 3.12 toolchain to ensure Python tools work correctly with Bazel 9.
Add +@rules_cc to --incompatible_autoload_externally to enable graceful migration path for cc_* rule usages before all files are updated with explicit imports.
Bazel 9 removes native.cc_* and CcInfo from global scope. Update: - swift/rules.bzl: Add cc_binary, cc_library, CcInfo imports; use explicit cc_binary/cc_library instead of native.cc_* - misc/bazel/cmake/cmake.bzl: Add CcInfo import for provider usage
Add explicit load statements for cc_binary, cc_library, and cc_test from @rules_cc//cc:defs.bzl in: - shared/cpp/BUILD.bazel - swift/logging/BUILD.bazel - misc/bazel/internal/zipmerge/BUILD.bazel
Add explicit load statements for java_library and java_test from @rules_java//java:defs.bzl in: - javascript/extractor/BUILD.bazel - javascript/extractor/test/com/semmle/js/extractor/test/BUILD.bazel
Bazel 9 moves the C++ runfiles library from @bazel_tools to @rules_cc. Update zipmerge_test.cpp: - Change include from tools/cpp/runfiles to rules_cc/cc/runfiles - Update namespace from bazel::tools::cpp::runfiles to rules_cc::cc::runfiles Note: The BUILD.bazel dependency change is in a separate commit.
rules_android has repository visibility issues with Bazel 9 when the Android SDK is present. Since we don't use Android, disable detection by setting ANDROID_HOME to empty.
Upgrade from 2.2.0-codeql.1 to 2.2.2-codeql.1 which includes: - Fix Windows bzlmod builder classpath issue - Move to official bazel worker api This eliminates the need for --legacy_external_runfiles on Windows. Also fix codegen templates to be included in runfiles.
b77972a to
37261b2
Compare
mbg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This generally looks good! A few minor comments and the same observation about the JSON file as Copilot (which may already be fixed as of your force-push a minute ago).
swift/rules.bzl
Outdated
| load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library") | ||
| load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be one load?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, it may be that defs.bzl reexports that definition, let me check
| "6.2.0-codeql.1" | ||
| ] | ||
| } | ||
| "6.2.0-codeql.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. This commit seems to break the JSON file, and does not fix anything. I don't see a "trailing comma after last array element" in the file to begin with.
| @@ -22,6 +22,7 @@ | |||
| ], | |||
| "versions": [ | |||
| "2.2.0-codeql.1", | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, not really. There are cases in which we may want to make a patched version stick around (for being able to merge a codeql PR independently of the internal repo), but this is not one of them.
| @@ -0,0 +1,14 @@ | |||
| Emitting jdeps is broken for the 2.0.0 kotlin extractor, and we don't need those files. | |||
| Patching it here rather than passing `--@rules_kotlin//kotlin/settings:jvm_emit_jdeps=false` | |||
| allows us to not have to specify that option (and therefore pull in `rules_kotlin`) in `semmle-code`. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"in the internal repo"?
| "codeql_add_language_version_option.patch": "sha256-HoH8NWXxmYHmm/SxaugRdXgMntvcQx5gRLW2yQIvWhM=", | ||
| "codeql_do_not_emit_jdeps.patch": "sha256-gIlhXEY71vlCkpr5wj2vm3yv6RwcuKLhgbTGqdVvQfU=" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Any reason for the reshuffle here?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uh, let me check, maybe the the fix.py script does not guarantee the order
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, it uses iterdir without sorting, so the order is not preserved. I'll make it lexicographic (which does mean a reshuffling here, but will avoid reshufflings in the future)
Summary
Upgrade Bazel from 8.x to 9.0.0.
Bazel 9 removes
native.cc_*andnative.java_*rules from Starlark scope, requiring explicit imports fromrules_ccandrules_java.Changes
Core upgrade
.bazelversionNew module dependencies
rules_cc0.2.16: providescc_binary,cc_library,cc_testrules_java9.0.3: providesjava_*rulesrules_go0.56.1 → 0.59.0 (Bazel 9 compatibility)gazelle0.40.0 → 0.47.0 (rules_go 0.59.0 compatibility)rules_nodejs6.2.0-codeql.1 → 6.7.3 (upstream version)rules_kotlin2.2.0-codeql.1 → 2.2.2-codeql.1 (Windows bzlmod fix)Configuration
+@rules_ccto--incompatible_autoload_externallyfor graceful migrationANDROID_HOME=) to avoidrules_androidBazel 9 compatibility issuesStarlark migrations
load()statements forcc_binary,cc_library,CcInfoin.bzlfilesnative.cc_*calls with explicit rule namesBUILD file migrations
load()forcc_binary,cc_library,cc_testfrom@rules_cc//cc:defs.bzlload()forjava_library,java_testfrom@rules_java//java:defs.bzlC++ runfiles API migration
@bazel_tools//tools/cpp/runfilesto@rules_cc//cc/runfileszipmerge_test.cppWindows compatibility fixes
rules_kotlinto 2.2.2 which fixes Windows bzlmod builder classpath issuesFixes
rules_nodejsmetadata (trailing comma)