Bazel 4.0 is a major release and Bazel’s first LTS release. It contains new features and backwards incompatible changes.
New features
- Starlark-defined flags can now be shorthanded using
--flag_alias
. - 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.
Incompatible changes
The following flags have been enabled by default:
--incompatible_objc_compile_info_migration
--incompatible_objc_provider_remove_compile_info
--incompatible_run_shell_command_string
--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_avoid_conflict_dlls=true
--incompatible_blacklisted_protos_requires_proto_info
--incompatible_force_strict_header_check_from_starlark
incompatible_require_linker_input_cc_api
: C++ Starlark API now requireslinker_inputs
wrappinglibrary_to_link
.--incompatible_proto_output_v2
for aquery, which applies a new, more compact aquery proto output format.
The following flag has been added:
--incompatible_display_source_file_location
has been added forbazel query --output=location
to 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_java_rules_from_bzl
and--incompatible_load_proto_rules_from_bzl
are now no-ops.--incompatible_string_replace_count
has been flipped and removed.--local_resources
and--incompatible_remove_local_resources
have been removed. If you've been setting--local resources
or--incompatible_remove_local_resources=false
, migrate to using--local_ram_resources
and--local_cpu_resources
instead.- The no-op
--deep_execroot
flag has been removed.
User Interface
- Error messages emitted when an action fails have been reworked to be more informative about the failing action.
Query
- Querying with
--output=location
now allows therelative_locations
flag to properly display relative locations instead of the full path. - The
--starlark:file
option allows the cquery feature in--output=starlark
mode to specify the expression to format output in a file.
Build Event Protocol
- The Build Event Protocol uses
AbortReason.OUT_OF_MEMORY
for abort events when the build tool is crashing due to OOM.
Starlark
- The Starlark JSON module is now available. Use
json.encode(x)
to encode a Starlark value becauseJSON. struct.to_json(x)
is deprecated and will be disabled by the--incompatible_struct_has_no_methods
flag. - Use
proto.encode_text(x)
to encode a Starlark value becausetextproto. struct.to_proto()
is deprecated and will be disabled by the--incompatible_struct_has_no_methods
flag. Both functions now reject list/dict fields that contain list/dict elements.
Android
- Support for using AndroidX dependencies in data-binding-enabled targets has been added.
- Data-binding generation for
android_local_test
has been fixed. - Instrumented files for transitive sources of
android_library
andandroid_binary
have been propagated.
Apple
- The
relative_ast_path
feature for darwin builds to relativize swiftmodule paths for debugging has been added. - The
--default_ios_provisioning_profile
flag has been removed (it was a no-op). debug_prefix_map_pwd_is_dot
feature 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
- With
--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.
Build Defs
//tools/build_defs/pkg:pkg_rpm
is no longer built in to Bazel. See migration instructions.
Python
py_binary
now tolerates package paths that contain hyphens ('-'). Note that such paths might not be importable from within Python code.
Toolchains
- The toolchain rule has been extended with the
target_settings
attribute.
Action Execution
- The new dynamic scheduler that is more resistant to network issues is now the default.
Documentation
- 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.