diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index ad81ff272c62f..1738efbb9f802 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -1004,6 +1004,7 @@ fn link_natively( exit_status: prog.status, command: &cmd, escaped_output, + verbose: sess.opts.verbose, }; sess.dcx().emit_err(err); // If MSVC's `link.exe` was expected but the return code diff --git a/compiler/rustc_codegen_ssa/src/errors.rs b/compiler/rustc_codegen_ssa/src/errors.rs index f93cb52ea3ea2..344030387627d 100644 --- a/compiler/rustc_codegen_ssa/src/errors.rs +++ b/compiler/rustc_codegen_ssa/src/errors.rs @@ -349,6 +349,7 @@ pub(crate) struct LinkingFailed<'a> { pub exit_status: ExitStatus, pub command: &'a Command, pub escaped_output: String, + pub verbose: bool, } impl Diagnostic<'_, G> for LinkingFailed<'_> { @@ -359,7 +360,17 @@ impl Diagnostic<'_, G> for LinkingFailed<'_> { let contains_undefined_ref = self.escaped_output.contains("undefined reference to"); - diag.note(format!("{:?}", self.command)).note(self.escaped_output); + let command = format!("{:?}", self.command); + let width = 100; + match (self.verbose, command.len() > width) { + (false, true) => { + diag.note("to see the full command that was run, rerun with `--verbose` flag"); + } + (true, _) | (_, false) => { + diag.note(command); + } + } + diag.note(format!("output:\n{}", self.escaped_output)); // Trying to match an error from OS linkers // which by now we have no way to translate. diff --git a/src/tools/run-make-support/src/external_deps/rustc.rs b/src/tools/run-make-support/src/external_deps/rustc.rs index ffe10092cc28a..a7260c16b2ced 100644 --- a/src/tools/run-make-support/src/external_deps/rustc.rs +++ b/src/tools/run-make-support/src/external_deps/rustc.rs @@ -221,6 +221,11 @@ impl Rustc { self } + pub fn verbose(&mut self) -> &mut Self { + self.cmd.arg("--verbose"); + self + } + /// Specify json messages printed by the compiler pub fn json(&mut self, items: &str) -> &mut Self { self.cmd.arg(format!("--json={items}")); diff --git a/tests/run-make/linkage-attr-framework/rmake.rs b/tests/run-make/linkage-attr-framework/rmake.rs index 4450350f96e4b..feef4664b0882 100644 --- a/tests/run-make/linkage-attr-framework/rmake.rs +++ b/tests/run-make/linkage-attr-framework/rmake.rs @@ -2,7 +2,7 @@ //@ only-apple -use run_make_support::{Rustc, run, rustc}; +use run_make_support::{Rustc, diff, run, rustc}; fn compile(cfg: &str) -> Rustc { let mut rustc = rustc(); @@ -16,11 +16,15 @@ fn main() { run("main"); } - let errs = compile("omit").run_fail(); + let errs = compile("omit").verbose().run_fail(); // The linker's exact error output changes between Xcode versions, depends on // linker invocation details, and the linker sometimes outputs more warnings. errs.assert_stderr_contains_regex(r"error: linking with `.*` failed"); errs.assert_stderr_contains_regex(r"(Undefined symbols|ld: symbol[^\s]* not found)"); errs.assert_stderr_contains_regex(r".?_CFRunLoopGetTypeID.?, referenced from:"); errs.assert_stderr_contains("clang: error: linker command failed with exit code 1"); + // Ensure we don't show the full linker command by default. + let errs = compile("omit").run_fail().assert_stderr_contains( + "to see the full command that was run, rerun with `--verbose` flag", + ); }