1
1
use super :: job:: { Freshness , Job , Work } ;
2
- use super :: { fingerprint, Context , Unit } ;
2
+ use super :: { fingerprint, Context , LinkType , Unit } ;
3
3
use crate :: core:: compiler:: context:: Metadata ;
4
4
use crate :: core:: compiler:: job_queue:: JobState ;
5
5
use crate :: core:: { profiles:: ProfileRoot , PackageId } ;
@@ -23,7 +23,7 @@ pub struct BuildOutput {
23
23
/// Names and link kinds of libraries, suitable for the `-l` flag.
24
24
pub library_links : Vec < String > ,
25
25
/// Linker arguments suitable to be passed to `-C link-arg=<args>`
26
- pub linker_args : Vec < String > ,
26
+ pub linker_args : Vec < ( Option < LinkType > , String ) > ,
27
27
/// Various `--cfg` flags to pass to the compiler.
28
28
pub cfgs : Vec < String > ,
29
29
/// Additional environment variables to run the compiler with.
@@ -290,6 +290,8 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
290
290
paths:: create_dir_all ( & script_dir) ?;
291
291
paths:: create_dir_all ( & script_out_dir) ?;
292
292
293
+ let extra_link_arg = cx. bcx . config . cli_unstable ( ) . extra_link_arg ;
294
+
293
295
// Prepare the unit of "dirty work" which will actually run the custom build
294
296
// command.
295
297
//
@@ -393,8 +395,13 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
393
395
paths:: set_file_time_no_err ( output_file, timestamp) ;
394
396
paths:: write ( & err_file, & output. stderr ) ?;
395
397
paths:: write ( & root_output_file, util:: path2bytes ( & script_out_dir) ?) ?;
396
- let parsed_output =
397
- BuildOutput :: parse ( & output. stdout , & pkg_name, & script_out_dir, & script_out_dir) ?;
398
+ let parsed_output = BuildOutput :: parse (
399
+ & output. stdout ,
400
+ & pkg_name,
401
+ & script_out_dir,
402
+ & script_out_dir,
403
+ extra_link_arg,
404
+ ) ?;
398
405
399
406
if json_messages {
400
407
emit_build_output ( state, & parsed_output, script_out_dir. as_path ( ) , id) ?;
@@ -418,6 +425,7 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
418
425
& pkg_name,
419
426
& prev_script_out_dir,
420
427
& script_out_dir,
428
+ extra_link_arg,
421
429
) ?,
422
430
} ;
423
431
@@ -467,13 +475,15 @@ impl BuildOutput {
467
475
pkg_name : & str ,
468
476
script_out_dir_when_generated : & Path ,
469
477
script_out_dir : & Path ,
478
+ extra_link_arg : bool ,
470
479
) -> CargoResult < BuildOutput > {
471
480
let contents = paths:: read_bytes ( path) ?;
472
481
BuildOutput :: parse (
473
482
& contents,
474
483
pkg_name,
475
484
script_out_dir_when_generated,
476
485
script_out_dir,
486
+ extra_link_arg,
477
487
)
478
488
}
479
489
@@ -484,6 +494,7 @@ impl BuildOutput {
484
494
pkg_name : & str ,
485
495
script_out_dir_when_generated : & Path ,
486
496
script_out_dir : & Path ,
497
+ extra_link_arg : bool ,
487
498
) -> CargoResult < BuildOutput > {
488
499
let mut library_paths = Vec :: new ( ) ;
489
500
let mut library_links = Vec :: new ( ) ;
@@ -536,7 +547,23 @@ impl BuildOutput {
536
547
}
537
548
"rustc-link-lib" => library_links. push ( value. to_string ( ) ) ,
538
549
"rustc-link-search" => library_paths. push ( PathBuf :: from ( value) ) ,
539
- "rustc-cdylib-link-arg" => linker_args. push ( value. to_string ( ) ) ,
550
+ "rustc-link-arg-cdylib" | "rustc-cdylib-link-arg" => {
551
+ linker_args. push ( ( Some ( LinkType :: Cdylib ) , value) )
552
+ }
553
+ "rustc-link-arg-bins" => {
554
+ if extra_link_arg {
555
+ linker_args. push ( ( Some ( LinkType :: Bin ) , value) ) ;
556
+ } else {
557
+ warnings. push ( format ! ( "cargo:{} requires -Zextra-link-arg flag" , key) ) ;
558
+ }
559
+ }
560
+ "rustc-link-arg" => {
561
+ if extra_link_arg {
562
+ linker_args. push ( ( None , value) ) ;
563
+ } else {
564
+ warnings. push ( format ! ( "cargo:{} requires -Zextra-link-arg flag" , key) ) ;
565
+ }
566
+ }
540
567
"rustc-cfg" => cfgs. push ( value. to_string ( ) ) ,
541
568
"rustc-env" => env. push ( BuildOutput :: parse_rustc_env ( & value, & whence) ?) ,
542
569
"warning" => warnings. push ( value. to_string ( ) ) ,
@@ -785,12 +812,15 @@ fn prev_build_output(cx: &mut Context<'_, '_>, unit: &Unit) -> (Option<BuildOutp
785
812
. and_then ( |bytes| util:: bytes2path ( & bytes) )
786
813
. unwrap_or_else ( |_| script_out_dir. clone ( ) ) ;
787
814
815
+ let extra_link_arg = cx. bcx . config . cli_unstable ( ) . extra_link_arg ;
816
+
788
817
(
789
818
BuildOutput :: parse_file (
790
819
& output_file,
791
820
& unit. pkg . to_string ( ) ,
792
821
& prev_script_out_dir,
793
822
& script_out_dir,
823
+ extra_link_arg,
794
824
)
795
825
. ok ( ) ,
796
826
prev_script_out_dir,
0 commit comments