Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 312f835

Browse files
committedNov 29, 2024
don't show the full linker args unless --verbose is passed
the linker arguments can be *very* long, especially for crates with many dependencies. often they are not useful. omit them unless the user specifically requests them.
1 parent 5bbbc09 commit 312f835

File tree

8 files changed

+65
-10
lines changed

8 files changed

+65
-10
lines changed
 

‎compiler/rustc_codegen_ssa/src/back/link.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -998,12 +998,12 @@ fn link_natively(
998998
let mut output = prog.stderr.clone();
999999
output.extend_from_slice(&prog.stdout);
10001000
let escaped_output = escape_linker_output(&output, flavor);
1001-
// FIXME: Add UI tests for this error.
10021001
let err = errors::LinkingFailed {
10031002
linker_path: &linker_path,
10041003
exit_status: prog.status,
10051004
command: &cmd,
10061005
escaped_output,
1006+
verbose: sess.opts.verbose,
10071007
};
10081008
sess.dcx().emit_err(err);
10091009
// If MSVC's `link.exe` was expected but the return code

‎compiler/rustc_codegen_ssa/src/errors.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ pub(crate) struct LinkingFailed<'a> {
349349
pub exit_status: ExitStatus,
350350
pub command: &'a Command,
351351
pub escaped_output: String,
352+
pub verbose: bool,
352353
}
353354

354355
impl<G: EmissionGuarantee> Diagnostic<'_, G> for LinkingFailed<'_> {
@@ -359,7 +360,13 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for LinkingFailed<'_> {
359360

360361
let contains_undefined_ref = self.escaped_output.contains("undefined reference to");
361362

362-
diag.note(format!("{:?}", self.command)).note(self.escaped_output);
363+
if self.verbose {
364+
diag.note(format!("{:?}", self.command));
365+
} else {
366+
diag.note("use `--verbose` to show all linker arguments");
367+
}
368+
369+
diag.note(self.escaped_output);
363370

364371
// Trying to match an error from OS linkers
365372
// which by now we have no way to translate.

‎src/tools/run-make-support/src/external_deps/rustc.rs

+6
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,12 @@ impl Rustc {
319319
self
320320
}
321321

322+
/// Pass the `--verbose` flag.
323+
pub fn verbose(&mut self) -> &mut Self {
324+
self.cmd.arg("--verbose");
325+
self
326+
}
327+
322328
/// `EXTRARSCXXFLAGS`
323329
pub fn extra_rs_cxx_flags(&mut self) -> &mut Self {
324330
// Adapted from tools.mk (trimmed):

‎tests/run-make/link-args-order/rmake.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@ fn main() {
1515
.link_args("b c")
1616
.link_args("d e")
1717
.link_arg("f")
18+
.arg("--print=link-args")
1819
.run_fail()
19-
.assert_stderr_contains(r#""a" "b" "c" "d" "e" "f""#);
20+
.assert_stdout_contains(r#""a" "b" "c" "d" "e" "f""#);
2021
rustc()
2122
.input("empty.rs")
2223
.linker_flavor(linker)
2324
.arg("-Zpre-link-arg=a")
2425
.arg("-Zpre-link-args=b c")
2526
.arg("-Zpre-link-args=d e")
2627
.arg("-Zpre-link-arg=f")
28+
.arg("--print=link-args")
2729
.run_fail()
28-
.assert_stderr_contains(r#""a" "b" "c" "d" "e" "f""#);
30+
.assert_stdout_contains(r#""a" "b" "c" "d" "e" "f""#);
2931
}

‎tests/run-make/link-dedup/rmake.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ fn main() {
1414
rustc().input("depb.rs").run();
1515
rustc().input("depc.rs").run();
1616

17-
let output = rustc().input("empty.rs").cfg("bar").run_fail();
18-
output.assert_stderr_contains(needle_from_libs(&["testa", "testb", "testa"]));
17+
let output = rustc().input("empty.rs").cfg("bar").arg("--print=link-args").run_fail();
18+
output.assert_stdout_contains(needle_from_libs(&["testa", "testb", "testa"]));
1919

20-
let output = rustc().input("empty.rs").run_fail();
21-
output.assert_stderr_contains(needle_from_libs(&["testa"]));
22-
output.assert_stderr_not_contains(needle_from_libs(&["testb"]));
23-
output.assert_stderr_not_contains(needle_from_libs(&["testa", "testa", "testa"]));
20+
let output = rustc().input("empty.rs").arg("--print=link-args").run_fail();
21+
output.assert_stdout_contains(needle_from_libs(&["testa"]));
22+
output.assert_stdout_not_contains(needle_from_libs(&["testb"]));
23+
output.assert_stdout_not_contains(needle_from_libs(&["testa", "testa", "testa"]));
2424
// Adjacent identical native libraries are no longer deduplicated if
2525
// they come from different crates (https://github.com/rust-lang/rust/pull/103311)
2626
// so the following will fail:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
fn main() {
2+
for arg in std::env::args() {
3+
match &*arg {
4+
"run_make_info" => println!("foo"),
5+
"run_make_warn" => eprintln!("warning: bar"),
6+
"run_make_error" => {
7+
eprintln!("error: baz");
8+
std::process::exit(1);
9+
}
10+
_ => (),
11+
}
12+
}
13+
}

‎tests/run-make/linker-warning/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fn main() {}
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use std::path::Path;
2+
3+
use run_make_support::rfs::remove_file;
4+
use run_make_support::{Rustc, rustc};
5+
6+
fn run_rustc() -> Rustc {
7+
let mut rustc = rustc();
8+
rustc.arg("main.rs").output("main").linker("./fake-linker");
9+
rustc
10+
}
11+
12+
fn main() {
13+
// first, compile our linker
14+
rustc().arg("fake-linker.rs").output("fake-linker").run();
15+
16+
// Make sure we don't show the linker args unless `--verbose` is passed
17+
run_rustc()
18+
.link_arg("run_make_error")
19+
.verbose()
20+
.run_fail()
21+
.assert_stderr_contains_regex("fake-linker.*run_make_error");
22+
run_rustc()
23+
.link_arg("run_make_error")
24+
.run_fail()
25+
.assert_stderr_not_contains_regex("fake-linker.*run_make_error");
26+
}

0 commit comments

Comments
 (0)
Failed to load comments.