2023-01-19 16:48:50 +00:00
|
|
|
###############################################################################
|
|
|
|
## Bazel Configuration Flags
|
|
|
|
##
|
|
|
|
## `.bazelrc` is a Bazel configuration file.
|
|
|
|
## https://bazel.build/docs/best-practices#bazelrc-file
|
|
|
|
###############################################################################
|
|
|
|
|
2023-06-13 17:34:14 +00:00
|
|
|
# https://bazel.build/reference/command-line-reference#flag--enable_platform_specific_config
|
|
|
|
common --enable_platform_specific_config
|
|
|
|
|
2023-01-19 16:48:50 +00:00
|
|
|
# https://bazel.build/docs/windows#symlink
|
|
|
|
startup --windows_enable_symlinks
|
2023-06-02 11:34:55 +00:00
|
|
|
build:windows --enable_runfiles
|
|
|
|
|
2023-06-13 17:34:14 +00:00
|
|
|
# Enable the only currently supported report type
|
|
|
|
# https://bazel.build/reference/command-line-reference#flag--combined_report
|
|
|
|
coverage --combined_report=lcov
|
|
|
|
|
2023-06-23 11:45:35 +00:00
|
|
|
# Avoid fully cached builds reporting no coverage and failing CI
|
|
|
|
# https://bazel.build/reference/command-line-reference#flag--experimental_fetch_all_coverage_outputs
|
|
|
|
coverage --experimental_fetch_all_coverage_outputs
|
|
|
|
|
2024-01-05 16:31:08 +00:00
|
|
|
# Required for some of the tests
|
|
|
|
# https://bazel.build/reference/command-line-reference#flag--experimental_cc_shared_library
|
|
|
|
common --experimental_cc_shared_library
|
|
|
|
|
2023-01-19 16:48:50 +00:00
|
|
|
###############################################################################
|
|
|
|
## Unique configuration groups
|
|
|
|
###############################################################################
|
2021-06-01 21:18:58 +00:00
|
|
|
|
2024-04-05 15:07:18 +00:00
|
|
|
# Enable use of the nightly toolchains.
|
|
|
|
build:nightly --//rust/toolchain/channel=nightly
|
|
|
|
|
2021-06-01 21:18:58 +00:00
|
|
|
# Enable rustfmt for all targets in the workspace
|
|
|
|
build:rustfmt --aspects=//rust:defs.bzl%rustfmt_aspect
|
|
|
|
build:rustfmt --output_groups=+rustfmt_checks
|
2021-07-10 16:22:07 +00:00
|
|
|
|
|
|
|
# Enable clippy for all targets in the workspace
|
|
|
|
build:clippy --aspects=//rust:defs.bzl%rust_clippy_aspect
|
|
|
|
build:clippy --output_groups=+clippy_checks
|
2021-08-20 21:44:39 +00:00
|
|
|
|
Added `rust_unpretty_aspect` and `rust_unpretty` rules (#2356)
Proposal for https://github.com/bazelbuild/rules_rust/issues/1642
Duplicates https://github.com/bazelbuild/rules_rust/pull/1643 (special
thanks to @freeformstu)
### Summary
Rustc can be used to expand all macros so that you can inspect the
generated source files easier.
This feature is enabled via `-Zunpretty={mode}`. The `-Z` flag is only
available in the nightly
version of `rustc` (https://github.com/rust-lang/rust/issues/43364).
### Unprettying
Build and test your targets normally.
```
bazel build //:ok_binary
INFO: Analyzed target //:ok_binary (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //:ok_binary up-to-date:
bazel-bin/ok_binary
INFO: Elapsed time: 0.081s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
```
Use the aspect to generate the expanded files in as a one-off build.
(`.bazelrc`)
```
# Enable unpretty for all targets in the workspace
build:unpretty --aspects=@rules_rust//rust:defs.bzl%rust_unpretty_aspect
build:unpretty --output_groups=+rust_unpretty
# `unpretty` requires the nightly toolchain. See tracking issue:
# https://github.com/rust-lang/rust/issues/43364
build:unpretty --@rules_rust//rust/toolchain/channel=nightly
```
```
bazel build --config=unpretty //:ok_binary
INFO: Analyzed target //:ok_binary (1 packages loaded, 2 targets configured).
INFO: Found 1 target...
Aspect @rules_rust//rust/private:unpretty.bzl%rust_unpretty_aspect of //:ok_binary up-to-date:
bazel-bin/ok_binary.expand.rs
INFO: Elapsed time: 0.149s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
```
Targeting tests is valid as well.
```
bazel build --config=unpretty //:ok_test
INFO: Analyzed target //:ok_test (0 packages loaded, 2 targets configured).
INFO: Found 1 target...
Aspect @rules_rust//rust/private:unpretty.bzl%rust_expand_aspect of //:ok_test up-to-date:
bazel-bin/test-397521499/ok_test.expand.rs
INFO: Elapsed time: 0.113s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
```
Finally, manually wire up a `rust_unpretty` target explicitly if you
want a target to build. This rule is unique compared to the aspect in
that it forces a transition to a nightly toolchain so that `-Zunpretty`
can be used.
```starlark
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_unpretty")
rust_binary(
name = "ok_binary",
srcs = ["src/main.rs"],
edition = "2021",
)
rust_unpretty(
name = "ok_binary_expand",
deps = [":ok_binary"],
)
```
```
bazel build //:ok_binary_expand
INFO: Analyzed target //:ok_binary_expand (0 packages loaded, 1 target configured).
INFO: Found 1 target...
Target //:ok_binary_expand up-to-date:
bazel-bin/ok_binary.expand.rs
INFO: Elapsed time: 0.090s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
```
2023-12-27 17:02:43 +00:00
|
|
|
# Enable unpretty for all targets in the workspace
|
|
|
|
build:unpretty --aspects=//rust:defs.bzl%rust_unpretty_aspect
|
|
|
|
build:unpretty --output_groups=+rust_unpretty
|
|
|
|
|
|
|
|
# `unpretty` requires the nightly toolchain. See tracking issue:
|
|
|
|
# https://github.com/rust-lang/rust/issues/43364
|
2024-04-05 15:07:18 +00:00
|
|
|
build:unpretty --config=nightly
|
Added `rust_unpretty_aspect` and `rust_unpretty` rules (#2356)
Proposal for https://github.com/bazelbuild/rules_rust/issues/1642
Duplicates https://github.com/bazelbuild/rules_rust/pull/1643 (special
thanks to @freeformstu)
### Summary
Rustc can be used to expand all macros so that you can inspect the
generated source files easier.
This feature is enabled via `-Zunpretty={mode}`. The `-Z` flag is only
available in the nightly
version of `rustc` (https://github.com/rust-lang/rust/issues/43364).
### Unprettying
Build and test your targets normally.
```
bazel build //:ok_binary
INFO: Analyzed target //:ok_binary (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //:ok_binary up-to-date:
bazel-bin/ok_binary
INFO: Elapsed time: 0.081s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
```
Use the aspect to generate the expanded files in as a one-off build.
(`.bazelrc`)
```
# Enable unpretty for all targets in the workspace
build:unpretty --aspects=@rules_rust//rust:defs.bzl%rust_unpretty_aspect
build:unpretty --output_groups=+rust_unpretty
# `unpretty` requires the nightly toolchain. See tracking issue:
# https://github.com/rust-lang/rust/issues/43364
build:unpretty --@rules_rust//rust/toolchain/channel=nightly
```
```
bazel build --config=unpretty //:ok_binary
INFO: Analyzed target //:ok_binary (1 packages loaded, 2 targets configured).
INFO: Found 1 target...
Aspect @rules_rust//rust/private:unpretty.bzl%rust_unpretty_aspect of //:ok_binary up-to-date:
bazel-bin/ok_binary.expand.rs
INFO: Elapsed time: 0.149s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
```
Targeting tests is valid as well.
```
bazel build --config=unpretty //:ok_test
INFO: Analyzed target //:ok_test (0 packages loaded, 2 targets configured).
INFO: Found 1 target...
Aspect @rules_rust//rust/private:unpretty.bzl%rust_expand_aspect of //:ok_test up-to-date:
bazel-bin/test-397521499/ok_test.expand.rs
INFO: Elapsed time: 0.113s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
```
Finally, manually wire up a `rust_unpretty` target explicitly if you
want a target to build. This rule is unique compared to the aspect in
that it forces a transition to a nightly toolchain so that `-Zunpretty`
can be used.
```starlark
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_unpretty")
rust_binary(
name = "ok_binary",
srcs = ["src/main.rs"],
edition = "2021",
)
rust_unpretty(
name = "ok_binary_expand",
deps = [":ok_binary"],
)
```
```
bazel build //:ok_binary_expand
INFO: Analyzed target //:ok_binary_expand (0 packages loaded, 1 target configured).
INFO: Found 1 target...
Target //:ok_binary_expand up-to-date:
bazel-bin/ok_binary.expand.rs
INFO: Elapsed time: 0.090s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
```
2023-12-27 17:02:43 +00:00
|
|
|
|
2023-01-19 16:48:50 +00:00
|
|
|
###############################################################################
|
|
|
|
## Incompatibility flags
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
# https://github.com/bazelbuild/bazel/issues/8195
|
|
|
|
build --incompatible_disallow_empty_glob=true
|
|
|
|
|
2023-01-20 12:08:30 +00:00
|
|
|
# https://github.com/bazelbuild/bazel/issues/12821
|
|
|
|
build --nolegacy_external_runfiles
|
|
|
|
|
2024-05-03 13:56:44 +00:00
|
|
|
# Required for cargo_build_script support before Bazel 7
|
|
|
|
build --incompatible_merge_fixed_and_default_shell_env
|
|
|
|
|
2023-10-06 16:01:55 +00:00
|
|
|
###############################################################################
|
|
|
|
## Bzlmod
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
# TODO: migrate all dependencies from WORKSPACE to MODULE.bazel
|
|
|
|
# https://github.com/bazelbuild/rules_rust/issues/2181
|
2024-10-04 00:34:54 +00:00
|
|
|
common --noenable_bzlmod --enable_workspace
|
2023-10-06 16:01:55 +00:00
|
|
|
|
2024-04-03 15:38:38 +00:00
|
|
|
# Disable the bzlmod lockfile, so we don't accidentally commit MODULE.bazel.lock
|
|
|
|
common --lockfile_mode=off
|
|
|
|
|
2023-12-19 15:25:18 +00:00
|
|
|
###############################################################################
|
|
|
|
## Custom user flags
|
|
|
|
##
|
|
|
|
## This should always be the last thing in the `.bazelrc` file to ensure
|
|
|
|
## consistent behavior when setting flags in that file as `.bazelrc` files are
|
|
|
|
## evaluated top to bottom.
|
|
|
|
###############################################################################
|
|
|
|
|
2022-03-01 14:59:47 +00:00
|
|
|
try-import %workspace%/user.bazelrc
|