Skip to content
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

Rollup of 5 pull requests #128330

Merged
merged 11 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
refactor cargo invocations with strongly-typed subcommand
Signed-off-by: onur-ozkan <work@onurozkan.dev>
  • Loading branch information
onur-ozkan committed Jul 27, 2024
commit d94e7ff065cd393a645eb3e9c96ce0418856e95d
22 changes: 6 additions & 16 deletions src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@ use crate::core::config::TargetSelection;
use crate::{Compiler, Mode, Subcommand};
use std::path::{Path, PathBuf};

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 Down Expand Up @@ -63,7 +53,7 @@ impl Step for Std {
Mode::Std,
SourceType::InTree,
target,
cargo_subcommand(builder.kind),
builder.kind,
);

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

// If we're not in stage 0, tests and examples will fail to compile
Expand Down Expand Up @@ -212,7 +202,7 @@ impl Step for Rustc {
Mode::Rustc,
SourceType::InTree,
target,
cargo_subcommand(builder.kind),
builder.kind,
);

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

cargo
Expand Down Expand Up @@ -348,7 +338,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 @@ -416,7 +406,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
14 changes: 10 additions & 4 deletions src/bootstrap/src/core/build_steps/clippy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,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 @@ -203,7 +209,7 @@ impl Step for Rustc {
Mode::Rustc,
SourceType::InTree,
target,
"clippy",
Kind::Clippy,
);

rustc_cargo(builder, &mut cargo, target, &compiler);
Expand Down Expand Up @@ -268,7 +274,7 @@ macro_rules! lint_any {
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 @@ -246,7 +246,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 @@ -258,7 +258,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 @@ -916,7 +916,7 @@ impl Step for Rustc {
Mode::Rustc,
SourceType::InTree,
target,
"build",
Kind::Build,
);

rustc_cargo(builder, &mut cargo, target, &compiler);
Expand Down Expand Up @@ -1356,7 +1356,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 @@ -712,7 +712,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 @@ -814,8 +814,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 @@ -962,7 +968,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