@@ -4,6 +4,7 @@ use crate::core::compiler::context::Metadata;
4
4
use crate :: core:: compiler:: job_queue:: JobState ;
5
5
use crate :: core:: { profiles:: ProfileRoot , PackageId } ;
6
6
use crate :: util:: errors:: { CargoResult , CargoResultExt } ;
7
+ use crate :: util:: interning:: InternedString ;
7
8
use crate :: util:: machine_message:: { self , Message } ;
8
9
use crate :: util:: { self , internal, paths, profile} ;
9
10
use cargo_platform:: Cfg ;
@@ -267,7 +268,8 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
267
268
}
268
269
} )
269
270
. collect :: < Vec < _ > > ( ) ;
270
- let pkg_name = unit. pkg . to_string ( ) ;
271
+ let pkg_name = unit. pkg . name ( ) ;
272
+ let pkg_descr = unit. pkg . to_string ( ) ;
271
273
let build_script_outputs = Arc :: clone ( & cx. build_script_outputs ) ;
272
274
let id = unit. pkg . package_id ( ) ;
273
275
let output_file = script_run_dir. join ( "output" ) ;
@@ -276,7 +278,8 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
276
278
let host_target_root = cx. files ( ) . host_dest ( ) . to_path_buf ( ) ;
277
279
let all = (
278
280
id,
279
- pkg_name. clone ( ) ,
281
+ pkg_name,
282
+ pkg_descr. clone ( ) ,
280
283
Arc :: clone ( & build_script_outputs) ,
281
284
output_file. clone ( ) ,
282
285
script_out_dir. clone ( ) ,
@@ -291,6 +294,7 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
291
294
paths:: create_dir_all ( & script_out_dir) ?;
292
295
293
296
let extra_link_arg = cx. bcx . config . cli_unstable ( ) . extra_link_arg ;
297
+ let nightly_features_allowed = cx. bcx . config . nightly_features_allowed ;
294
298
295
299
// Prepare the unit of "dirty work" which will actually run the custom build
296
300
// command.
@@ -365,7 +369,7 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
365
369
} ,
366
370
true ,
367
371
)
368
- . chain_err ( || format ! ( "failed to run custom build command for `{}`" , pkg_name ) ) ;
372
+ . chain_err ( || format ! ( "failed to run custom build command for `{}`" , pkg_descr ) ) ;
369
373
370
374
if let Err ( error) = output {
371
375
insert_warnings_in_build_outputs (
@@ -394,10 +398,12 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
394
398
paths:: write ( & root_output_file, util:: path2bytes ( & script_out_dir) ?) ?;
395
399
let parsed_output = BuildOutput :: parse (
396
400
& output. stdout ,
397
- & pkg_name,
401
+ pkg_name,
402
+ & pkg_descr,
398
403
& script_out_dir,
399
404
& script_out_dir,
400
405
extra_link_arg,
406
+ nightly_features_allowed,
401
407
) ?;
402
408
403
409
if json_messages {
@@ -414,15 +420,17 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
414
420
// itself to run when we actually end up just discarding what we calculated
415
421
// above.
416
422
let fresh = Work :: new ( move |state| {
417
- let ( id, pkg_name, build_script_outputs, output_file, script_out_dir) = all;
423
+ let ( id, pkg_name, pkg_descr , build_script_outputs, output_file, script_out_dir) = all;
418
424
let output = match prev_output {
419
425
Some ( output) => output,
420
426
None => BuildOutput :: parse_file (
421
427
& output_file,
422
- & pkg_name,
428
+ pkg_name,
429
+ & pkg_descr,
423
430
& prev_script_out_dir,
424
431
& script_out_dir,
425
432
extra_link_arg,
433
+ nightly_features_allowed,
426
434
) ?,
427
435
} ;
428
436
@@ -469,29 +477,35 @@ fn insert_warnings_in_build_outputs(
469
477
impl BuildOutput {
470
478
pub fn parse_file (
471
479
path : & Path ,
472
- pkg_name : & str ,
480
+ pkg_name : InternedString ,
481
+ pkg_descr : & str ,
473
482
script_out_dir_when_generated : & Path ,
474
483
script_out_dir : & Path ,
475
484
extra_link_arg : bool ,
485
+ nightly_features_allowed : bool ,
476
486
) -> CargoResult < BuildOutput > {
477
487
let contents = paths:: read_bytes ( path) ?;
478
488
BuildOutput :: parse (
479
489
& contents,
480
490
pkg_name,
491
+ pkg_descr,
481
492
script_out_dir_when_generated,
482
493
script_out_dir,
483
494
extra_link_arg,
495
+ nightly_features_allowed,
484
496
)
485
497
}
486
498
487
499
// Parses the output of a script.
488
500
// The `pkg_name` is used for error messages.
489
501
pub fn parse (
490
502
input : & [ u8 ] ,
491
- pkg_name : & str ,
503
+ pkg_name : InternedString ,
504
+ pkg_descr : & str ,
492
505
script_out_dir_when_generated : & Path ,
493
506
script_out_dir : & Path ,
494
507
extra_link_arg : bool ,
508
+ nightly_features_allowed : bool ,
495
509
) -> CargoResult < BuildOutput > {
496
510
let mut library_paths = Vec :: new ( ) ;
497
511
let mut library_links = Vec :: new ( ) ;
@@ -502,7 +516,7 @@ impl BuildOutput {
502
516
let mut rerun_if_changed = Vec :: new ( ) ;
503
517
let mut rerun_if_env_changed = Vec :: new ( ) ;
504
518
let mut warnings = Vec :: new ( ) ;
505
- let whence = format ! ( "build script of `{}`" , pkg_name ) ;
519
+ let whence = format ! ( "build script of `{}`" , pkg_descr ) ;
506
520
507
521
for line in input. split ( |b| * b == b'\n' ) {
508
522
let line = match str:: from_utf8 ( line) {
@@ -562,7 +576,37 @@ impl BuildOutput {
562
576
}
563
577
}
564
578
"rustc-cfg" => cfgs. push ( value. to_string ( ) ) ,
565
- "rustc-env" => env. push ( BuildOutput :: parse_rustc_env ( & value, & whence) ?) ,
579
+ "rustc-env" => {
580
+ let ( key, val) = BuildOutput :: parse_rustc_env ( & value, & whence) ?;
581
+ // Build scripts aren't allowed to set RUSTC_BOOTSTRAP.
582
+ // See https://github.com/rust-lang/cargo/issues/7088.
583
+ if key == "RUSTC_BOOTSTRAP" {
584
+ // If RUSTC_BOOTSTRAP is already set, the user of Cargo knows about
585
+ // bootstrap and still wants to override the channel. Give them a way to do
586
+ // so, but still emit a warning that the current crate shouldn't be trying
587
+ // to set RUSTC_BOOTSTRAP.
588
+ // If this is a nightly build, setting RUSTC_BOOTSTRAP wouldn't affect the
589
+ // behavior, so still only give a warning.
590
+ if nightly_features_allowed {
591
+ warnings. push ( format ! ( "Cannot set `RUSTC_BOOTSTRAP={}` from {}.\n \
592
+ note: Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project.",
593
+ val, whence
594
+ ) ) ;
595
+ } else {
596
+ // Setting RUSTC_BOOTSTRAP would change the behavior of the crate.
597
+ // Abort with an error.
598
+ anyhow:: bail!( "Cannot set `RUSTC_BOOTSTRAP={}` from {}.\n \
599
+ note: Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project.\n \
600
+ help: If you're sure you want to do this in your project, set the environment variable `RUSTC_BOOTSTRAP={}` before running cargo instead.",
601
+ val,
602
+ whence,
603
+ pkg_name,
604
+ ) ;
605
+ }
606
+ } else {
607
+ env. push ( ( key, val) ) ;
608
+ }
609
+ }
566
610
"warning" => warnings. push ( value. to_string ( ) ) ,
567
611
"rerun-if-changed" => rerun_if_changed. push ( PathBuf :: from ( value) ) ,
568
612
"rerun-if-env-changed" => rerun_if_env_changed. push ( value. to_string ( ) ) ,
@@ -813,10 +857,12 @@ fn prev_build_output(cx: &mut Context<'_, '_>, unit: &Unit) -> (Option<BuildOutp
813
857
(
814
858
BuildOutput :: parse_file (
815
859
& output_file,
860
+ unit. pkg . name ( ) ,
816
861
& unit. pkg . to_string ( ) ,
817
862
& prev_script_out_dir,
818
863
& script_out_dir,
819
864
extra_link_arg,
865
+ cx. bcx . config . nightly_features_allowed ,
820
866
)
821
867
. ok ( ) ,
822
868
prev_script_out_dir,
0 commit comments