Skip to content

Trim @bazel_tools and move dev tooling out of tools/ - #31146

Draft
fmeum wants to merge 3 commits into
bazelbuild:masterfrom
fmeum:bazel-tools-cleanup
Draft

fmeum wants to merge 3 commits into
bazelbuild:masterfrom
fmeum:bazel-tools-cleanup

Conversation

@fmeum

@fmeum fmeum commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

Description

Stacked on #31144.

Now that the native rules and their autoloads are gone, a lot of what is embedded into @bazel_tools is either dead or was never referenceable from outside. This pass removes what nothing references anymore, stops embedding files that only make sense inside the Bazel repo, and moves developer tooling that never belonged in @bazel_tools into scripts/. The embedded file count drops from 292 to 259.

Removed from @bazel_tools and the repo:

  • tools/whitelists and tools/build_defs/cc/whitelists/starlark_hdrs_check: the old-name package groups. Bazel has rejected the whitelist label as a transition allowlist for years and nothing references the other two. parse_headers_and_layering_check stays, rules_cc's cc_toolchain still defaults to it.
  • tools/coverage: superseded by the tools/test defaults long ago; the remaining references are vendored Bazel copies.
  • tools/defaults: an empty package left over from the synthesized //tools/defaults package.
  • tools/build_rules/test_rules.bzl: loads a file that no longer exists.
  • tools/cpp/compiler_flag.bzl and tools/jdk/java_toolchain_alias.bzl: forwarders to rules_cc and rules_java without external users. Java test mocks now load the alias macros from rules_java directly.
  • tools/java:java_stub_template.txt: a deprecated alias that announced its own removal.
  • tools/objc:gcov and :mcov, stubs of the native objc rules.
  • The //:windows and //:windows_msvc aliases in the root package, kept for third_party code that no longer exists.
  • tools/python: the py2/py3 wrapper templates and their test, and private/py_test_alias.bzl.
  • tools/android: the instrumentation_test_check tool and an unreferenced platform. The module extension stays, it still has external users.
  • tools/compliance: Bazel's SBOM experiment, not used by CI or the release process.

No longer embedded, but kept in the repo:

  • tools/jdk: the BUILD.java_tools* templates and nosystemjdk/README; only the sources of the (now C++) proguard allowlister binary are embedded, its test runs from the repo BUILD instead of from inside @bazel_tools.
  • tools/build_rules: java_rules_skylark.bzl and utilities.bzl, together with the jarhelper sources that were embedded for the native Android rules. The package no longer exists in @bazel_tools.
  • src/java_tools/import_deps_checker: its embedded BUILD referenced @android_tools, which @bazel_tools cannot see, so the target could never be analyzed.
  • tools/cpp/test_data: unreferenced.
  • The WORKSPACE stub in the embedded tools zip.

Moved to scripts/: ctexplain, aquery_differ and the get_workspace_status example that --workspace_status_command documents.

Kept on purpose despite being legacy, because they still have users: tools/android's extension, tools/build_defs/pkg and hash, the python .bzl shims that rules_python's //:bzl target lists, and the proguard allowlister, which both rules_java and rules_android default to. bazelbuild/rules_java#382 and bazel-contrib/rules_jvm_external#1628 drop those defaults on the consumer side.

Motivation

@bazel_tools ships with every Bazel binary and is loaded by every build, so everything embedded in it is startup cost and, worse, an implicit API surface that has to be kept working. Most of the removed pieces only existed because the native Java, Python, Android and objc rules referenced them; those rules are gone, and each item was checked against Bazel's own code, the embedded files and a GitHub code search before removal.

Build API Changes

