9.0.0
Bazel 9.0 is a major long-term-support (LTS) release. It contains new features and backwards incompatible changes.
Highlights
- Bzlmod is now always enabled, and all
WORKSPACElogic has been removed from Bazel (#26131), removing age-old tech debt. The Bzlmod migration tool is available to help with your migration. - All C++-related rules (including
cc_binary,cc_library, etc.) have been removed from Bazel and are now located inrules_cc. - The flag
--incompatible_autoload_externallynow defaults to the empty string (#23043), meaning that all language-specific rules will now need to be loaded from their respective modules (rules_cc,rules_java, etc). This marks the conclusion of the Starlarkification effort. - Bazel 9 enforces a minimum dependency on
protobufversion 33.4, which includes support for a prebuilt protobuf compiler. Users can set the--@protobuf//bazel/toolchains:prefer_prebuilt_protocflag to avoid having to buildprotoc. See the announcement on Protobuf News for more information.
Migration-Ready Incompatible Flags
The following flags are flipped in 9.0:
Users can use bazelisk --migrate with the BAZELISK_INCOMPATIBLE_FLAGS environment variable to test these flag flips with Bazel 8.x.
--combined_report(now defaults tolcov).--experimental_platform_in_output_dir(now defaults toAuto; #27575)--experimental_retain_test_configuration_across_testonly(#28075)--incompatible_autoload_externally(now defaults to the empty string; #23043)--incompatible_bazel_test_exec_run_under(#23179)--incompatible_compact_repo_mapping_manifest(#26262)--incompatible_disable_autoloads_in_main_repo(#25755)--incompatible_disable_native_repo_rules(#22080)--incompatible_enable_proto_toolchain_resolution(#28182)
The following flags will be flipped in a future major release:
--incompatible_eagerly_resolve_select_keys(#26281)--incompatible_config_setting_private_default_visibility(#12933)--incompatible_disable_starlark_host_transitions(#17032)--incompatible_exclude_starlark_flags_from_exec_config(#26909)
General
- [Incompatible] The
--watchfsstartup option has been removed. Use the--watchfscommand option instead. - [Incompatible] The
--verbose_explanationsflag is now a no-op: the additional information it produced wasn't useful enough to justify the memory cost of the additional bookkeeping. - [Incompatible] The
--experimental_split_xml_generationflag no longer exists. - [Incompatible] The long-deprecated
--remote_default_platform_propertiesflag and its--host_platform_remote_properties_overridesynonym have been removed. Use--remote_default_exec_propertiesinstead. - [Incompatible] The
--incompatible_sandbox_hermetic_tmpflag has been removed. To mount the entire/tmpdirectory into the sandbox, specify--sandbox_add_mount_pair=/tmp. - [Incompatible] The
--run_envflag now has lower priority than theenvattribute on specific targets. This is in line with existing behavior of other flags like--test_env. - [Incompatible] When
--modify_execution_infois specified multiple times, the individual values are now all interpreted in order rather than only the value specified last. - The "
bazel --quiet" startup option can now be used to make Bazel emit much less output. - Commands executed by "
bazel run" now have two extra environment variables:$BUILD_IDindicates the id of the Bazel command and$BUILD_EXECROOTindicates the execroot of the Bazel server. - The progress of completed configured aspects is now shown in the UI, next to the number of completed targets. Example: "(100 packages loaded, 10000 targets configured, 500 aspect applications)".
--max_idle_secsnow takes system sleep time into account when deciding when to shutdown the Bazel server.- Soft-deprecated bazel startup option
--write_command_log. Users should switch to use the command option with the same name or look at the build event messages. - Added
--verbose_visibility_errorsfor printing more information when a visibility violation occurs.
Build Event Protocol
- The gRPC downloader now sends
Fetchevents to the BES. - Added a new flag `--incompatible_bep_cpu_from_platform` (defaults to false). When set to true, the values of `Configuration.platform_name` and `Configuration.cpu` will be obtained from `--experimental_override_platform_cpu_name` mapping for the target platform or the CPU constraint of the platform if a mapping does not exist.
- The BEP now includes the critical path time (
critical_path_timeinTimingMetrics).
C++ / Objective-C
- [Incompatible] As noted in the Highlights section, all C++ rules have been removed from Bazel and must be loaded from
@rules_cc. These includecc_binary,cc_import,cc_library,cc_shared_library,cc_static_library,cc_test,cc_toolchain,cc_toolchain_alias,objc_import,objc_library,fdo_prefetch_hints,fdo_profile,memprof_profile,propeller_optimize. - [Incompatible] Removed the
--incompatible_enable_cc_test_featureflag. The functionality this was intended for was never completed, and is no longer needed. - [Incompatible]
linking_context.linkstampshas been removed. - [Incompatible] Bazel now uses
-Iinstead of-isystemforcc_library/cc_binaryincludesattr. To use-isystemfor only external repositories, you can pass--features=external_include_paths --host_features=external_include_paths. To use-isystemfor a singlecc_library/cc_binaryincludes, you can setfeatures = ["system_include_paths"]on the target. - Tool paths specified in
cc_toolchainaction configs are now normalized based on the current execution platform's OS rather than the host OS. In particular, Windows-style absolute paths are now treated as absolute paths when building on a Windows executor from a non-Windows host. - Introductory support for C++20 modules; it supports
cc_librarywith a single module interface.
Configurability / cquery
- [Incompatible] Constraints and toolchain requirements on the default exec group no longer apply to the test exec group, which configures test actions. This includes, for example, the
rule()function'stoolchainsparameter andexec_compatible_with. To configure test actions, useexec_group_compatible_withor define an explicit test exec group with toolchain requirements on test rules that require it. - [Incompatible] Changing
--test_envno longer invalidates the analysis cache.ctx.configuration.test_envmay be empty for non-test rules and should not be used by them. - [Incompatible] Python rules can no longer set runtimes with
--python_top(--incompatible_use_python_toolchains=falseno longer works). See https://rules-python.readthedocs.io/en/latest/toolchains.html for toolchain & runtime configuration guidance. - [Incompatible]
--incompatible_bazel_test_exec_run_underis now enabled by default, which means that the target in a invocation will be built for each test's execution platform.
Coverage
- [Incompatible] Baseline coverage files for individual tests are no longer announced in the BES. Instead, a new
baseline_report.lcovfile containing the merged baseline coverage information for the entire invocation is now announced in the BES. It is also still merged into the combined report. - Baseline coverage files are now included in the combined report.
LCOVparsing does not break on FN lines including an end line number.- Rules can now register their own baseline coverage files in
LCOVformat via the newbaseline_coverage_filesparameter ofctx.instrumented_files_info. If the target matches the instrumentation filter, Bazel will merge the data into the combined coverage report generated with--combined_report. - Branches will always be merged as best as possible based on branch and block numbers during coverage report generation.
External Dependencies
- [Incompatible] As noted in the Highlights section, Bzlmod is now always enabled, and all
WORKSPACElogic has been removed from Bazel (#26131). The--enable_bzlmodand--enable_workspaceflags are now no-ops. - [Incompatible] The
bazel synccommand has been removed. Usebazel fetch --allinstead. - [Incompatible] The Python
sixlibrary is no longer included in@bazel_tools. - [Incompatible] The legacy
@bazel_tools//tools/build_defs/repo:maven_rules.bzlrule for downloading Maven artifacts has been deleted. Consider migrating torules_jvm_externalif you are using this rule. - [Incompatible] The canonical names of repos created with
use_repo_rulehave changed to be more stable. This may require updating command-line flags such as--override_repositoryif you're using canonical repo names; however, note that--override_repositorynow also supports apparent repo names (see below). - [Incompatible]
--experimental_worker_for_repo_fetchingis removed. - [Incompatible] A
single_version_overridethat pins a module to a lower version than requested in abazel_depfor that module now results in an error instead of silently ignoring thebazel_depversion requirement. This is meant to catch a common source of bugs when updating abazel_depwithout noticing that it is overridden. - [Incompatible] Added and flipped
--incompatible_compact_repo_mapping_manifest, which causes the repo mapping manifest file for runfiles to use a more compact format when necessary. - [Incompatible] With
--experimental_check_external_repository_filesenabled (the default), Bazel will now refetch the respective repositories when it encounters external modifications. This is necessary to ensure correct incrementality. If you rely on external modifications to these repositories, either disable the flag or use a supported mechanism such as--override_repository,local_path_overrideoroverride_repo. --override_repositorynow supports apparent repository names from the point of view of the main repository. An unknown apparent repo name will result in an error.- Added a new flag
--repo_contents_cache(defaults to thecontentsdirectory under the ) where Bazel stores fetched contents of repos that can be safely cached across workspaces. A repo rule can indicate cacheability by returning from its implementation function.
Java
- [Incompatible]
--experimental_java_classpathnow defaults tobazel(was:javabuilder). This is expected to reduce the number of Java compilations running on incremental builds if a remote or disk cache is used. Other types of builds are not expected to be negatively affected by this change. - Java tests are no longer run with a
SecurityManagerthat preventsSystem.exit, sinceSecurityManagerfunctionality is being removed from the JDK.System.exitcalls are still reported and fail the test. java_import.jarsattributes can no longer be empty, and--noincompatible_disallow_java_import_empty_jarsis no longer supported.singlejarcan exclude certain entries.- If a
java_importtarget'ssrcjarattribute refers to a source file, the file must exist.
Local Execution
- [Incompatible] The mnemonic passed to
--worker_extra_flagis now matched against the worker key mnemonic when one is available, instead of the action mnemonic. This makes it consistent with other worker flags taking a mnemonic. - On Linux, the default limit on the number of
--watchfsfile events per directory has been raised to 10,000 (from 500). If needed, it can be increased further via--host_jvm_args=-Djdk.nio.file.WatchService.maxEventsPerPoll=<limit>. - Copying outputs out of the sandbox has been optimized and is now up to 80% faster for tree artifacts with a large number of children.
- Added a new flag,
--sandbox_enable_loopback_device(defaults to true). If set to false, a loopback device will not be set up in thelinux-sandboxnetwork namespace for local actions. - Added a new startup flag
--experimental_run_in_user_cgroup(defaults to false). If set to true, the client creates a temporary script file called `systemd-wrapper.sh`, and thedaemonizebinary will run this script with `systemd-run` instead of running the Java server directly. This flag only works on Linux.
Performance
- Actions that create runfiles trees are now considered regular actions. This means that they are now reported in statistics, critical paths and the like.
- Changing any part of
--run_underthat isn't the label (such as the shell command) no longer invalidates the analysis cache. - Added flag
--experimental_thread_dump_intervalto allow Bazel dump threads periodically. This is especially helpful to debug hangs where Bazel runs unsupervised, e.g. on CI. - The contents of source directories are now tracked for invalidation. Using
globor explicit lists of files to consume source directories is still strongly preferred, but there may be cases in which this isn't feasible (e.g. file names that aren't valid labels). - NestedSet memoization has been replaced with weakly referenced lists, resulting in a reduction of up to 20% retained heap and 15% peak heap.
- Added a new flag
--gc_churning_threshold(an integer from 0 to 100; defaults to 100) to tell Bazel to give up if more than this percentage of wall time is spent performing GC. Another new flag,--gc_churning_threshold_if_multiple_top_level_targetswhich takes precedence if there are multiple top-level targets.
Remote Execution
- [Incompatible] Flag
--incompatible_remote_use_new_exit_code_for_lost_inputsis deleted. - [Incompatible] When remote execution fails and an action is executed locally, modifications of its inputs during execution are now checked according to the value of the
--guard_against_concurrent_changesflag rather than as if that flag was set tofull. - The Merkle tree implementation used by remote caching and execution has been reworked, resulting in up to a 30% wall time and 70% peak heap reduction.
- The new flag
--remote_max_concurrency_per_connectioncan be used to specify the maximum number of concurrent gRPC requests Bazel will issue on a single connection to the server. The default value of 100 matches the previous behavior. - Directories matched by
--remote_download_regexwill now be fully downloaded. Previously, directory-only matches would result in an empty directory. - Added support for Zstd, Deflate and Snappy encoding to HTTP remote caches.
- Setting
--remote_grpc_log=(the empty string) will now disable the remote gRPC log (previously it would throw an error).
Starlark / Build Language
- Global functions and built-in data types:
- [Incompatible] Starlark
range()function, the stringsplit()andrsplit()methods, and listindex()andpop()methods no longer acceptNoneas argument values. - The string
split()andrsplit()methods now allowsepandmaxsplitto be provided as keyword arguments. - (Also in 8.1.0+) Added a
setdata type to Starlark.
- [Incompatible] Starlark
- Rules API:
- [Incompatible] Legacy
structproviders are no longer supported. The--incompatible_disallow_struct_provider_syntaxflag is now a no-op. - [Incompatible] Strings in attribute's "
provides" parameters are no longer supported. - The new
attr.label_list_dicttype accepts a dict in which keys are strings and values are lists of labels. - Turn the vestigial
distribsattribute into a no-op. - The (deprecated)
output_licensesattribute is now a string list rather than an internal data type. The only visible change may be that some query output may change from printing capitalized values of inputs will now show lower case. - Materializer functions now have access to the label of the rule they are running on as
ctx.label. - Adds
ctx.rule.varto allow aspects to get rule-specific variables, and removes rule-specific variables from an aspect'sctx.vardict. - The mnemonic of a file write action can now be set via the
mnemonicparameter ofctx.actions.write. ctx.actions.writenow supports path mapping when passed anArgsobject. Use themnemonicsattribute to assign it a dedicated mnemonic, which can then be used with--modify_execution_infoto opt in to path mapping (see #22658 for details on path mapping).ctx.actions.symlinknow accepts atarget_typeargument.
- [Incompatible] Legacy
- Symbolic macros:
- [Incompatible] Starlark computation step limits are now enforced for symbolic macros.
Windows
- If a cc toolchain feature named
shorten_virtual_includesis enabled, virtual include header files are linked underbin/_virtual_includes/<hash of target path>instead ofbin/<target package path>/_virtual_includes/<target name>. With rules_cc 0.1.3 or later, this shortens the virtual include paths which is critical for mitigating long path issues with MSVC on Windows. - Tool paths specified in
cc_toolchainaction configs are now normalized based on the current execution platform's OS rather than the host OS. In particular, Windows-style absolute paths are now treated as absolute paths when building on a Windows executor from a non-Windows host. ctx.actions.symlinkwith atarget_fileargument will now create a symlink or junction as appropriate for the target artifact type (file or directory), even when building without the bytes; with atarget_pathargument, the type may be manually specified via the newtarget_typeargument.- Bazel now falls back gracefully instead of crashing on Windows filesystems that do not support junctions (such as
virtiofsor VirtualBox shared folders).
Appendix
The following flags have been removed:
--experimental_add_exec_constraints_to_targets--experimental_split_xml_generation--experimental_worker_for_repo_fetching--incompatible_enable_cc_test_feature--incompatible_remote_use_new_exit_code_for_lost_inputs--incompatible_sandbox_hermetic_tmp--verbose_explanations--watchfs(startup option)
The following flags are now no-ops:
--enable_bzlmod--enable_workspace--experimental_bep_target_summary--incompatible_disable_native_repo_rules--incompatible_legacy_local_fallback--incompatible_use_python_toolchains--legacy_external_runfiles--verbose_explanations
Acknowledgements:
This release contains contributions from many people at Google, as well as Aaron Sky, Adin Cebic, Adrian Vogelsgesang, Agustin Mista, Alan Mond, Alberto Cavalcante, Alessandro Patti, Alex Eagle, Alex Fax, Alexander Golovlev, Ankush Chudiwal, Austin Schuh, Benjamin Peterson, Benji Vos, Benson Muite, Bo Zhang, Boleyn Su, Bradley Bridges, Chris Sauer, Christian Scott, Christopher Rydell, Chuck Grindel, Cornelius Riemenschneider, David Sanderson, David Zbarsky, DeeperMind, Dimi Shahbaz, Dmitry Ivankov, Dmitry Ryabkov, Ed Schouten, Eric Riff, Fabian Meumertzheim, Farid Zakaria, Fredrik Medley, George Gensure, Grzegorz Lukasik, Han-Wen Nienhuys, Honnix, Ian Stapleton Cordasco, jacqueline.lee, Jaden Peterson, James Jenkins, James Judd, Javier Maestro, Jay Conrod, Jim Carroll, jjudd, John Millikin, Jon Shea, Jonathan Schear, Jonathan Woodbury, Jordan Mele, kalvdans, Keith Lea, Keith Smiley, Kevin Bernal, Kiron, kxxt, Lev Leontev, László Csomor, Lucas Loffel, Luis Padron, Marcus Eagan, Mark Reuter, Markus Hofbauer, Matt Brown, Matt Smith, Mike Lundy, Mislav Mandaric, Nathan Naze, nialdaly, Pareesh Madan, Pelikan.B, Peter Li, Peter Lukacs, Philipp Stephani, PikachuHy, Ricard Sol, Richard Woodbury, Roman Salvador, Rostislav Rumenov, Ruoyu Zhong, Ryan Matthews, Sara Adams, sarad, Simon Thornington, Siva Mahadevan, Son Luong Ngoc, Spencer Putt, Stephan Pleines, Steve Barrau, Taylor Barrella, tfrench, Thi Don, Timothy Gu, Tomasz Pasternak, Torgil Svensson, Ulrik Falklof, Valentin Grigorev, Vy Hong, Wade Carpenter, Will Stranton, Wojciech Mazur, xndcn, Yannic Bonenberger, Zachary Kipping, and Zhongpeng Lin.
Notice: Bazel installers contain binaries licensed under the GPLv2 with Classpath exception. Those installers should always be redistributed along with the source code.
Some versions of Bazel contain a bundled version of OpenJDK. The license of the bundled OpenJDK and other open-source components can be displayed by running the command bazel license. The vendor and version information of the bundled
OpenJDK can be displayed by running the command bazel info java-runtime. The binaries and source-code of the bundled OpenJDK can be downloaded from our mirror server.
Security: All our binaries are signed with our public key 3D5919B448457EE0.