Skip to content

Commit

Permalink
Unrolled build for rust-lang#128269
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#128269 - onur-ozkan:improve-cargo-invocations, r=Mark-Simulacrum

improve cargo invocations on bootstrap

Fixes few of the `FIXME`s on cargo invocations and should be considered as blocker for rust-lang#128180.
  • Loading branch information
rust-timer authored Jul 29, 2024
2 parents 2e63026 + 92ca0a6 commit 5c88116
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 117 deletions.
58 changes: 37 additions & 21 deletions src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ use crate::core::builder::{
use crate::core::config::TargetSelection;
use crate::{Compiler, Mode, Subcommand};

pub fn cargo_subcommand(kind: Kind) -> &'static str {
match kind {
Kind::Check
// We ensure check steps for both std and rustc from build_steps/clippy, so handle `Kind::Clippy` as well.
| Kind::Clippy => "check",
Kind::Fix => "fix",
_ => unreachable!(),
}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Std {
pub target: TargetSelection,
Expand All @@ -31,11 +21,22 @@ pub struct Std {
///
/// [`compile::Rustc`]: crate::core::build_steps::compile::Rustc
crates: Vec<String>,
/// Override `Builder::kind` on cargo invocations.
///
/// By default, `Builder::kind` is propagated as the subcommand to the cargo invocations.
/// However, there are cases when this is not desirable. For example, when running `x clippy $tool_name`,
/// passing `Builder::kind` to cargo invocations would run clippy on the entire compiler and library,
/// which is not useful if we only want to lint a few crates with specific rules.
override_build_kind: Option<Kind>,
}

impl Std {
pub fn new(target: TargetSelection) -> Self {
Self { target, crates: vec![] }
Self::new_with_build_kind(target, None)
}

pub fn new_with_build_kind(target: TargetSelection, kind: Option<Kind>) -> Self {
Self { target, crates: vec![], override_build_kind: kind }
}
}

Expand All @@ -49,7 +50,7 @@ impl Step for Std {

fn make_run(run: RunConfig<'_>) {
let crates = run.make_run_crates(Alias::Library);
run.builder.ensure(Std { target: run.target, crates });
run.builder.ensure(Std { target: run.target, crates, override_build_kind: None });
}

fn run(self, builder: &Builder<'_>) {
Expand All @@ -64,7 +65,7 @@ impl Step for Std {
Mode::Std,
SourceType::InTree,
target,
cargo_subcommand(builder.kind),
self.override_build_kind.unwrap_or(builder.kind),
);

std_cargo(builder, target, compiler.stage, &mut cargo);
Expand Down Expand Up @@ -118,7 +119,7 @@ impl Step for Std {
Mode::Std,
SourceType::InTree,
target,
cargo_subcommand(builder.kind),
self.override_build_kind.unwrap_or(builder.kind),
);

// If we're not in stage 0, tests and examples will fail to compile
Expand Down Expand Up @@ -159,16 +160,31 @@ pub struct Rustc {
///
/// [`compile::Rustc`]: crate::core::build_steps::compile::Rustc
crates: Vec<String>,
/// Override `Builder::kind` on cargo invocations.
///
/// By default, `Builder::kind` is propagated as the subcommand to the cargo invocations.
/// However, there are cases when this is not desirable. For example, when running `x clippy $tool_name`,
/// passing `Builder::kind` to cargo invocations would run clippy on the entire compiler and library,
/// which is not useful if we only want to lint a few crates with specific rules.
override_build_kind: Option<Kind>,
}

impl Rustc {
pub fn new(target: TargetSelection, builder: &Builder<'_>) -> Self {
Self::new_with_build_kind(target, builder, None)
}

pub fn new_with_build_kind(
target: TargetSelection,
builder: &Builder<'_>,
kind: Option<Kind>,
) -> Self {
let crates = builder
.in_tree_crates("rustc-main", Some(target))
.into_iter()
.map(|krate| krate.name.to_string())
.collect();
Self { target, crates }
Self { target, crates, override_build_kind: kind }
}
}

Expand All @@ -183,7 +199,7 @@ impl Step for Rustc {

fn make_run(run: RunConfig<'_>) {
let crates = run.make_run_crates(Alias::Compiler);
run.builder.ensure(Rustc { target: run.target, crates });
run.builder.ensure(Rustc { target: run.target, crates, override_build_kind: None });
}

/// Builds the compiler.
Expand All @@ -204,7 +220,7 @@ impl Step for Rustc {
builder.ensure(crate::core::build_steps::compile::Std::new(compiler, compiler.host));
builder.ensure(crate::core::build_steps::compile::Std::new(compiler, target));
} else {
builder.ensure(Std::new(target));
builder.ensure(Std::new_with_build_kind(target, self.override_build_kind));
}

let mut cargo = builder::Cargo::new(
Expand All @@ -213,7 +229,7 @@ impl Step for Rustc {
Mode::Rustc,
SourceType::InTree,
target,
cargo_subcommand(builder.kind),
self.override_build_kind.unwrap_or(builder.kind),
);

rustc_cargo(builder, &mut cargo, target, &compiler);
Expand Down Expand Up @@ -291,7 +307,7 @@ impl Step for CodegenBackend {
Mode::Codegen,
SourceType::InTree,
target,
cargo_subcommand(builder.kind),
builder.kind,
);

cargo
Expand Down Expand Up @@ -349,7 +365,7 @@ impl Step for RustAnalyzer {
compiler,
Mode::ToolRustc,
target,
cargo_subcommand(builder.kind),
builder.kind,
"src/tools/rust-analyzer",
SourceType::InTree,
&["in-rust-tree".to_owned()],
Expand Down Expand Up @@ -417,7 +433,7 @@ macro_rules! tool_check_step {
compiler,
Mode::ToolRustc,
target,
cargo_subcommand(builder.kind),
builder.kind,
$path,
$source_type,
&[],
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/core/build_steps/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::path::Path;

use crate::core::builder::{crate_description, Builder, RunConfig, ShouldRun, Step};
use crate::utils::helpers::t;
use crate::{Build, Compiler, Mode, Subcommand};
use crate::{Build, Compiler, Kind, Mode, Subcommand};

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct CleanAll {}
Expand Down Expand Up @@ -66,7 +66,7 @@ macro_rules! clean_crate_tree {
fn run(self, builder: &Builder<'_>) -> Self::Output {
let compiler = self.compiler;
let target = compiler.host;
let mut cargo = builder.bare_cargo(compiler, $mode, target, "clean");
let mut cargo = builder.bare_cargo(compiler, $mode, target, Kind::Clean);

// Since https://github.com/rust-lang/rust/pull/111076 enables
// unstable cargo feature (`public-dependency`), we need to ensure
Expand Down
18 changes: 12 additions & 6 deletions src/bootstrap/src/core/build_steps/clippy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,14 @@ impl Step for Std {
let target = self.target;
let compiler = builder.compiler(builder.top_stage, builder.config.build);

let mut cargo =
builder::Cargo::new(builder, compiler, Mode::Std, SourceType::InTree, target, "clippy");
let mut cargo = builder::Cargo::new(
builder,
compiler,
Mode::Std,
SourceType::InTree,
target,
Kind::Clippy,
);

std_cargo(builder, target, compiler.stage, &mut cargo);

Expand Down Expand Up @@ -178,7 +184,7 @@ impl Step for Rustc {
builder.ensure(compile::Std::new(compiler, compiler.host));
builder.ensure(compile::Std::new(compiler, target));
} else {
builder.ensure(check::Std::new(target));
builder.ensure(check::Std::new_with_build_kind(target, Some(Kind::Check)));
}

let mut cargo = builder::Cargo::new(
Expand All @@ -187,7 +193,7 @@ impl Step for Rustc {
Mode::Rustc,
SourceType::InTree,
target,
"clippy",
Kind::Clippy,
);

rustc_cargo(builder, &mut cargo, target, &compiler);
Expand Down Expand Up @@ -245,14 +251,14 @@ macro_rules! lint_any {
let compiler = builder.compiler(builder.top_stage, builder.config.build);
let target = self.target;

builder.ensure(check::Rustc::new(target, builder));
builder.ensure(check::Rustc::new_with_build_kind(target, builder, Some(Kind::Check)));

let cargo = prepare_tool_cargo(
builder,
compiler,
Mode::ToolRustc,
target,
"clippy",
Kind::Clippy,
$path,
SourceType::InTree,
&[],
Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl Step for Std {
Mode::Std,
SourceType::InTree,
target,
"check",
Kind::Check,
);
cargo.rustflag("-Zalways-encode-mir");
cargo.arg("--manifest-path").arg(builder.src.join("library/sysroot/Cargo.toml"));
Expand All @@ -259,7 +259,7 @@ impl Step for Std {
Mode::Std,
SourceType::InTree,
target,
"build",
Kind::Build,
);
std_cargo(builder, target, compiler.stage, &mut cargo);
for krate in &*self.crates {
Expand Down Expand Up @@ -919,7 +919,7 @@ impl Step for Rustc {
Mode::Rustc,
SourceType::InTree,
target,
"build",
Kind::Build,
);

rustc_cargo(builder, &mut cargo, target, &compiler);
Expand Down Expand Up @@ -1359,7 +1359,7 @@ impl Step for CodegenBackend {
Mode::Codegen,
SourceType::InTree,
target,
"build",
Kind::Build,
);
cargo
.arg("--manifest-path")
Expand Down
14 changes: 10 additions & 4 deletions src/bootstrap/src/core/build_steps/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ fn doc_std(
let out_dir = target_dir.join(target.triple).join("doc");

let mut cargo =
builder::Cargo::new(builder, compiler, Mode::Std, SourceType::InTree, target, "doc");
builder::Cargo::new(builder, compiler, Mode::Std, SourceType::InTree, target, Kind::Doc);

compile::std_cargo(builder, target, compiler.stage, &mut cargo);
cargo
Expand Down Expand Up @@ -816,8 +816,14 @@ impl Step for Rustc {
);

// Build cargo command.
let mut cargo =
builder::Cargo::new(builder, compiler, Mode::Rustc, SourceType::InTree, target, "doc");
let mut cargo = builder::Cargo::new(
builder,
compiler,
Mode::Rustc,
SourceType::InTree,
target,
Kind::Doc,
);

cargo.rustdocflag("--document-private-items");
// Since we always pass --document-private-items, there's no need to warn about linking to private items.
Expand Down Expand Up @@ -964,7 +970,7 @@ macro_rules! tool_doc {
compiler,
Mode::ToolRustc,
target,
"doc",
Kind::Doc,
$path,
source_type,
&[],
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/src/core/build_steps/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::path::PathBuf;
use crate::core::build_steps::dist::distdir;
use crate::core::build_steps::test;
use crate::core::build_steps::tool::{self, SourceType, Tool};
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
use crate::core::config::flags::get_completion;
use crate::core::config::TargetSelection;
use crate::utils::exec::command;
Expand Down Expand Up @@ -142,7 +142,7 @@ impl Step for Miri {
host_compiler,
Mode::ToolRustc,
host,
"run",
Kind::Run,
"src/tools/miri",
SourceType::InTree,
&[],
Expand Down
Loading

0 comments on commit 5c88116

Please sign in to comment.