Yes, in the sense that a few targets and .bzl files disappear from @bazel_tools. All of them were either already unusable (the whitelist package groups, the import_deps_checker target), superseded for years (tools/coverage, the root //:windows aliases, the objc stubs) or explicitly deprecated (tools/java:java_stub_template.txt). Code search found no live users; the few hits are vendored Bazel copies, samples and one test fixture. There is no migration beyond switching to the replacement each item already pointed at.

Release Notes

RELNOTES[INC]: Leftovers of the removed native rules were deleted from @bazel_tools: the tools/whitelists package groups, tools/coverage, tools/cpp:compiler_flag.bzl, tools/jdk:java_toolchain_alias.bzl, tools/java:java_stub_template.txt, tools/objc:gcov and :mcov, the root //:windows aliases and the tools/build_rules package. Use the rules_cc, rules_java and tools/test targets they forwarded to.

@fmeum
fmeum force-pushed the bazel-tools-cleanup branch 4 times, most recently from 7df12ce to 0357592 Compare September 16, 2026 08:21
Move aquery_differ and ctexplain to scripts/ and remove the unused Android
instrumentation checker/platform, compliance experiment, defaults package,
and test_rules.bzl. None is included in the embedded tools archive.

Stop embedding the JDK BUILD templates, nosystemjdk README, C++ test data,
Python wrapper template/test, and generated WORKSPACE stub. The embedded
BUILD files do not expose the latter files as targets; exported BUILD
metadata itself is not a supported consumer interface. Keep the JDK
BUILD.java_tools* templates in the source repository for packaging.

Remove the embedded import-deps-checker and jarhelper packages: the former
requires the unavailable @android_tools repository, while the latter
requires absent Bazel source packages. These targets cannot be analyzed
from @bazel_tools. Keep their implementations in the source repository.

Retain usable public labels and loadable Starlark files for the following
commits, including the buildstamp example and build_rules utilities.
Update source distributions, CI labels and moved Python imports together.
Global GitHub code searches on 2026-09-16 found no matches for either
"@bazel_tools//:windows" or "@bazel_tools//:windows_msvc". Drop those root
config_setting aliases.

The references to tools/python:private/py_test_alias.bzl are test-rule
loads in old copies of aquery_differ and src/test/starlark. Remove this
unused py_test forwarder and its source-file exports/filegroup entries.

Move the proguard allowlister test and its testonly support library from
@bazel_tools to the Bazel source repository, retaining the binary and its
sources in the archive. Global matches for proguard_allowlister_test are
test definitions. Stop embedding its four test-only source/data files.
Remove the Java integration test's blanket source-repo tools/jdk toolchain
registration together with this move.

Keep symbols with non-test references, including references in old Bazel
copies, in the final cleanup commit rather than claiming zero usage.
Keep the remaining compatibility removals together, separate from the
structurally unreachable and zero-reference/test-only cleanup. Global
GitHub code search on 2026-09-16 found non-test references for these
surfaces; this commit does not claim that all consumers have migrated.

Stop embedding tools/build_rules (retain the sources for Bazel's own
bootstrap) and move tools/buildstamp/get_workspace_status to scripts/.
Remove tools/coverage, the old whitelist package groups, compiler_flag.bzl,
java_toolchain_alias.bzl, tools/java:java_stub_template.txt and the objc
coverage stubs. Update the associated Java test mocks and documentation.

Concrete consumer references found during review:
- buildfarm/buildfarm, persistentworkers/src/main/protobuf/BUILD, loads
  @bazel_tools//tools/build_rules:utilities.bzl for java_library_srcs:
  https://github.com/buildfarm/buildfarm/blob/29b23a551b391c03b9667b082744fc863ff0565a/persistentworkers/src/main/protobuf/BUILD
- timothyklim/rules_scala3 defaults _java_stub_template to
  @bazel_tools//tools/java:java_stub_template.txt in rules/scala.bzl and
  scala3/private/worker_scala_{binary,library}.bzl:
  https://github.com/timothyklim/rules_scala3/blob/a29ef64416a6cfb66cdb2dffd13f06dcfe31d8fb/rules/scala.bzl
- Old rules_apple copies still name the objc coverage stubs; old Bazel
  copies retain relative loads of compiler_flag.bzl and other shims.

RELNOTES[INC]: Remove legacy @bazel_tools build_rules, buildstamp,
coverage and whitelist targets, compiler_flag.bzl, java_toolchain_alias.bzl,
the tools/java java_stub_template alias and the objc coverage stubs.
Consumers must migrate to maintained rulesets or provide their own helpers.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant