Skip to content

Suppress noisy build script warnings#4046

Open
pauldraper wants to merge 2 commits into
bazelbuild:mainfrom
pauldraper:pauldraper/cargo-build-script-warnings
Open

Suppress noisy build script warnings#4046
pauldraper wants to merge 2 commits into
bazelbuild:mainfrom
pauldraper:pauldraper/cargo-build-script-warnings

Conversation

@pauldraper
Copy link
Copy Markdown

@pauldraper pauldraper commented May 18, 2026

Fixes #3880.

cargo::warning= lines from build.rs are forwarded to stderr unconditionally, which is noisy for -sys crates such as zstd-sys, aws-lc-sys, openssl-sys. Under Cargo these warnings are hidden for registry/git deps unless the build fails or the user passes -vv; under rules_rust the user always sees them.

This PR adds two complementary fixes (both discussed on the issue):

  1. Global flag --@rules_rust//cargo/settings:emit_build_script_warnings (default auto). Values:
    • on — emit for every target, overriding any per-target opt-out (useful for debugging an -sys crate).
    • auto — respect the per-target emit_warnings attribute. crate_universe-generated targets opt out, so registry crates stay quiet (matching Cargo); first-party targets emit by default.
    • off — silence build-wide.
  2. Per-target attribute cargo_build_script(emit_warnings = ...) (default True). crate_universe renders generated cargo_build_script targets with emit_warnings = False. Honored only when the global flag is auto.

@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 18, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@pauldraper pauldraper force-pushed the pauldraper/cargo-build-script-warnings branch from edd527a to 0f5334e Compare May 18, 2026 12:49
`cargo::warning=` lines emitted by `build.rs` are forwarded to stderr
unconditionally, which is noisy for `-sys` crates like `zstd-sys` and
`aws-lc-sys` whose warnings the consumer cannot act on (issue bazelbuild#3880).

Add two ways to silence them:
- `//cargo/settings:emit_build_script_warnings` (default `auto`): a
  global flag with values `on` / `auto` / `off`. `on` forces emit,
  `off` silences build-wide, `auto` defers to the per-target attr.
- `cargo_build_script(emit_warnings = ...)` (default `True`):
  a per-target attribute that silences a single build script when the
  global flag is `auto`.

The runner reads `RULES_RUST_SUPPRESS_BUILD_SCRIPT_WARNINGS` from its
env to decide.
Render `emit_warnings = False` on every generated `cargo_build_script`
target, matching Cargo's default behavior for registry/git crates
(warnings are only surfaced when the build fails or under `-vv`). Users
can re-enable per-target with additive build content if they need the
output, or globally with the new
`//cargo/settings:emit_build_script_warnings=on` flag.

Existing checked-in 3rdparty BUILD files will pick up the change on the
next `crates_vendor` run; no manual edits required.

Refs bazelbuild#3880.
@pauldraper pauldraper force-pushed the pauldraper/cargo-build-script-warnings branch from 0f5334e to b5ad05c Compare May 18, 2026 12:52
@UebelAndre UebelAndre self-requested a review May 18, 2026 15:19
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.

How to suppress cargo build script warnings with msvc?

1 participant