Skip to content

Commit

Permalink
fix: emit warnings as warnings when learning target info from rustc
Browse files Browse the repository at this point in the history
This is a horrible hack,
but at least it unblocks people who pass `-Awarnings` via RUSTFLAGS.

A long-term solution is a better interface
between build systems and the compiler.
See the discussion on Zulip:
https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/Improving.20communication.20interface.20between.20cargo.2Frustc

Fixes rust-lang#8010
  • Loading branch information
weihanglo committed Jan 8, 2025
1 parent 911e54c commit 325384c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/cargo/core/compiler/build_context/target_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ impl TargetInfo {
process.arg("--print=crate-name"); // `___` as a delimiter.
process.arg("--print=cfg");

// parse_crate_type() relies on "unsupported/unknown crate type" error message,
// so make warnings always emitted as warnings.
process.arg("-Wwarnings");

let (output, error) = rustc
.cached_output(&process, extra_fingerprint)
.with_context(|| {
Expand Down
8 changes: 4 additions & 4 deletions tests/testsuite/cross_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1283,11 +1283,11 @@ fn always_emit_warnings_as_warnings_when_learning_target_info() {
p.cargo("build -v --target")
.env("RUSTFLAGS", "-Awarnings")
.arg(&target)
.with_status(101)
.with_stderr_data(str![[r#"
[ERROR] output of --print=file-names missing when learning about target-specific information from rustc
command was: `rustc - --crate-name ___ --print=file-names -Awarnings --target wasm32-unknown-unknown --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=split-debuginfo --print=crate-name --print=cfg`
...
[COMPILING] foo v0.0.0 ([ROOT]/foo)
[RUNNING] `rustc --crate-name foo [..]-Awarnings[..]`
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
"#]])
.run();
}

0 comments on commit 325384c

Please sign in to comment.