Skip to content

Commit a51fb2b

Browse files
committed
Auto merge of #99130 - jyn514:std-cache-invalidation, r=Mark-Simulacrum
Fix `x build library/std compiler/rustc` Previously, this was broken because of improper caching: 1. `StepDescription::maybe_run` builds `Compile::Std`, which only built `std` and not `proc_macro` 1. `Std` calls `builder.ensure(StdLink)` 1. `Rustc` calls `ensure(Std)`, which builds all crates, including `proc_macro` 1. `Rustc` calls `ensure(StdLink)`. `ensure` would see that it had already been run and do nothing. <-- bug is here 1. Cargo gives an error that `proc_macro` doesn't exist. This fixes the caching by adding `crates` to `StdLink`, so it will get rerun if the crates that are built change. Fixes #99129.
2 parents adaddb5 + 7d4bd54 commit a51fb2b

File tree

1 file changed

+38
-22
lines changed

1 file changed

+38
-22
lines changed

src/bootstrap/compile.rs

+38-22
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl Step for Std {
104104
|| builder.config.keep_stage_std.contains(&compiler.stage)
105105
{
106106
builder.info("Warning: Using a potentially old libstd. This may not behave well.");
107-
builder.ensure(StdLink { compiler, target_compiler: compiler, target });
107+
builder.ensure(StdLink::from_std(self, compiler));
108108
return;
109109
}
110110

@@ -122,11 +122,7 @@ impl Step for Std {
122122
copy_third_party_objects(builder, &compiler, target);
123123
copy_self_contained_objects(builder, &compiler, target);
124124

125-
builder.ensure(StdLink {
126-
compiler: compiler_to_use,
127-
target_compiler: compiler,
128-
target,
129-
});
125+
builder.ensure(StdLink::from_std(self, compiler_to_use));
130126
return;
131127
}
132128

@@ -149,11 +145,10 @@ impl Step for Std {
149145
false,
150146
);
151147

152-
builder.ensure(StdLink {
153-
compiler: builder.compiler(compiler.stage, builder.config.build),
154-
target_compiler: compiler,
155-
target,
156-
});
148+
builder.ensure(StdLink::from_std(
149+
self,
150+
builder.compiler(compiler.stage, builder.config.build),
151+
));
157152
}
158153
}
159154

@@ -394,6 +389,19 @@ struct StdLink {
394389
pub compiler: Compiler,
395390
pub target_compiler: Compiler,
396391
pub target: TargetSelection,
392+
/// Not actually used; only present to make sure the cache invalidation is correct.
393+
crates: Interned<Vec<String>>,
394+
}
395+
396+
impl StdLink {
397+
fn from_std(std: Std, host_compiler: Compiler) -> Self {
398+
Self {
399+
compiler: host_compiler,
400+
target_compiler: std.compiler,
401+
target: std.target,
402+
crates: std.crates,
403+
}
404+
}
397405
}
398406

399407
impl Step for StdLink {
@@ -614,7 +622,7 @@ impl Step for Rustc {
614622
if builder.config.keep_stage.contains(&compiler.stage) {
615623
builder.info("Warning: Using a potentially old librustc. This may not behave well.");
616624
builder.info("Warning: Use `--keep-stage-std` if you want to rebuild the compiler when it changes");
617-
builder.ensure(RustcLink { compiler, target_compiler: compiler, target });
625+
builder.ensure(RustcLink::from_rustc(self, compiler));
618626
return;
619627
}
620628

@@ -623,11 +631,7 @@ impl Step for Rustc {
623631
builder.ensure(Rustc::new(compiler_to_use, target));
624632
builder
625633
.info(&format!("Uplifting stage1 rustc ({} -> {})", builder.config.build, target));
626-
builder.ensure(RustcLink {
627-
compiler: compiler_to_use,
628-
target_compiler: compiler,
629-
target,
630-
});
634+
builder.ensure(RustcLink::from_rustc(self, compiler_to_use));
631635
return;
632636
}
633637

@@ -688,11 +692,10 @@ impl Step for Rustc {
688692
false,
689693
);
690694

691-
builder.ensure(RustcLink {
692-
compiler: builder.compiler(compiler.stage, builder.config.build),
693-
target_compiler: compiler,
694-
target,
695-
});
695+
builder.ensure(RustcLink::from_rustc(
696+
self,
697+
builder.compiler(compiler.stage, builder.config.build),
698+
));
696699
}
697700
}
698701

@@ -807,6 +810,19 @@ struct RustcLink {
807810
pub compiler: Compiler,
808811
pub target_compiler: Compiler,
809812
pub target: TargetSelection,
813+
/// Not actually used; only present to make sure the cache invalidation is correct.
814+
crates: Interned<Vec<String>>,
815+
}
816+
817+
impl RustcLink {
818+
fn from_rustc(rustc: Rustc, host_compiler: Compiler) -> Self {
819+
Self {
820+
compiler: host_compiler,
821+
target_compiler: rustc.compiler,
822+
target: rustc.target,
823+
crates: rustc.crates,
824+
}
825+
}
810826
}
811827

812828
impl Step for RustcLink {

0 commit comments

Comments
 (0)