From bcb5eebcfe286d91953f1eafb7f94b3ef5836c00 Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Wed, 8 Jan 2025 15:10:19 -0500 Subject: [PATCH] fix: emit warnings as warnings when learning rust target info 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/cargo#8010 --- src/cargo/core/compiler/build_context/target_info.rs | 4 ++++ tests/testsuite/cross_compile.rs | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cargo/core/compiler/build_context/target_info.rs b/src/cargo/core/compiler/build_context/target_info.rs index 1844073ae45..6a0bea3f79e 100644 --- a/src/cargo/core/compiler/build_context/target_info.rs +++ b/src/cargo/core/compiler/build_context/target_info.rs @@ -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(|| { diff --git a/tests/testsuite/cross_compile.rs b/tests/testsuite/cross_compile.rs index 6dbf4919df9..f80fa302b69 100644 --- a/tests/testsuite/cross_compile.rs +++ b/tests/testsuite/cross_compile.rs @@ -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(); }