@@ -213,6 +213,7 @@ fn rustc<'a, 'cfg>(
213
213
// If we are a binary and the package also contains a library, then we
214
214
// don't pass the `-l` flags.
215
215
let pass_l_flag = unit. target . is_lib ( ) || !unit. pkg . targets ( ) . iter ( ) . any ( |t| t. is_lib ( ) ) ;
216
+ let pass_link_args = unit. target . is_cdylib ( ) ;
216
217
let do_rename = unit. target . allows_underscores ( ) && !unit. mode . is_any_test ( ) ;
217
218
let real_name = unit. target . name ( ) . to_string ( ) ;
218
219
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) ?;
@@ -344,6 +346,7 @@ fn rustc<'a, 'cfg>(
344
346
build_state : & BuildMap ,
345
347
build_scripts : & BuildScripts ,
346
348
pass_l_flag : bool ,
349
+ pass_link_args : bool ,
347
350
current_id : & PackageId ,
348
351
) -> CargoResult < ( ) > {
349
352
for key in build_scripts. to_link . iter ( ) {
@@ -365,9 +368,11 @@ fn rustc<'a, 'cfg>(
365
368
rustc. arg ( "-l" ) . arg ( name) ;
366
369
}
367
370
}
368
- for arg in output. linker_args . iter ( ) {
369
- let link_arg = format ! ( "link-arg={}" , arg) ;
370
- rustc. arg ( "-C" ) . arg ( link_arg) ;
371
+ if pass_link_args {
372
+ for arg in output. linker_args . iter ( ) {
373
+ let link_arg = format ! ( "link-arg={}" , arg) ;
374
+ rustc. arg ( "-C" ) . arg ( link_arg) ;
375
+ }
371
376
}
372
377
}
373
378
}
0 commit comments