11use super :: job:: { Freshness , Job , Work } ;
2- use super :: { fingerprint, Context , Unit } ;
2+ use super :: { fingerprint, Context , LinkType , Unit } ;
33use crate :: core:: compiler:: context:: Metadata ;
44use crate :: core:: compiler:: job_queue:: JobState ;
55use crate :: core:: { profiles:: ProfileRoot , PackageId } ;
@@ -23,7 +23,7 @@ pub struct BuildOutput {
2323 /// Names and link kinds of libraries, suitable for the `-l` flag.
2424 pub library_links : Vec < String > ,
2525 /// 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 ) > ,
2727 /// Various `--cfg` flags to pass to the compiler.
2828 pub cfgs : Vec < String > ,
2929 /// Additional environment variables to run the compiler with.
@@ -290,6 +290,8 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
290290 paths:: create_dir_all ( & script_dir) ?;
291291 paths:: create_dir_all ( & script_out_dir) ?;
292292
293+ let extra_link_arg = cx. bcx . config . cli_unstable ( ) . extra_link_arg ;
294+
293295 // Prepare the unit of "dirty work" which will actually run the custom build
294296 // command.
295297 //
@@ -393,8 +395,13 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
393395 paths:: set_file_time_no_err ( output_file, timestamp) ;
394396 paths:: write ( & err_file, & output. stderr ) ?;
395397 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+ ) ?;
398405
399406 if json_messages {
400407 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> {
418425 & pkg_name,
419426 & prev_script_out_dir,
420427 & script_out_dir,
428+ extra_link_arg,
421429 ) ?,
422430 } ;
423431
@@ -467,13 +475,15 @@ impl BuildOutput {
467475 pkg_name : & str ,
468476 script_out_dir_when_generated : & Path ,
469477 script_out_dir : & Path ,
478+ extra_link_arg : bool ,
470479 ) -> CargoResult < BuildOutput > {
471480 let contents = paths:: read_bytes ( path) ?;
472481 BuildOutput :: parse (
473482 & contents,
474483 pkg_name,
475484 script_out_dir_when_generated,
476485 script_out_dir,
486+ extra_link_arg,
477487 )
478488 }
479489
@@ -484,6 +494,7 @@ impl BuildOutput {
484494 pkg_name : & str ,
485495 script_out_dir_when_generated : & Path ,
486496 script_out_dir : & Path ,
497+ extra_link_arg : bool ,
487498 ) -> CargoResult < BuildOutput > {
488499 let mut library_paths = Vec :: new ( ) ;
489500 let mut library_links = Vec :: new ( ) ;
@@ -536,7 +547,23 @@ impl BuildOutput {
536547 }
537548 "rustc-link-lib" => library_links. push ( value. to_string ( ) ) ,
538549 "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+ }
540567 "rustc-cfg" => cfgs. push ( value. to_string ( ) ) ,
541568 "rustc-env" => env. push ( BuildOutput :: parse_rustc_env ( & value, & whence) ?) ,
542569 "warning" => warnings. push ( value. to_string ( ) ) ,
@@ -785,12 +812,15 @@ fn prev_build_output(cx: &mut Context<'_, '_>, unit: &Unit) -> (Option<BuildOutp
785812 . and_then ( |bytes| util:: bytes2path ( & bytes) )
786813 . unwrap_or_else ( |_| script_out_dir. clone ( ) ) ;
787814
815+ let extra_link_arg = cx. bcx . config . cli_unstable ( ) . extra_link_arg ;
816+
788817 (
789818 BuildOutput :: parse_file (
790819 & output_file,
791820 & unit. pkg . to_string ( ) ,
792821 & prev_script_out_dir,
793822 & script_out_dir,
823+ extra_link_arg,
794824 )
795825 . ok ( ) ,
796826 prev_script_out_dir,
0 commit comments