@@ -211,6 +211,7 @@ fn rustc<'a, 'cfg>(
211
211
// If we are a binary and the package also contains a library, then we
212
212
// don't pass the `-l` flags.
213
213
let pass_l_flag = unit. target . is_lib ( ) || !unit. pkg . targets ( ) . iter ( ) . any ( |t| t. is_lib ( ) ) ;
214
+ let pass_link_args = unit. target . is_cdylib ( ) ;
214
215
let do_rename = unit. target . allows_underscores ( ) && !unit. mode . is_any_test ( ) ;
215
216
let real_name = unit. target . name ( ) . to_string ( ) ;
216
217
let crate_name = unit. target . crate_name ( ) ;
@@ -257,6 +258,7 @@ fn rustc<'a, 'cfg>(
257
258
& build_state,
258
259
& build_deps,
259
260
pass_l_flag,
261
+ pass_link_args,
260
262
current_id,
261
263
) ?;
262
264
add_plugin_deps ( & mut rustc, & build_state, & build_deps, & root_output) ?;
@@ -346,6 +348,7 @@ fn rustc<'a, 'cfg>(
346
348
build_state : & BuildMap ,
347
349
build_scripts : & BuildScripts ,
348
350
pass_l_flag : bool ,
351
+ pass_link_args : bool ,
349
352
current_id : PackageId ,
350
353
) -> CargoResult < ( ) > {
351
354
for key in build_scripts. to_link . iter ( ) {
@@ -367,9 +370,11 @@ fn rustc<'a, 'cfg>(
367
370
rustc. arg ( "-l" ) . arg ( name) ;
368
371
}
369
372
}
370
- for arg in output. linker_args . iter ( ) {
371
- let link_arg = format ! ( "link-arg={}" , arg) ;
372
- rustc. arg ( "-C" ) . arg ( link_arg) ;
373
+ if pass_link_args {
374
+ for arg in output. linker_args . iter ( ) {
375
+ let link_arg = format ! ( "link-arg={}" , arg) ;
376
+ rustc. arg ( "-C" ) . arg ( link_arg) ;
377
+ }
373
378
}
374
379
}
375
380
}
0 commit comments