Skip to content

ensure compiler existance of tools on the dist step #140006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/bootstrap/src/core/build_steps/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,13 +421,13 @@ impl Step for Rustc {
builder.install(&rustdoc, &image.join("bin"), FileType::Executable);
}

let ra_proc_macro_srv_compiler =
builder.compiler_for(compiler.stage, builder.config.build, compiler.host);
builder.ensure(compile::Rustc::new(ra_proc_macro_srv_compiler, compiler.host));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this now build the compiler for the proc macro server even if tool::RustAnalyzerProcMacroSrv should not actually be built? 🤔 It's not always enabled.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compiler is passed before the condition here so I'm not sure how to guard against that without applying ugly hacks. Also, in practice, I don't think we ever hit the case of "trying to build RustAnalyzerProcMacroSrv while the compiler isn't compiled/ready for use".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, fair enough.


if let Some(ra_proc_macro_srv) = builder.ensure_if_default(
tool::RustAnalyzerProcMacroSrv {
compiler: builder.compiler_for(
compiler.stage,
builder.config.build,
compiler.host,
),
compiler: ra_proc_macro_srv_compiler,
target: compiler.host,
},
builder.kind,
Expand Down Expand Up @@ -1177,6 +1177,8 @@ impl Step for Cargo {
let compiler = self.compiler;
let target = self.target;

builder.ensure(compile::Rustc::new(compiler, target));

let cargo = builder.ensure(tool::Cargo { compiler, target });
let src = builder.src.join("src/tools/cargo");
let etc = src.join("src/etc");
Expand Down Expand Up @@ -1231,6 +1233,8 @@ impl Step for RustAnalyzer {
let compiler = self.compiler;
let target = self.target;

builder.ensure(compile::Rustc::new(compiler, target));

let rust_analyzer = builder.ensure(tool::RustAnalyzer { compiler, target });

let mut tarball = Tarball::new(builder, "rust-analyzer", &target.triple);
Expand Down Expand Up @@ -1273,6 +1277,8 @@ impl Step for Clippy {
let compiler = self.compiler;
let target = self.target;

builder.ensure(compile::Rustc::new(compiler, target));

// Prepare the image directory
// We expect clippy to build, because we've exited this step above if tool
// state for clippy isn't testing.
Expand Down Expand Up @@ -1323,9 +1329,12 @@ impl Step for Miri {
if !builder.build.unstable_features() {
return None;
}

let compiler = self.compiler;
let target = self.target;

builder.ensure(compile::Rustc::new(compiler, target));

let miri = builder.ensure(tool::Miri { compiler, target });
let cargomiri = builder.ensure(tool::CargoMiri { compiler, target });

Expand Down Expand Up @@ -1462,6 +1471,8 @@ impl Step for Rustfmt {
let compiler = self.compiler;
let target = self.target;

builder.ensure(compile::Rustc::new(compiler, target));

let rustfmt = builder.ensure(tool::Rustfmt { compiler, target });
let cargofmt = builder.ensure(tool::Cargofmt { compiler, target });
let mut tarball = Tarball::new(builder, "rustfmt", &target.triple);
Expand Down Expand Up @@ -2327,6 +2338,8 @@ impl Step for LlvmBitcodeLinker {
let compiler = self.compiler;
let target = self.target;

builder.ensure(compile::Rustc::new(compiler, target));

let llbc_linker =
builder.ensure(tool::LlvmBitcodeLinker { compiler, target, extra_features: vec![] });

Expand Down
32 changes: 32 additions & 0 deletions src/bootstrap/src/core/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ mod dist {
use pretty_assertions::assert_eq;

use super::{Config, TEST_TRIPLE_1, TEST_TRIPLE_2, TEST_TRIPLE_3, first, run_build};
use crate::Flags;
use crate::core::builder::*;

fn configure(host: &[&str], target: &[&str]) -> Config {
Expand Down Expand Up @@ -646,6 +647,37 @@ mod dist {
);
}

/// This also serves as an important regression test for <https://github.com/rust-lang/rust/issues/138123>
/// and <https://github.com/rust-lang/rust/issues/138004>.
#[test]
fn dist_all_cross() {
let cmd_args =
&["dist", "--stage", "2", "--dry-run", "--config=/does/not/exist"].map(str::to_owned);
let config_str = r#"
[rust]
channel = "nightly"

[build]
extended = true

build = "i686-unknown-haiku"
host = ["i686-unknown-netbsd"]
target = ["i686-unknown-netbsd"]
"#;
let config = Config::parse_inner(Flags::parse(cmd_args), |&_| toml::from_str(config_str));
let mut cache = run_build(&[], config);

// Stage 2 `compile::Rustc` should **NEVER** be cached here.
assert_eq!(
first(cache.all::<compile::Rustc>()),
&[
rustc!(TEST_TRIPLE_1 => TEST_TRIPLE_1, stage = 0),
rustc!(TEST_TRIPLE_1 => TEST_TRIPLE_1, stage = 1),
rustc!(TEST_TRIPLE_1 => TEST_TRIPLE_3, stage = 1),
]
);
}

#[test]
fn build_all() {
let build = Build::new(configure(
Expand Down
Loading