8 files changed +65
-10
lines changed Original file line number Diff line number Diff line change @@ -998,12 +998,12 @@ fn link_natively(
998
998
let mut output = prog. stderr . clone ( ) ;
999
999
output. extend_from_slice ( & prog. stdout ) ;
1000
1000
let escaped_output = escape_linker_output ( & output, flavor) ;
1001
- // FIXME: Add UI tests for this error.
1002
1001
let err = errors:: LinkingFailed {
1003
1002
linker_path : & linker_path,
1004
1003
exit_status : prog. status ,
1005
1004
command : & cmd,
1006
1005
escaped_output,
1006
+ verbose : sess. opts . verbose ,
1007
1007
} ;
1008
1008
sess. dcx ( ) . emit_err ( err) ;
1009
1009
// If MSVC's `link.exe` was expected but the return code
Original file line number Diff line number Diff line change @@ -349,6 +349,7 @@ pub(crate) struct LinkingFailed<'a> {
349
349
pub exit_status : ExitStatus ,
350
350
pub command : & ' a Command ,
351
351
pub escaped_output : String ,
352
+ pub verbose : bool ,
352
353
}
353
354
354
355
impl < G : EmissionGuarantee > Diagnostic < ' _ , G > for LinkingFailed < ' _ > {
@@ -359,7 +360,13 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for LinkingFailed<'_> {
359
360
360
361
let contains_undefined_ref = self . escaped_output . contains ( "undefined reference to" ) ;
361
362
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 ) ;
363
370
364
371
// Trying to match an error from OS linkers
365
372
// which by now we have no way to translate.
Original file line number Diff line number Diff line change @@ -319,6 +319,12 @@ impl Rustc {
319
319
self
320
320
}
321
321
322
+ /// Pass the `--verbose` flag.
323
+ pub fn verbose ( & mut self ) -> & mut Self {
324
+ self . cmd . arg ( "--verbose" ) ;
325
+ self
326
+ }
327
+
322
328
/// `EXTRARSCXXFLAGS`
323
329
pub fn extra_rs_cxx_flags ( & mut self ) -> & mut Self {
324
330
// Adapted from tools.mk (trimmed):
Original file line number Diff line number Diff line change @@ -15,15 +15,17 @@ fn main() {
15
15
. link_args ( "b c" )
16
16
. link_args ( "d e" )
17
17
. link_arg ( "f" )
18
+ . arg ( "--print=link-args" )
18
19
. run_fail ( )
19
- . assert_stderr_contains ( r#""a" "b" "c" "d" "e" "f""# ) ;
20
+ . assert_stdout_contains ( r#""a" "b" "c" "d" "e" "f""# ) ;
20
21
rustc ( )
21
22
. input ( "empty.rs" )
22
23
. linker_flavor ( linker)
23
24
. arg ( "-Zpre-link-arg=a" )
24
25
. arg ( "-Zpre-link-args=b c" )
25
26
. arg ( "-Zpre-link-args=d e" )
26
27
. arg ( "-Zpre-link-arg=f" )
28
+ . arg ( "--print=link-args" )
27
29
. run_fail ( )
28
- . assert_stderr_contains ( r#""a" "b" "c" "d" "e" "f""# ) ;
30
+ . assert_stdout_contains ( r#""a" "b" "c" "d" "e" "f""# ) ;
29
31
}
Original file line number Diff line number Diff line change @@ -14,13 +14,13 @@ fn main() {
14
14
rustc ( ) . input ( "depb.rs" ) . run ( ) ;
15
15
rustc ( ) . input ( "depc.rs" ) . run ( ) ;
16
16
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" ] ) ) ;
19
19
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" ] ) ) ;
24
24
// Adjacent identical native libraries are no longer deduplicated if
25
25
// they come from different crates (https://github.com/rust-lang/rust/pull/103311)
26
26
// so the following will fail:
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
1
+ fn main ( ) { }
Original file line number Diff line number Diff line change
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