@@ -269,7 +269,12 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
269
269
}
270
270
} )
271
271
. collect :: < Vec < _ > > ( ) ;
272
- let crate_name = unit. target . crate_name ( ) ;
272
+ let library_name = unit
273
+ . pkg
274
+ . targets ( )
275
+ . iter ( )
276
+ . find ( |t| t. is_lib ( ) )
277
+ . map ( |t| t. crate_name ( ) ) ;
273
278
let pkg_descr = unit. pkg . to_string ( ) ;
274
279
let build_script_outputs = Arc :: clone ( & cx. build_script_outputs ) ;
275
280
let id = unit. pkg . package_id ( ) ;
@@ -279,7 +284,7 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
279
284
let host_target_root = cx. files ( ) . host_dest ( ) . to_path_buf ( ) ;
280
285
let all = (
281
286
id,
282
- crate_name . clone ( ) ,
287
+ library_name . clone ( ) ,
283
288
pkg_descr. clone ( ) ,
284
289
Arc :: clone ( & build_script_outputs) ,
285
290
output_file. clone ( ) ,
@@ -399,7 +404,7 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
399
404
paths:: write ( & root_output_file, paths:: path2bytes ( & script_out_dir) ?) ?;
400
405
let parsed_output = BuildOutput :: parse (
401
406
& output. stdout ,
402
- crate_name ,
407
+ library_name ,
403
408
& pkg_descr,
404
409
& script_out_dir,
405
410
& script_out_dir,
@@ -421,12 +426,12 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
421
426
// itself to run when we actually end up just discarding what we calculated
422
427
// above.
423
428
let fresh = Work :: new ( move |state| {
424
- let ( id, crate_name , pkg_descr, build_script_outputs, output_file, script_out_dir) = all;
429
+ let ( id, library_name , pkg_descr, build_script_outputs, output_file, script_out_dir) = all;
425
430
let output = match prev_output {
426
431
Some ( output) => output,
427
432
None => BuildOutput :: parse_file (
428
433
& output_file,
429
- crate_name ,
434
+ library_name ,
430
435
& pkg_descr,
431
436
& prev_script_out_dir,
432
437
& script_out_dir,
@@ -478,7 +483,7 @@ fn insert_warnings_in_build_outputs(
478
483
impl BuildOutput {
479
484
pub fn parse_file (
480
485
path : & Path ,
481
- crate_name : String ,
486
+ library_name : Option < String > ,
482
487
pkg_descr : & str ,
483
488
script_out_dir_when_generated : & Path ,
484
489
script_out_dir : & Path ,
@@ -488,7 +493,7 @@ impl BuildOutput {
488
493
let contents = paths:: read_bytes ( path) ?;
489
494
BuildOutput :: parse (
490
495
& contents,
491
- crate_name ,
496
+ library_name ,
492
497
pkg_descr,
493
498
script_out_dir_when_generated,
494
499
script_out_dir,
@@ -499,11 +504,11 @@ impl BuildOutput {
499
504
500
505
// Parses the output of a script.
501
506
// The `pkg_descr` is used for error messages.
502
- // The `crate_name ` is used for determining if RUSTC_BOOTSTRAP should be allowed.
507
+ // The `library_name ` is used for determining if RUSTC_BOOTSTRAP should be allowed.
503
508
pub fn parse (
504
509
input : & [ u8 ] ,
505
510
// Takes String instead of InternedString so passing `unit.pkg.name()` will give a compile error.
506
- crate_name : String ,
511
+ library_name : Option < String > ,
507
512
pkg_descr : & str ,
508
513
script_out_dir_when_generated : & Path ,
509
514
script_out_dir : & Path ,
@@ -592,12 +597,21 @@ impl BuildOutput {
592
597
// behavior, so still only give a warning.
593
598
// NOTE: cargo only allows nightly features on RUSTC_BOOTSTRAP=1, but we
594
599
// want setting any value of RUSTC_BOOTSTRAP to downgrade this to a warning
595
- // (so that `RUSTC_BOOTSTRAP=crate_name` will work)
596
- let rustc_bootstrap_allows = |name : & str | {
600
+ // (so that `RUSTC_BOOTSTRAP=library_name` will work)
601
+ let rustc_bootstrap_allows = |name : Option < & str > | {
602
+ let name = match name {
603
+ // as of 2021, no binaries on crates.io use RUSTC_BOOTSTRAP, so
604
+ // fine-grained opt-outs aren't needed. end-users can always use
605
+ // RUSTC_BOOTSTRAP=1 from the top-level if it's really a problem.
606
+ None => return false ,
607
+ Some ( n) => n,
608
+ } ;
597
609
std:: env:: var ( "RUSTC_BOOTSTRAP" )
598
610
. map_or ( false , |var| var. split ( ',' ) . any ( |s| s == name) )
599
611
} ;
600
- if nightly_features_allowed || rustc_bootstrap_allows ( & * crate_name) {
612
+ if nightly_features_allowed
613
+ || rustc_bootstrap_allows ( library_name. as_deref ( ) )
614
+ {
601
615
warnings. push ( format ! ( "Cannot set `RUSTC_BOOTSTRAP={}` from {}.\n \
602
616
note: Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project.",
603
617
val, whence
@@ -610,7 +624,7 @@ impl BuildOutput {
610
624
help: If you're sure you want to do this in your project, set the environment variable `RUSTC_BOOTSTRAP={}` before running cargo instead.",
611
625
val,
612
626
whence,
613
- crate_name ,
627
+ library_name . as_deref ( ) . unwrap_or ( "1" ) ,
614
628
) ;
615
629
}
616
630
} else {
@@ -867,7 +881,11 @@ fn prev_build_output(cx: &mut Context<'_, '_>, unit: &Unit) -> (Option<BuildOutp
867
881
(
868
882
BuildOutput :: parse_file (
869
883
& output_file,
870
- unit. target . crate_name ( ) ,
884
+ unit. pkg
885
+ . targets ( )
886
+ . iter ( )
887
+ . find ( |t| t. is_lib ( ) )
888
+ . map ( |t| t. crate_name ( ) ) ,
871
889
& unit. pkg . to_string ( ) ,
872
890
& prev_script_out_dir,
873
891
& script_out_dir,
0 commit comments