Skip to content
Merged
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
2 changes: 2 additions & 0 deletions src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ impl Step for PrepareRustcRmetaSysroot {

// Copy the generated rmeta artifacts to a separate directory
let dir = builder
.config
.out
.join(build_compiler.host)
.join(format!("stage{}-rustc-rmeta-artifacts", build_compiler.stage + 1));
Expand Down Expand Up @@ -289,6 +290,7 @@ impl Step for PrepareStdRmetaSysroot {

// Copy the generated rmeta artifacts to a separate directory
let dir = builder
.config
.out
.join(self.build_compiler.host)
.join(format!("stage{}-std-rmeta-artifacts", self.build_compiler.stage));
Expand Down
1 change: 0 additions & 1 deletion src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,6 @@ impl Step for StdLink {

let is_downloaded_beta_stage0 = builder
.sess
.config
.initial_rustc
.starts_with(builder.out.join(compiler.host).join("stage0/bin"));

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,7 @@ impl CommandLineStep for RustdocGUI {
cmd.arg("--out-dir").arg(out_dir);
}

if let Some(initial_cargo) = builder.config.initial_cargo.to_str() {
if let Some(initial_cargo) = builder.sess.initial_cargo.to_str() {
cmd.arg("--initial-cargo").arg(initial_cargo);
}

Expand Down
9 changes: 4 additions & 5 deletions src/bootstrap/src/core/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1462,11 +1462,10 @@ Alternatively, you can set `build.local-rebuild=true` and use a stage0 compiler
/// The used Clippy is (or in the case of stage 0, already was) built using `build_compiler`.
pub fn cargo_clippy_cmd(&self, build_compiler: Compiler) -> BootstrapCommand {
if build_compiler.stage == 0 {
let cargo_clippy = self
.config
.initial_cargo_clippy
.clone()
.unwrap_or_else(|| self.sess.config.download_clippy());
let cargo_clippy =
self.config.external_cargo_clippy.clone().unwrap_or_else(|| {
self.sess.config.download_clippy(&self.sess.initial_sysroot)
});

let mut cmd = command(cargo_clippy);
cmd.env("CARGO", &self.initial_cargo);
Expand Down
94 changes: 34 additions & 60 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use crate::core::config::{
GccCiMode, LlvmCiMode, LlvmLibunwind, Merge, ReplaceOpt, RustcLto, SplitDebuginfo,
StringOrBool, TargetSelection, threads_from_config,
};
use crate::core::download::{DownloadContext, download_beta_toolchain, is_download_ci_available};
use crate::core::download::{DownloadContext, is_download_ci_available};
use crate::utils::channel::{self, GitInfo};
use crate::utils::exec::{ExecutionContext, command};
use crate::utils::helpers::{self, exe, fail, get_host_target, t};
Expand Down Expand Up @@ -243,9 +243,13 @@ pub(crate) struct Config {

pub reproducible_artifacts: Vec<String>,

/// Build triple for the pre-compiled snapshot compiler.
pub host_target: TargetSelection,
/// Which triples to produce a compiler toolchain for.
pub hosts: Vec<TargetSelection>,
/// Which triples to build libraries (core/alloc/std/test/proc_macro) for.
pub targets: Vec<TargetSelection>,

pub local_rebuild: bool,
pub allocator: Option<Allocator>,
pub control_flow_guard: bool,
Expand Down Expand Up @@ -301,12 +305,13 @@ pub(crate) struct Config {
pub in_tree_llvm_info: channel::GitInfo,
pub in_tree_gcc_info: channel::GitInfo,

// These are either the stage0 downloaded binaries or the locally installed ones.
pub initial_cargo: PathBuf,
pub initial_rustc: PathBuf,
pub initial_rustdoc: PathBuf,
pub initial_cargo_clippy: Option<PathBuf>,
pub initial_sysroot: PathBuf,
/// rustc/cargo/rustdoc/clippy paths specified in the config file
/// Access the `initial_` fields from `Session` to use either the externally configured
/// or downloaded (stage0) binaries.
pub external_cargo: Option<PathBuf>,
pub external_rustc: Option<PathBuf>,
pub external_rustdoc: Option<PathBuf>,
pub external_cargo_clippy: Option<PathBuf>,

/// Externally configured `rustfmt` binary for formatting in-tree source code.
/// If you want to use rustfmt for formatting, use the `InternalRustfmt` step, instead of
Expand Down Expand Up @@ -499,7 +504,6 @@ impl Config {
gdb: build_gdb,
lldb: build_lldb,
nodejs: build_nodejs,

yarn: build_yarn,
npm: build_npm,
python: build_python,
Expand Down Expand Up @@ -771,7 +775,7 @@ impl Config {

// NOTE: Bootstrap spawns various commands with different working directories.
// To avoid writing to random places on the file system, `config.out` needs to be an absolute path.
let mut out = if !out.is_absolute() {
let out = if !out.is_absolute() {
// `canonicalize` requires the path to already exist. Use our vendored copy of `absolute` instead.
absolute(&out).expect("can't make empty path absolute")
} else {
Expand Down Expand Up @@ -810,10 +814,10 @@ impl Config {

if !flags_skip_stage0_validation {
if let Some(rustc) = &build_rustc {
check_stage0_version(rustc, "rustc", &src, &exec_ctx);
check_external_binary_version(rustc, "rustc", &src, &exec_ctx);
}
if let Some(cargo) = &build_cargo {
check_stage0_version(cargo, "cargo", &src, &exec_ctx);
check_external_binary_version(cargo, "cargo", &src, &exec_ctx);
}
}

Expand Down Expand Up @@ -841,34 +845,6 @@ impl Config {
ci_env,
};

let initial_rustc = build_rustc.unwrap_or_else(|| {
download_beta_toolchain(&dwn_ctx, &out);
default_stage0_rustc_path(&out)
});

let initial_rustdoc = build_rustdoc
.unwrap_or_else(|| initial_rustc.with_file_name(exe("rustdoc", host_target)));

let initial_sysroot = t!(PathBuf::from_str(
command(&initial_rustc)
.args(["--print", "sysroot"])
.run_in_dry_run()
.run_capture_stdout(&exec_ctx)
.stdout()
.trim()
));

let initial_cargo = build_cargo.unwrap_or_else(|| {
download_beta_toolchain(&dwn_ctx, &out);
initial_sysroot.join("bin").join(exe("cargo", host_target))
});

// NOTE: it's important this comes *after* we set `initial_rustc` just above.
if exec_ctx.dry_run() {
out = out.join("tmp-dry-run");
fs::create_dir_all(&out).expect("Failed to create dry-run directory");
}

let file_content = t!(fs::read_to_string(src.join("src/ci/channel")));
let ci_channel = file_content.trim_end();

Expand Down Expand Up @@ -1464,6 +1440,10 @@ NOTE: Please add `--stage 2` to your command line, or if you're sure you want to
explicit_stage_from_cli: flags_stage.is_some(),
explicit_stage_from_config,
extended: build_extended.unwrap_or(false),
external_cargo: build_cargo,
external_cargo_clippy: build_cargo_clippy,
external_rustc: build_rustc,
external_rustdoc: build_rustdoc,
external_rustfmt: build_rustfmt,
free_args: flags_free_args,
full_bootstrap: build_full_bootstrap.unwrap_or(false),
Expand All @@ -1475,11 +1455,6 @@ NOTE: Please add `--stage 2` to your command line, or if you're sure you want to
in_tree_llvm_info,
include_default_paths: flags_include_default_paths,
incremental: flags_incremental || rust_incremental == Some(true),
initial_cargo,
initial_cargo_clippy: build_cargo_clippy,
initial_rustc,
initial_rustdoc,
initial_sysroot,
jobs: Some(threads_from_config(flags_jobs.or(build_jobs).unwrap_or(0))),
json_output: flags_json_output,
keep_stage: flags_keep_stage,
Expand Down Expand Up @@ -2275,8 +2250,9 @@ fn postprocess_toml(
toml.merge(None, &mut Default::default(), override_toml, ReplaceOpt::Override);
}

/// check rustc/cargo version is same or lower with 1 apart from the building one
pub fn check_stage0_version(
/// Check that the version of an externally provided rustc/cargo is either the same or 1 version
/// older than the in-tree version.
fn check_external_binary_version(
program_path: &Path,
component_name: &'static str,
src_dir: &Path,
Expand All @@ -2286,32 +2262,30 @@ pub fn check_stage0_version(
return;
}

let stage0_output =
command(program_path).arg("--version").run_capture_stdout(exec_ctx).stdout();
let mut stage0_output = stage0_output.lines().next().unwrap().split(' ');
let output = command(program_path).arg("--version").run_capture_stdout(exec_ctx).stdout();
let mut output = output.lines().next().unwrap().split(' ');

let stage0_name = stage0_output.next().unwrap();
if stage0_name != component_name {
let name = output.next().unwrap();
if name != component_name {
fail(&format!(
"Expected to find {component_name} at {} but it claims to be {stage0_name}",
"Expected to find {component_name} at {} but it claims to be {name}",
program_path.display()
));
}

let stage0_version =
semver::Version::parse(stage0_output.next().unwrap().split('-').next().unwrap().trim())
.unwrap();
let binary_version =
semver::Version::parse(output.next().unwrap().split('-').next().unwrap().trim()).unwrap();
let source_version =
semver::Version::parse(fs::read_to_string(src_dir.join("src/version")).unwrap().trim())
.unwrap();
if !(source_version == stage0_version
|| (source_version.major == stage0_version.major
&& (source_version.minor == stage0_version.minor
|| source_version.minor == stage0_version.minor + 1)))
if !(source_version == binary_version
|| (source_version.major == binary_version.major
&& (source_version.minor == binary_version.minor
|| source_version.minor == binary_version.minor + 1)))
{
let prev_version = format!("{}.{}.x", source_version.major, source_version.minor - 1);
fail(&format!(
"Unexpected {component_name} version: {stage0_version}, we should use {prev_version}/{source_version} to build source with {source_version}"
"Unexpected {component_name} version: {binary_version}, we should use {prev_version}/{source_version} to build source with {source_version}"
));
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/bootstrap/src/core/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,15 @@ enum DownloadSource {

/// Functions that are only ever called once, but named for clarity and to avoid thousand-line functions.
impl Config {
pub(crate) fn download_clippy(&self) -> PathBuf {
pub(crate) fn download_clippy(&self, initial_sysroot: &Path) -> PathBuf {
self.do_if_verbose(|| println!("downloading stage0 clippy artifacts"));

let date = &self.stage0_metadata.compiler.date;
let version = &self.stage0_metadata.compiler.version;
let host = self.host_target;

let clippy_stamp =
BuildStamp::new(&self.initial_sysroot).with_prefix("clippy").add_stamp(date);
let cargo_clippy = self.initial_sysroot.join("bin").join(exe("cargo-clippy", host));
let clippy_stamp = BuildStamp::new(initial_sysroot).with_prefix("clippy").add_stamp(date);
let cargo_clippy = initial_sysroot.join("bin").join(exe("cargo-clippy", host));
if cargo_clippy.exists() && clippy_stamp.is_up_to_date() {
return cargo_clippy;
}
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/core/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ than building it.
.map(|p| cmd_finder.must_have(p))
.or_else(|| cmd_finder.maybe_have("reuse"));

let stage0_supported_target_list: HashSet<String> = command(&sess.config.initial_rustc)
let stage0_supported_target_list: HashSet<String> = command(&sess.initial_rustc)
.args(["--print", "target-list"])
.run_in_dry_run()
.run_capture_stdout(&sess)
Expand Down Expand Up @@ -314,7 +314,7 @@ than building it.
}
}

for target in &sess.targets {
for target in &sess.config.targets {
sess.config
.target_config
.entry(*target)
Expand Down
Loading
Loading