@@ -213,6 +213,7 @@ fn rustc<'a, 'cfg>(
213
213
let do_rename = unit. target . allows_underscores ( ) && !unit. mode . is_any_test ( ) ;
214
214
let real_name = unit. target . name ( ) . to_string ( ) ;
215
215
let crate_name = unit. target . crate_name ( ) ;
216
+ let extra_link_arg = cx. bcx . config . cli_unstable ( ) . extra_link_arg ;
216
217
217
218
// Rely on `target_filenames` iterator as source of truth rather than rederiving filestem.
218
219
let rustc_dep_info_loc = if do_rename && cx. files ( ) . metadata ( unit) . is_none ( ) {
@@ -261,6 +262,7 @@ fn rustc<'a, 'cfg>(
261
262
& build_scripts,
262
263
pass_l_flag,
263
264
link_type,
265
+ extra_link_arg,
264
266
current_id,
265
267
) ?;
266
268
add_plugin_deps ( & mut rustc, & script_outputs, & build_scripts, & root_output) ?;
@@ -355,6 +357,7 @@ fn rustc<'a, 'cfg>(
355
357
build_scripts : & BuildScripts ,
356
358
pass_l_flag : bool ,
357
359
link_type : Option < LinkType > ,
360
+ extra_link_arg : bool ,
358
361
current_id : PackageId ,
359
362
) -> CargoResult < ( ) > {
360
363
for key in build_scripts. to_link . iter ( ) {
@@ -376,17 +379,15 @@ fn rustc<'a, 'cfg>(
376
379
rustc. arg ( "-l" ) . arg ( name) ;
377
380
}
378
381
}
379
-
380
382
if link_type. is_some ( ) {
381
- for arg in output
383
+ output
382
384
. linker_args
383
385
. iter ( )
384
386
. filter ( |x| x. 0 . is_none ( ) || x. 0 == link_type)
385
- . map ( |x| & x. 1 )
386
- {
387
- let link_arg = format ! ( "link-arg={}" , arg) ;
388
- rustc. arg ( "-C" ) . arg ( link_arg) ;
389
- }
387
+ . filter ( |x| x. 0 == Some ( LinkType :: Cdylib ) || extra_link_arg)
388
+ . for_each ( |x| {
389
+ rustc. arg ( "-C" ) . arg ( format ! ( "link-arg={}" , x. 1 ) ) ;
390
+ } ) ;
390
391
}
391
392
}
392
393
}
0 commit comments