Skip to content

Commit bcbd2cc

Browse files
Add keep-stage-std to x.py
This keeps only the `std` artifacts compiled by the given stage, not the compiler. This is useful when working on the latter stages of the compiler in tandem with the standard library, since you don't have to rebuild the *entire* compiler when the standard library changes.
1 parent a6008fa commit bcbd2cc

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/bootstrap/compile.rs

+8-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,11 @@ 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");
478+
builder.info(
479+
"Warning: Please file a GitHub issue if `--keep-stage-std` doesn't work for you.",
480+
);
481+
builder.info("Warning: It may replace `--keep-stage` in the future");
475482
builder.ensure(RustcLink { compiler, target_compiler: compiler, target });
476483
return;
477484
}

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)