Bazel 4.0 is a major release and Bazel’s first LTS release. It contains new features and backwards incompatible changes.
- Starlark-defined flags can now be shorthanded using
- Support has been added for building with a Java 15 toolchain.
- Targets incompatible with the platform can now be skipped. For more details, see the Platforms documentation.
- Java workers are now multithreaded by default, reducing memory overhead.
- Bazel 4.0 is our first release with long-term support.
The following flags have been enabled by default:
--incompatible_restrict_string_escapes=true. Unnecessary backslashes such as
\.in string literals now result in an error, instead of silently being treated as
\\.. To fix the error while preserving behavior, manually add another backslash. However, the error often signals the original code needs to be updated.
incompatible_require_linker_input_cc_api: C++ Starlark API now requires
--incompatible_proto_output_v2for aquery, which applies a new, more compact aquery proto output format.
The following flag has been added:
--incompatible_display_source_file_locationhas been added for
bazel query --output=locationto print the line 1 location of the actual source files instead of the source file targets.
The following flags have either been removed or are no-ops:
--incompatible_load_proto_rules_from_bzlare now no-ops.
--incompatible_string_replace_counthas been flipped and removed.
--incompatible_remove_local_resourceshave been removed. If you've been setting
--incompatible_remove_local_resources=false, migrate to using
- The no-op
--deep_execrootflag has been removed.
- Error messages emitted when an action fails have been reworked to be more informative about the failing action.
- Querying with
--output=locationnow allows the
relative_locationsflag to properly display relative locations instead of the full path.
--starlark:fileoption allows the cquery feature in
--output=starlarkmode to specify the expression to format output in a file.
Build Event Protocol
- The Build Event Protocol uses
AbortReason.OUT_OF_MEMORYfor abort events when the build tool is crashing due to OOM.
- The Starlark JSON module is now available. Use
json.encode(x)to encode a Starlark value because
JSON. struct.to_json(x)is deprecated and will be disabled by the
proto.encode_text(x)to encode a Starlark value because
textproto. struct.to_proto()is deprecated and will be disabled by the
--incompatible_struct_has_no_methodsflag. Both functions now reject list/dict fields that contain list/dict elements.
- Support for using AndroidX dependencies in data-binding-enabled targets has been added.
- Data-binding generation for
android_local_testhas been fixed.
- Instrumented files for transitive sources of
android_binaryhave been propagated.
relative_ast_pathfeature for darwin builds to relativize swiftmodule paths for debugging has been added.
--default_ios_provisioning_profileflag has been removed (it was a no-op).
debug_prefix_map_pwd_is_dotfeature has been enabled by default on macOS. This feature passes
-fdebug-prefix-map=$PWD=.for every compile to remove absolute paths from debug information.
Process Management / Sandboxing
--experimental_worker_multiplex, Javac workers now use a single multithreaded process, saving memory.
- Bazel returns exit code 36 (rather than 1) if it fails to start a subprocess in a local sandbox due to environmental issues, for example, if the argument list is too long.
//tools/build_defs/pkg:pkg_rpmis no longer built in to Bazel. See migration instructions.
py_binarynow tolerates package paths that contain hyphens ('-'). Note that such paths might not be importable from within Python code.
- The toolchain rule has been extended with the
- The new dynamic scheduler that is more resistant to network issues is now the default.
- A new release versioning page has ben published, covering versioning and the types of releases for Bazel users and contributors.
- Information about creating persistent workers and multiplex workers has been curated in a Persistent Workers section for ease of reference.
- A new Sandboxing page has been published, that covering how to use the sandboxing strategy to restrict file system access, and how to debug issues that may arise.
This release contains contributions from many people at Google, as well as Adam Liddell, Akira Baruah, Alex Eagle, Alexander Grund, Andrew Z Allen, Benjamin Peterson, Benson Muite, Brentley Jones, Cristian Hancila, Dan Halperin, Daniel Wagner-Hall, Dmitry Ivankov, Eric Cousineau, Gregor Jasny, Grzegorz Lukasik, Joe Lencioni, Jonathan Perry, Jonathon Belotti, Keith Smiley, Kevin Gessner, Matt Davis, Matt Mackay, Menny Even Danan, Neeraj Gupta, Philipp Schrader, Ricardo Delfin, Ryan Beasley, Samuel Giddins, Simon Bjorklen, Simon Stewart, Stiopa Koltsov, Thi Doan, ThomasCJY, Tom de Goede, V Vn Ngha, William A Rowe Jr, Yannic, Yannic Bonenberger, erenon, hollste, johnjbarton, vectoralpha.