Fix staging in x install

This commit is contained in:
Jakub Beránek 2025-08-15 20:43:41 +02:00
parent 2074e1344d
commit 3ec2abc2f4
No known key found for this signature in database
GPG Key ID: 909CD0D26483516B
3 changed files with 81 additions and 85 deletions

View File

@ -762,6 +762,29 @@ pub struct Std {
pub target: TargetSelection,
}
impl Std {
pub fn new(builder: &Builder<'_>, target: TargetSelection) -> Self {
// This is a build time optimization for running just `x dist rust-std` (without
// `x dist rustc`).
// If we know that we will be uplifting a stage2+ library from stage 1 anyway,
// there is no point in building a stage2 rustc, which will then not do anything (because
// the stdlib will be uplifted).
let top_stage = builder.top_stage;
let stage = if top_stage > 1
&& compile::Std::should_be_uplifted_from_stage_1(builder, top_stage, target)
{
builder.info(&format!(
"Note: stage {top_stage} library for `{}` would be uplifted from stage 1, so stage was downgraded from {top_stage} to 1 to avoid needless compiler build(s)",
target
));
1
} else {
top_stage
};
Std { build_compiler: builder.compiler(stage, builder.config.host_target), target }
}
}
impl Step for Std {
type Output = Option<GeneratedTarball>;
const DEFAULT: bool = true;
@ -771,27 +794,7 @@ impl Step for Std {
}
fn make_run(run: RunConfig<'_>) {
// This is a build time optimization for running just `x dist rust-std` (without
// `x dist rustc`).
// If we know that we will be uplifting a stage2+ library from stage 1 anyway,
// there is no point in building a stage2 rustc, which will then not do anything (because
// the stdlib will be uplifted).
let top_stage = run.builder.top_stage;
let stage = if top_stage > 1
&& compile::Std::should_be_uplifted_from_stage_1(run.builder, top_stage, run.target)
{
run.builder.info(&format!(
"Note: stage {top_stage} library for `{}` would be uplifted from stage 1, so stage was downgraded from {top_stage} to 1 to avoid needless compiler build(s)",
run.target
));
1
} else {
top_stage
};
run.builder.ensure(Std {
build_compiler: run.builder.compiler(stage, run.builder.config.host_target),
target: run.target,
});
run.builder.ensure(Std::new(run.builder, run.target));
}
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {

View File

@ -65,17 +65,14 @@ fn is_dir_writable_for_user(dir: &Path) -> bool {
fn install_sh(
builder: &Builder<'_>,
package: &str,
stage: u32,
host: Option<TargetSelection>,
build_compiler: impl Into<Option<Compiler>>,
target: Option<TargetSelection>,
tarball: &GeneratedTarball,
) {
let _guard = builder.msg(
Kind::Install,
package,
None,
(host.unwrap_or(builder.host_target), stage),
host,
);
let _guard = match build_compiler.into() {
Some(build_compiler) => builder.msg(Kind::Install, package, None, build_compiler, target),
None => builder.msg_unstaged(Kind::Install, package, target.unwrap_or(builder.host_target)),
};
let prefix = default_path(&builder.config.prefix, "/usr/local");
let sysconfdir = prefix.join(default_path(&builder.config.sysconfdir, "/etc"));
@ -167,10 +164,10 @@ macro_rules! install {
IS_HOST: $IS_HOST:expr,
$run_item:block $(, $c:ident)*;)+) => {
$(
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct $name {
pub compiler: Compiler,
pub target: TargetSelection,
build_compiler: Compiler,
target: TargetSelection,
}
impl $name {
@ -194,7 +191,7 @@ macro_rules! install {
fn make_run(run: RunConfig<'_>) {
run.builder.ensure($name {
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.host_target),
build_compiler: run.builder.compiler(run.builder.top_stage - 1, run.builder.config.host_target),
target: run.target,
});
}
@ -209,96 +206,95 @@ macro_rules! install {
install!((self, builder, _config),
Docs, path = "src/doc", _config.docs, IS_HOST: false, {
let tarball = builder.ensure(dist::Docs { host: self.target }).expect("missing docs");
install_sh(builder, "docs", self.compiler.stage, Some(self.target), &tarball);
install_sh(builder, "docs", self.build_compiler, Some(self.target), &tarball);
};
Std, path = "library/std", true, IS_HOST: false, {
// `expect` should be safe, only None when host != build, but this
// only runs when host == build
let tarball = builder.ensure(dist::Std {
build_compiler: self.compiler,
target: self.target
}).expect("missing std");
install_sh(builder, "std", self.compiler.stage, Some(self.target), &tarball);
let std = dist::Std::new(builder, self.target);
let build_compiler = std.build_compiler;
let tarball = builder.ensure(std).expect("missing std");
install_sh(builder, "std", build_compiler, Some(self.target), &tarball);
};
Cargo, alias = "cargo", Self::should_build(_config), IS_HOST: true, {
let tarball = builder
.ensure(dist::Cargo { build_compiler: self.compiler, target: self.target })
.ensure(dist::Cargo { build_compiler: self.build_compiler, target: self.target })
.expect("missing cargo");
install_sh(builder, "cargo", self.compiler.stage, Some(self.target), &tarball);
install_sh(builder, "cargo", self.build_compiler, Some(self.target), &tarball);
};
RustAnalyzer, alias = "rust-analyzer", Self::should_build(_config), IS_HOST: true, {
if let Some(tarball) =
builder.ensure(dist::RustAnalyzer { compilers: RustcPrivateCompilers::from_build_compiler(builder, self.compiler, self.target), target: self.target })
builder.ensure(dist::RustAnalyzer { compilers: RustcPrivateCompilers::from_build_compiler(builder, self.build_compiler, self.target), target: self.target })
{
install_sh(builder, "rust-analyzer", self.compiler.stage, Some(self.target), &tarball);
install_sh(builder, "rust-analyzer", self.build_compiler, Some(self.target), &tarball);
} else {
builder.info(
&format!("skipping Install rust-analyzer stage{} ({})", self.compiler.stage, self.target),
&format!("skipping Install rust-analyzer stage{} ({})", self.build_compiler.stage + 1, self.target),
);
}
};
Clippy, alias = "clippy", Self::should_build(_config), IS_HOST: true, {
let tarball = builder
.ensure(dist::Clippy { compilers: RustcPrivateCompilers::from_build_compiler(builder, self.compiler, self.target), target: self.target })
.ensure(dist::Clippy { compilers: RustcPrivateCompilers::from_build_compiler(builder, self.build_compiler, self.target), target: self.target })
.expect("missing clippy");
install_sh(builder, "clippy", self.compiler.stage, Some(self.target), &tarball);
install_sh(builder, "clippy", self.build_compiler, Some(self.target), &tarball);
};
Miri, alias = "miri", Self::should_build(_config), IS_HOST: true, {
if let Some(tarball) = builder.ensure(dist::Miri { compilers: RustcPrivateCompilers::from_build_compiler(builder, self.compiler, self.target) , target: self.target }) {
install_sh(builder, "miri", self.compiler.stage, Some(self.target), &tarball);
if let Some(tarball) = builder.ensure(dist::Miri { compilers: RustcPrivateCompilers::from_build_compiler(builder, self.build_compiler, self.target) , target: self.target }) {
install_sh(builder, "miri", self.build_compiler, Some(self.target), &tarball);
} else {
// Miri is only available on nightly
builder.info(
&format!("skipping Install miri stage{} ({})", self.compiler.stage, self.target),
&format!("skipping Install miri stage{} ({})", self.build_compiler.stage + 1, self.target),
);
}
};
LlvmTools, alias = "llvm-tools", _config.llvm_tools_enabled && _config.llvm_enabled(_config.host_target), IS_HOST: true, {
if let Some(tarball) = builder.ensure(dist::LlvmTools { target: self.target }) {
install_sh(builder, "llvm-tools", self.compiler.stage, Some(self.target), &tarball);
install_sh(builder, "llvm-tools", None, Some(self.target), &tarball);
} else {
builder.info(
&format!("skipping llvm-tools stage{} ({}): external LLVM", self.compiler.stage, self.target),
&format!("skipping llvm-tools ({}): external LLVM", self.target),
);
}
};
Rustfmt, alias = "rustfmt", Self::should_build(_config), IS_HOST: true, {
if let Some(tarball) = builder.ensure(dist::Rustfmt {
compilers: RustcPrivateCompilers::from_build_compiler(builder, self.compiler, self.target),
compilers: RustcPrivateCompilers::from_build_compiler(builder, self.build_compiler, self.target),
target: self.target
}) {
install_sh(builder, "rustfmt", self.compiler.stage, Some(self.target), &tarball);
install_sh(builder, "rustfmt", self.build_compiler, Some(self.target), &tarball);
} else {
builder.info(
&format!("skipping Install Rustfmt stage{} ({})", self.compiler.stage, self.target),
&format!("skipping Install Rustfmt stage{} ({})", self.build_compiler.stage + 1, self.target),
);
}
};
Rustc, path = "compiler/rustc", true, IS_HOST: true, {
let tarball = builder.ensure(dist::Rustc {
target_compiler: builder.compiler(builder.top_stage, self.target),
target_compiler: builder.compiler(self.build_compiler.stage + 1, self.target),
});
install_sh(builder, "rustc", self.compiler.stage, Some(self.target), &tarball);
install_sh(builder, "rustc", self.build_compiler, Some(self.target), &tarball);
};
RustcCodegenCranelift, alias = "rustc-codegen-cranelift", Self::should_build(_config), IS_HOST: true, {
if let Some(tarball) = builder.ensure(dist::CraneliftCodegenBackend {
compilers: RustcPrivateCompilers::new(builder, builder.top_stage, self.target),
compilers: RustcPrivateCompilers::from_build_compiler(builder, self.build_compiler, self.target),
target: self.target
}) {
install_sh(builder, "rustc-codegen-cranelift", self.compiler.stage, Some(self.target), &tarball);
install_sh(builder, "rustc-codegen-cranelift", self.build_compiler, Some(self.target), &tarball);
} else {
builder.info(
&format!("skipping Install CodegenBackend(\"cranelift\") stage{} ({})",
self.compiler.stage, self.target),
self.build_compiler.stage + 1, self.target),
);
}
};
LlvmBitcodeLinker, alias = "llvm-bitcode-linker", Self::should_build(_config), IS_HOST: true, {
if let Some(tarball) = builder.ensure(dist::LlvmBitcodeLinker { build_compiler: self.compiler, target: self.target }) {
install_sh(builder, "llvm-bitcode-linker", self.compiler.stage, Some(self.target), &tarball);
if let Some(tarball) = builder.ensure(dist::LlvmBitcodeLinker { build_compiler: self.build_compiler, target: self.target }) {
install_sh(builder, "llvm-bitcode-linker", self.build_compiler, Some(self.target), &tarball);
} else {
builder.info(
&format!("skipping llvm-bitcode-linker stage{} ({})", self.compiler.stage, self.target),
&format!("skipping llvm-bitcode-linker stage{} ({})", self.build_compiler.stage + 1, self.target),
);
}
};
@ -306,7 +302,7 @@ install!((self, builder, _config),
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct Src {
pub stage: u32,
stage: u32,
}
impl Step for Src {
@ -326,6 +322,6 @@ impl Step for Src {
fn run(self, builder: &Builder<'_>) {
let tarball = builder.ensure(dist::Src);
install_sh(builder, "src", self.stage, None, &tarball);
install_sh(builder, "src", None, None, &tarball);
}
}

View File

@ -2310,18 +2310,18 @@ mod snapshot {
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 0 <host> -> WasmComponentLd 1 <host>
[build] rustc 1 <host> -> std 1 <host>
[build] rustc 1 <host> -> rustc 2 <host>
[build] rustc 1 <host> -> WasmComponentLd 2 <host>
[build] rustc 0 <host> -> UnstableBookGen 1 <host>
[build] rustc 0 <host> -> Rustbook 1 <host>
[doc] unstable-book (book) <host>
[build] rustc 1 <host> -> std 1 <host>
[doc] book (book) <host>
[doc] book/first-edition (book) <host>
[doc] book/second-edition (book) <host>
[doc] book/2018-edition (book) <host>
[build] rustdoc 1 <host>
[doc] rustc 1 <host> -> standalone 2 <host>
[build] rustc 1 <host> -> rustc 2 <host>
[build] rustc 1 <host> -> WasmComponentLd 2 <host>
[build] rustdoc 2 <host>
[doc] rustc 2 <host> -> std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
[build] rustc 1 <host> -> error-index 2 <host>
@ -2340,26 +2340,23 @@ mod snapshot {
[doc] rustc 1 <host> -> releases 2 <host>
[build] rustc 0 <host> -> RustInstaller 1 <host>
[dist] docs <host>
[build] rustc 2 <host> -> std 2 <host>
[dist] rustc 2 <host> -> std 2 <host>
[dist] rustc 1 <host> -> std 1 <host>
[build] rustc 1 <host> -> rust-analyzer-proc-macro-srv 2 <host>
[build] rustc 0 <host> -> GenerateCopyright 1 <host>
[dist] rustc <host>
[build] rustc 2 <host> -> cargo 3 <host>
[dist] rustc 2 <host> -> cargo 3 <host>
[build] rustc 2 <host> -> rustc 3 <host>
[build] rustc 2 <host> -> WasmComponentLd 3 <host>
[build] rustc 2 <host> -> rust-analyzer 3 <host>
[dist] rustc 2 <host> -> rust-analyzer 3 <host>
[build] rustc 2 <host> -> rustfmt 3 <host>
[build] rustc 2 <host> -> cargo-fmt 3 <host>
[dist] rustc 2 <host> -> rustfmt 3 <host>
[build] rustc 2 <host> -> clippy-driver 3 <host>
[build] rustc 2 <host> -> cargo-clippy 3 <host>
[dist] rustc 2 <host> -> clippy 3 <host>
[build] rustc 2 <host> -> miri 3 <host>
[build] rustc 2 <host> -> cargo-miri 3 <host>
[dist] rustc 2 <host> -> miri 3 <host>
[build] rustc 1 <host> -> cargo 2 <host>
[dist] rustc 1 <host> -> cargo 2 <host>
[build] rustc 1 <host> -> rust-analyzer 2 <host>
[dist] rustc 1 <host> -> rust-analyzer 2 <host>
[build] rustc 1 <host> -> rustfmt 2 <host>
[build] rustc 1 <host> -> cargo-fmt 2 <host>
[dist] rustc 1 <host> -> rustfmt 2 <host>
[build] rustc 1 <host> -> clippy-driver 2 <host>
[build] rustc 1 <host> -> cargo-clippy 2 <host>
[dist] rustc 1 <host> -> clippy 2 <host>
[build] rustc 1 <host> -> miri 2 <host>
[build] rustc 1 <host> -> cargo-miri 2 <host>
[dist] rustc 1 <host> -> miri 2 <host>
[dist] src <>
");
}