Skip to content

Upgrade Bazel to 9.0.0#21276

Open
redsun82 wants to merge 13 commits intomainfrom
redsun82/bazel-9
Open

Upgrade Bazel to 9.0.0#21276
redsun82 wants to merge 13 commits intomainfrom
redsun82/bazel-9

Conversation

@redsun82
Copy link
Contributor

@redsun82 redsun82 commented Feb 5, 2026

Summary

Upgrade Bazel from 8.x to 9.0.0.

Bazel 9 removes native.cc_* and native.java_* rules from Starlark scope, requiring explicit imports from rules_cc and rules_java.

Changes

Core upgrade

  • Upgrade Bazel to 9.0.0 in .bazelversion

New module dependencies

  • rules_cc 0.2.16: provides cc_binary, cc_library, cc_test
  • rules_java 9.0.3: provides java_* rules
  • Update rules_go 0.56.1 → 0.59.0 (Bazel 9 compatibility)
  • Update gazelle 0.40.0 → 0.47.0 (rules_go 0.59.0 compatibility)
  • Update rules_nodejs 6.2.0-codeql.1 → 6.7.3 (upstream version)
  • Update rules_kotlin 2.2.0-codeql.1 → 2.2.2-codeql.1 (Windows bzlmod fix)

Configuration

  • Add +@rules_cc to --incompatible_autoload_externally for graceful migration
  • Register Python 3.12 toolchain (rules_python 1.x requires explicit registration)
  • Disable Android SDK auto-detection (ANDROID_HOME=) to avoid rules_android Bazel 9 compatibility issues

Starlark migrations

  • Add explicit load() statements for cc_binary, cc_library, CcInfo in .bzl files
  • Replace native.cc_* calls with explicit rule names

BUILD file migrations

  • Add explicit load() for cc_binary, cc_library, cc_test from @rules_cc//cc:defs.bzl
  • Add explicit load() for java_library, java_test from @rules_java//java:defs.bzl

C++ runfiles API migration

  • Move from @bazel_tools//tools/cpp/runfiles to @rules_cc//cc/runfiles
  • Update include path and namespace in zipmerge_test.cpp

Windows compatibility fixes

  • Upgrade rules_kotlin to 2.2.2 which fixes Windows bzlmod builder classpath issues
  • Fix codegen templates to be properly included in runfiles (dbscheme, ql, rust)

Fixes

  • Correct malformed JSON in rules_nodejs metadata (trailing comma)

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 and update namespace accordingly
- BUILD.bazel: Update dependency from @bazel_tools//tools/cpp/runfiles
  to @rules_cc//cc/runfiles
Fix malformed JSON in metadata file - remove trailing comma after
last array element.
@redsun82 redsun82 added the depends on internal PR This PR should only be merged in sync with an internal Semmle PR label Feb 5, 2026
github-actions bot and others added 4 commits February 5, 2026 18:14
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.
@redsun82 redsun82 marked this pull request as ready for review February 6, 2026 17:25
@redsun82 redsun82 requested review from a team as code owners February 6, 2026 17:25
Copilot AI review requested due to automatic review settings February 6, 2026 17:25
@redsun82 redsun82 requested review from a team as code owners February 6, 2026 17:25
Copy link
Contributor

Copilot AI left a 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"
Copy link

Copilot AI Feb 6, 2026

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.

Suggested change
"6.2.0-codeql.1"
"6.2.0-codeql.1"
]
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

depends on internal PR This PR should only be merged in sync with an internal Semmle PR JS Swift

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant