Skip to content

Commit 5e3558c

Browse files
committed
fix: emit warnings as warnings when learning rust target info
This is a horrible hack, It lets the rustc invocation for learning target info always emit warnings as warnings. 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 #8010
1 parent e57a2f4 commit 5e3558c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/cargo/core/compiler/build_context/target_info.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ impl TargetInfo {
206206
process.arg("--print=crate-name"); // `___` as a delimiter.
207207
process.arg("--print=cfg");
208208

209+
// parse_crate_type() relies on "unsupported/unknown crate type" error message,
210+
// so make warnings always emitted as warnings.
211+
process.arg("-Wwarnings");
212+
209213
let (output, error) = rustc
210214
.cached_output(&process, extra_fingerprint)
211215
.with_context(|| {

tests/testsuite/cross_compile.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,11 +1287,11 @@ fn always_emit_warnings_as_warnings_when_learning_target_info() {
12871287
p.cargo("build -v --target")
12881288
.env("RUSTFLAGS", "-Awarnings")
12891289
.arg(target)
1290-
.with_status(101)
12911290
.with_stderr_data(str![[r#"
1292-
[ERROR] output of --print=file-names missing when learning about target-specific information from rustc
1293-
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`
1294-
...
1291+
[COMPILING] foo v0.0.0 ([ROOT]/foo)
1292+
[RUNNING] `rustc --crate-name foo [..]-Awarnings[..]`
1293+
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
1294+
12951295
"#]])
12961296
.run();
12971297
}

0 commit comments

Comments
 (0)