@@ -215,6 +215,7 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
215
215
// don't pass the `-l` flags.
216
216
let pass_l_flag = unit. target . is_lib ( ) || !unit. pkg . targets ( ) . iter ( ) . any ( |t| t. is_lib ( ) ) ;
217
217
let link_type = unit. target . into ( ) ;
218
+ let extra_link_arg = cx. bcx . config . cli_unstable ( ) . extra_link_arg ;
218
219
219
220
let dep_info_name = match cx. files ( ) . metadata ( unit) {
220
221
Some ( metadata) => format ! ( "{}-{}.d" , unit. target. crate_name( ) , metadata) ,
@@ -263,6 +264,7 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
263
264
& build_scripts,
264
265
pass_l_flag,
265
266
link_type,
267
+ extra_link_arg,
266
268
current_id,
267
269
) ?;
268
270
add_plugin_deps ( & mut rustc, & script_outputs, & build_scripts, & root_output) ?;
@@ -345,6 +347,7 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
345
347
build_scripts : & BuildScripts ,
346
348
pass_l_flag : bool ,
347
349
link_type : Option < LinkType > ,
350
+ extra_link_arg : bool ,
348
351
current_id : PackageId ,
349
352
) -> CargoResult < ( ) > {
350
353
for key in build_scripts. to_link . iter ( ) {
@@ -366,17 +369,15 @@ fn rustc(cx: &mut Context<'_, '_>, unit: &Unit, exec: &Arc<dyn Executor>) -> Car
366
369
rustc. arg ( "-l" ) . arg ( name) ;
367
370
}
368
371
}
369
-
370
372
if link_type. is_some ( ) {
371
- for arg in output
373
+ output
372
374
. linker_args
373
375
. iter ( )
374
376
. filter ( |x| x. 0 . is_none ( ) || x. 0 == link_type)
375
- . map ( |x| & x. 1 )
376
- {
377
- let link_arg = format ! ( "link-arg={}" , arg) ;
378
- rustc. arg ( "-C" ) . arg ( link_arg) ;
379
- }
377
+ . filter ( |x| x. 0 == Some ( LinkType :: Cdylib ) || extra_link_arg)
378
+ . for_each ( |x| {
379
+ rustc. arg ( "-C" ) . arg ( format ! ( "link-arg={}" , x. 1 ) ) ;
380
+ } ) ;
380
381
}
381
382
}
382
383
}
0 commit comments