Skip to content

Commit 0a3cf02

Browse files
Rollup merge of #77120 - ecstatic-morse:keep-stage-std, r=Mark-Simulacrum
Add `--keep-stage-std` to `x.py` for keeping only standard library artifacts Unlike `--keep-stage 0`, `--keep-stage-std 0` will allow the stage 0 compiler artifacts (i.e., stage1/bin/rustc) to be rebuilt if it has changed. This allows contributors to iterate on later stages of the compiler in tandem with the standard library without needing to to rebuild the entire compiler. I often run into this when working on const-checking, since I may need to add a feature gate or make a small tweak to the standard library.
2 parents 8621ef1 + 16769eb commit 0a3cf02

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

src/bootstrap/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1515
- Make the default stage for x.py configurable [#76625](https://github.com/rust-lang/rust/pull/76625)
1616
- Add a dedicated debug-logging option [#76588](https://github.com/rust-lang/rust/pull/76588)
1717
- Add sample defaults for x.py [#76628](https://github.com/rust-lang/rust/pull/76628)
18+
- Add `--keep-stage-std`, which behaves like `keep-stage` but allows the stage
19+
0 compiler artifacts (i.e., stage1/bin/rustc) to be rebuilt if changed
20+
[#77120](https://github.com/rust-lang/rust/pull/77120).
21+
1822

1923
## [Version 0] - 2020-09-11
2024

src/bootstrap/compile.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ impl Step for Std {
5959
let target = self.target;
6060
let compiler = self.compiler;
6161

62-
if builder.config.keep_stage.contains(&compiler.stage) {
62+
if builder.config.keep_stage.contains(&compiler.stage)
63+
|| builder.config.keep_stage_std.contains(&compiler.stage)
64+
{
6365
builder.info("Warning: Using a potentially old libstd. This may not behave well.");
6466
builder.ensure(StdLink { compiler, target_compiler: compiler, target });
6567
return;
@@ -472,6 +474,7 @@ impl Step for Rustc {
472474

473475
if builder.config.keep_stage.contains(&compiler.stage) {
474476
builder.info("Warning: Using a potentially old librustc. This may not behave well.");
477+
builder.info("Warning: Use `--keep-stage-std` if you want to rebuild the compiler when it changes");
475478
builder.ensure(RustcLink { compiler, target_compiler: compiler, target });
476479
return;
477480
}

src/bootstrap/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ pub struct Config {
7171
pub on_fail: Option<String>,
7272
pub stage: u32,
7373
pub keep_stage: Vec<u32>,
74+
pub keep_stage_std: Vec<u32>,
7475
pub src: PathBuf,
7576
pub jobs: Option<u32>,
7677
pub cmd: Subcommand,
@@ -539,6 +540,7 @@ impl Config {
539540
config.incremental = flags.incremental;
540541
config.dry_run = flags.dry_run;
541542
config.keep_stage = flags.keep_stage;
543+
config.keep_stage_std = flags.keep_stage_std;
542544
config.bindir = "bin".into(); // default
543545
if let Some(value) = flags.deny_warnings {
544546
config.deny_warnings = value;

src/bootstrap/flags.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub struct Flags {
1919
pub on_fail: Option<String>,
2020
pub stage: Option<u32>,
2121
pub keep_stage: Vec<u32>,
22+
pub keep_stage_std: Vec<u32>,
2223

2324
pub host: Option<Vec<TargetSelection>>,
2425
pub target: Option<Vec<TargetSelection>>,
@@ -144,6 +145,13 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
144145
(pass multiple times to keep e.g., both stages 0 and 1)",
145146
"N",
146147
);
148+
opts.optmulti(
149+
"",
150+
"keep-stage-std",
151+
"stage(s) of the standard library to keep without recompiling \
152+
(pass multiple times to keep e.g., both stages 0 and 1)",
153+
"N",
154+
);
147155
opts.optopt("", "src", "path to the root of the rust checkout", "DIR");
148156
let j_msg = format!(
149157
"number of jobs to run in parallel; \
@@ -510,7 +518,9 @@ Arguments:
510518
println!("--stage not supported for x.py check, always treated as stage 0");
511519
process::exit(1);
512520
}
513-
if matches.opt_str("keep-stage").is_some() {
521+
if matches.opt_str("keep-stage").is_some()
522+
|| matches.opt_str("keep-stage-std").is_some()
523+
{
514524
println!("--keep-stage not supported for x.py check, only one stage available");
515525
process::exit(1);
516526
}
@@ -528,6 +538,11 @@ Arguments:
528538
.into_iter()
529539
.map(|j| j.parse().expect("`keep-stage` should be a number"))
530540
.collect(),
541+
keep_stage_std: matches
542+
.opt_strs("keep-stage-std")
543+
.into_iter()
544+
.map(|j| j.parse().expect("`keep-stage-std` should be a number"))
545+
.collect(),
531546
host: if matches.opt_present("host") {
532547
Some(
533548
split(&matches.opt_strs("host"))

0 commit comments

Comments
 (0)