refactor cargo invocations with strongly-typed subcommand
Signed-off-by: onur-ozkan <work@onurozkan.dev>
This commit is contained in:
parent
a526d7ce45
commit
d94e7ff065
9 changed files with 117 additions and 109 deletions
|
|
@ -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,
|
||||
|
|
@ -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);
|
||||
|
|
@ -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
|
||||
|
|
@ -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);
|
||||
|
|
@ -290,7 +280,7 @@ impl Step for CodegenBackend {
|
|||
Mode::Codegen,
|
||||
SourceType::InTree,
|
||||
target,
|
||||
cargo_subcommand(builder.kind),
|
||||
builder.kind,
|
||||
);
|
||||
|
||||
cargo
|
||||
|
|
@ -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()],
|
||||
|
|
@ -416,7 +406,7 @@ macro_rules! tool_check_step {
|
|||
compiler,
|
||||
Mode::ToolRustc,
|
||||
target,
|
||||
cargo_subcommand(builder.kind),
|
||||
builder.kind,
|
||||
$path,
|
||||
$source_type,
|
||||
&[],
|
||||
|
|
|
|||
|
|
@ -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 {}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
@ -203,7 +209,7 @@ impl Step for Rustc {
|
|||
Mode::Rustc,
|
||||
SourceType::InTree,
|
||||
target,
|
||||
"clippy",
|
||||
Kind::Clippy,
|
||||
);
|
||||
|
||||
rustc_cargo(builder, &mut cargo, target, &compiler);
|
||||
|
|
@ -268,7 +274,7 @@ macro_rules! lint_any {
|
|||
compiler,
|
||||
Mode::ToolRustc,
|
||||
target,
|
||||
"clippy",
|
||||
Kind::Clippy,
|
||||
$path,
|
||||
SourceType::InTree,
|
||||
&[],
|
||||
|
|
|
|||
|
|
@ -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"));
|
||||
|
|
@ -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 {
|
||||
|
|
@ -916,7 +916,7 @@ impl Step for Rustc {
|
|||
Mode::Rustc,
|
||||
SourceType::InTree,
|
||||
target,
|
||||
"build",
|
||||
Kind::Build,
|
||||
);
|
||||
|
||||
rustc_cargo(builder, &mut cargo, target, &compiler);
|
||||
|
|
@ -1356,7 +1356,7 @@ impl Step for CodegenBackend {
|
|||
Mode::Codegen,
|
||||
SourceType::InTree,
|
||||
target,
|
||||
"build",
|
||||
Kind::Build,
|
||||
);
|
||||
cargo
|
||||
.arg("--manifest-path")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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.
|
||||
|
|
@ -962,7 +968,7 @@ macro_rules! tool_doc {
|
|||
compiler,
|
||||
Mode::ToolRustc,
|
||||
target,
|
||||
"doc",
|
||||
Kind::Doc,
|
||||
$path,
|
||||
source_type,
|
||||
&[],
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -142,7 +142,7 @@ impl Step for Miri {
|
|||
host_compiler,
|
||||
Mode::ToolRustc,
|
||||
host,
|
||||
"run",
|
||||
Kind::Run,
|
||||
"src/tools/miri",
|
||||
SourceType::InTree,
|
||||
&[],
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ impl Step for CrateBootstrap {
|
|||
compiler,
|
||||
Mode::ToolBootstrap,
|
||||
bootstrap_host,
|
||||
"test",
|
||||
Kind::Test,
|
||||
path,
|
||||
SourceType::InTree,
|
||||
&[],
|
||||
|
|
@ -124,7 +124,7 @@ You can skip linkcheck with --skip src/tools/linkchecker"
|
|||
compiler,
|
||||
Mode::ToolBootstrap,
|
||||
bootstrap_host,
|
||||
"test",
|
||||
Kind::Test,
|
||||
"src/tools/linkchecker",
|
||||
SourceType::InTree,
|
||||
&[],
|
||||
|
|
@ -289,7 +289,7 @@ impl Step for Cargo {
|
|||
compiler,
|
||||
Mode::ToolRustc,
|
||||
self.host,
|
||||
"test",
|
||||
Kind::Test,
|
||||
"src/tools/cargo",
|
||||
SourceType::Submodule,
|
||||
&[],
|
||||
|
|
@ -360,7 +360,7 @@ impl Step for RustAnalyzer {
|
|||
compiler,
|
||||
Mode::ToolRustc,
|
||||
host,
|
||||
"test",
|
||||
Kind::Test,
|
||||
crate_path,
|
||||
SourceType::InTree,
|
||||
&["in-rust-tree".to_owned()],
|
||||
|
|
@ -412,7 +412,7 @@ impl Step for Rustfmt {
|
|||
compiler,
|
||||
Mode::ToolRustc,
|
||||
host,
|
||||
"test",
|
||||
Kind::Test,
|
||||
"src/tools/rustfmt",
|
||||
SourceType::InTree,
|
||||
&[],
|
||||
|
|
@ -447,7 +447,7 @@ impl Miri {
|
|||
Mode::Std,
|
||||
SourceType::Submodule,
|
||||
target,
|
||||
"miri-setup",
|
||||
Kind::MiriSetup,
|
||||
);
|
||||
|
||||
// Tell `cargo miri setup` where to find the sources.
|
||||
|
|
@ -532,7 +532,7 @@ impl Step for Miri {
|
|||
host_compiler,
|
||||
Mode::ToolRustc,
|
||||
host,
|
||||
"test",
|
||||
Kind::Test,
|
||||
"src/tools/miri",
|
||||
SourceType::InTree,
|
||||
&[],
|
||||
|
|
@ -622,7 +622,7 @@ impl Step for CargoMiri {
|
|||
compiler,
|
||||
Mode::ToolStd, // it's unclear what to use here, we're not building anything just doing a smoke test!
|
||||
target,
|
||||
"miri-test",
|
||||
Kind::MiriTest,
|
||||
"src/tools/miri/test-cargo-miri",
|
||||
SourceType::Submodule,
|
||||
&[],
|
||||
|
|
@ -682,7 +682,7 @@ impl Step for CompiletestTest {
|
|||
// when std sources change.
|
||||
Mode::ToolStd,
|
||||
host,
|
||||
"test",
|
||||
Kind::Test,
|
||||
"src/tools/compiletest",
|
||||
SourceType::InTree,
|
||||
&[],
|
||||
|
|
@ -732,7 +732,7 @@ impl Step for Clippy {
|
|||
compiler,
|
||||
Mode::ToolRustc,
|
||||
host,
|
||||
"test",
|
||||
Kind::Test,
|
||||
"src/tools/clippy",
|
||||
SourceType::InTree,
|
||||
&[],
|
||||
|
|
@ -1282,7 +1282,7 @@ impl Step for RunMakeSupport {
|
|||
self.compiler,
|
||||
Mode::ToolStd,
|
||||
self.target,
|
||||
"build",
|
||||
Kind::Build,
|
||||
"src/tools/run-make-support",
|
||||
SourceType::InTree,
|
||||
&[],
|
||||
|
|
@ -1326,7 +1326,7 @@ impl Step for CrateRunMakeSupport {
|
|||
compiler,
|
||||
Mode::ToolBootstrap,
|
||||
host,
|
||||
"test",
|
||||
Kind::Test,
|
||||
"src/tools/run-make-support",
|
||||
SourceType::InTree,
|
||||
&[],
|
||||
|
|
@ -1372,7 +1372,7 @@ impl Step for CrateBuildHelper {
|
|||
compiler,
|
||||
Mode::ToolBootstrap,
|
||||
host,
|
||||
"test",
|
||||
Kind::Test,
|
||||
"src/tools/build_helper",
|
||||
SourceType::InTree,
|
||||
&[],
|
||||
|
|
@ -2631,7 +2631,7 @@ impl Step for Crate {
|
|||
mode,
|
||||
SourceType::InTree,
|
||||
target,
|
||||
"miri-test",
|
||||
Kind::MiriTest,
|
||||
);
|
||||
// This hack helps bootstrap run standard library tests in Miri. The issue is as
|
||||
// follows: when running `cargo miri test` on libcore, cargo builds a local copy of core
|
||||
|
|
@ -2654,14 +2654,7 @@ impl Step for Crate {
|
|||
}
|
||||
|
||||
// Build `cargo test` command
|
||||
builder::Cargo::new(
|
||||
builder,
|
||||
compiler,
|
||||
mode,
|
||||
SourceType::InTree,
|
||||
target,
|
||||
builder.kind.as_str(),
|
||||
)
|
||||
builder::Cargo::new(builder, compiler, mode, SourceType::InTree, target, builder.kind)
|
||||
};
|
||||
|
||||
match mode {
|
||||
|
|
@ -2753,7 +2746,7 @@ impl Step for CrateRustdoc {
|
|||
compiler,
|
||||
Mode::ToolRustc,
|
||||
target,
|
||||
builder.kind.as_str(),
|
||||
builder.kind,
|
||||
"src/tools/rustdoc",
|
||||
SourceType::InTree,
|
||||
&[],
|
||||
|
|
@ -2845,7 +2838,7 @@ impl Step for CrateRustdocJsonTypes {
|
|||
compiler,
|
||||
Mode::ToolRustc,
|
||||
target,
|
||||
builder.kind.as_str(),
|
||||
builder.kind,
|
||||
"src/rustdoc-json-types",
|
||||
SourceType::InTree,
|
||||
&[],
|
||||
|
|
@ -3080,7 +3073,7 @@ impl Step for TierCheck {
|
|||
self.compiler,
|
||||
Mode::ToolStd,
|
||||
self.compiler.host,
|
||||
"run",
|
||||
Kind::Run,
|
||||
"src/tools/tier-check",
|
||||
SourceType::InTree,
|
||||
&[],
|
||||
|
|
@ -3152,7 +3145,7 @@ impl Step for RustInstaller {
|
|||
compiler,
|
||||
Mode::ToolBootstrap,
|
||||
bootstrap_host,
|
||||
"test",
|
||||
Kind::Test,
|
||||
"src/tools/rust-installer",
|
||||
SourceType::InTree,
|
||||
&[],
|
||||
|
|
@ -3322,7 +3315,7 @@ impl Step for CodegenCranelift {
|
|||
Mode::Codegen, // Must be codegen to ensure dlopen on compiled dylibs works
|
||||
SourceType::InTree,
|
||||
target,
|
||||
"run",
|
||||
Kind::Run,
|
||||
);
|
||||
|
||||
cargo.current_dir(&builder.src.join("compiler/rustc_codegen_cranelift"));
|
||||
|
|
@ -3454,7 +3447,7 @@ impl Step for CodegenGCC {
|
|||
Mode::Codegen, // Must be codegen to ensure dlopen on compiled dylibs works
|
||||
SourceType::InTree,
|
||||
target,
|
||||
"run",
|
||||
Kind::Run,
|
||||
);
|
||||
|
||||
cargo.current_dir(&builder.src.join("compiler/rustc_codegen_gcc"));
|
||||
|
|
@ -3542,7 +3535,7 @@ impl Step for TestFloatParse {
|
|||
compiler,
|
||||
Mode::ToolStd,
|
||||
bootstrap_host,
|
||||
"test",
|
||||
Kind::Test,
|
||||
path,
|
||||
SourceType::InTree,
|
||||
&[],
|
||||
|
|
@ -3565,7 +3558,7 @@ impl Step for TestFloatParse {
|
|||
compiler,
|
||||
Mode::ToolStd,
|
||||
bootstrap_host,
|
||||
"run",
|
||||
Kind::Run,
|
||||
path,
|
||||
SourceType::InTree,
|
||||
&[],
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ impl Step for ToolBuild {
|
|||
compiler,
|
||||
self.mode,
|
||||
target,
|
||||
"build",
|
||||
Kind::Build,
|
||||
path,
|
||||
self.source_type,
|
||||
&self.extra_features,
|
||||
|
|
@ -139,12 +139,12 @@ pub fn prepare_tool_cargo(
|
|||
compiler: Compiler,
|
||||
mode: Mode,
|
||||
target: TargetSelection,
|
||||
command: &'static str,
|
||||
cmd_kind: Kind,
|
||||
path: &str,
|
||||
source_type: SourceType,
|
||||
extra_features: &[String],
|
||||
) -> CargoCommand {
|
||||
let mut cargo = builder::Cargo::new(builder, compiler, mode, source_type, target, command);
|
||||
let mut cargo = builder::Cargo::new(builder, compiler, mode, source_type, target, cmd_kind);
|
||||
|
||||
let dir = builder.src.join(path);
|
||||
cargo.arg("--manifest-path").arg(dir.join("Cargo.toml"));
|
||||
|
|
@ -640,7 +640,7 @@ impl Step for Rustdoc {
|
|||
build_compiler,
|
||||
Mode::ToolRustc,
|
||||
target,
|
||||
"build",
|
||||
Kind::Build,
|
||||
"src/tools/rustdoc",
|
||||
SourceType::InTree,
|
||||
features.as_slice(),
|
||||
|
|
@ -899,7 +899,7 @@ impl Step for LlvmBitcodeLinker {
|
|||
self.compiler,
|
||||
Mode::ToolRustc,
|
||||
self.target,
|
||||
"build",
|
||||
Kind::Build,
|
||||
"src/tools/llvm-bitcode-linker",
|
||||
SourceType::InTree,
|
||||
&self.extra_features,
|
||||
|
|
|
|||
|
|
@ -701,6 +701,8 @@ pub enum Kind {
|
|||
#[value(alias = "t")]
|
||||
Test,
|
||||
Miri,
|
||||
MiriSetup,
|
||||
MiriTest,
|
||||
Bench,
|
||||
#[value(alias = "d")]
|
||||
Doc,
|
||||
|
|
@ -725,6 +727,8 @@ impl Kind {
|
|||
Kind::Format => "fmt",
|
||||
Kind::Test => "test",
|
||||
Kind::Miri => "miri",
|
||||
Kind::MiriSetup => panic!("`as_str` is not supported for `Kind::MiriSetup`."),
|
||||
Kind::MiriTest => panic!("`as_str` is not supported for `Kind::MiriTest`."),
|
||||
Kind::Bench => "bench",
|
||||
Kind::Doc => "doc",
|
||||
Kind::Clean => "clean",
|
||||
|
|
@ -1000,6 +1004,7 @@ impl<'a> Builder<'a> {
|
|||
Kind::Vendor => describe!(vendor::Vendor),
|
||||
// special-cased in Build::build()
|
||||
Kind::Format | Kind::Suggest | Kind::Perf => vec![],
|
||||
Kind::MiriTest | Kind::MiriSetup => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1386,23 +1391,30 @@ impl<'a> Builder<'a> {
|
|||
compiler: Compiler,
|
||||
mode: Mode,
|
||||
target: TargetSelection,
|
||||
cmd: &str, // FIXME make this properly typed
|
||||
cmd_kind: Kind,
|
||||
) -> BootstrapCommand {
|
||||
let mut cargo;
|
||||
if cmd == "clippy" {
|
||||
cargo = self.cargo_clippy_cmd(compiler);
|
||||
cargo.arg(cmd);
|
||||
} else if let Some(subcmd) = cmd.strip_prefix("miri") {
|
||||
// Command must be "miri-X".
|
||||
let subcmd = subcmd
|
||||
.strip_prefix('-')
|
||||
.unwrap_or_else(|| panic!("expected `miri-$subcommand`, but got {}", cmd));
|
||||
cargo = self.cargo_miri_cmd(compiler);
|
||||
cargo.arg("miri").arg(subcmd);
|
||||
} else {
|
||||
cargo = command(&self.initial_cargo);
|
||||
cargo.arg(cmd);
|
||||
}
|
||||
let mut cargo = match cmd_kind {
|
||||
Kind::Clippy => {
|
||||
let mut cargo = self.cargo_clippy_cmd(compiler);
|
||||
cargo.arg(cmd_kind.as_str());
|
||||
cargo
|
||||
}
|
||||
Kind::MiriSetup => {
|
||||
let mut cargo = self.cargo_miri_cmd(compiler);
|
||||
cargo.arg("miri").arg("setup");
|
||||
cargo
|
||||
}
|
||||
Kind::MiriTest => {
|
||||
let mut cargo = self.cargo_miri_cmd(compiler);
|
||||
cargo.arg("miri").arg("test");
|
||||
cargo
|
||||
}
|
||||
_ => {
|
||||
let mut cargo = command(&self.initial_cargo);
|
||||
cargo.arg(cmd_kind.as_str());
|
||||
cargo
|
||||
}
|
||||
};
|
||||
|
||||
// Run cargo from the source root so it can find .cargo/config.
|
||||
// This matters when using vendoring and the working directory is outside the repository.
|
||||
|
|
@ -1431,7 +1443,7 @@ impl<'a> Builder<'a> {
|
|||
Color::Auto => {} // nothing to do
|
||||
}
|
||||
|
||||
if cmd != "install" {
|
||||
if cmd_kind != Kind::Install {
|
||||
cargo.arg("--target").arg(target.rustc_target_arg());
|
||||
} else {
|
||||
assert_eq!(target, compiler.host);
|
||||
|
|
@ -1440,8 +1452,11 @@ impl<'a> Builder<'a> {
|
|||
if self.config.rust_optimize.is_release() {
|
||||
// FIXME: cargo bench/install do not accept `--release`
|
||||
// and miri doesn't want it
|
||||
if cmd != "bench" && cmd != "install" && !cmd.starts_with("miri-") {
|
||||
cargo.arg("--release");
|
||||
match cmd_kind {
|
||||
Kind::Bench | Kind::Install | Kind::Miri | Kind::MiriSetup | Kind::MiriTest => {}
|
||||
_ => {
|
||||
cargo.arg("--release");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1464,9 +1479,9 @@ impl<'a> Builder<'a> {
|
|||
mode: Mode,
|
||||
source_type: SourceType,
|
||||
target: TargetSelection,
|
||||
cmd: &str, // FIXME make this properly typed
|
||||
cmd_kind: Kind,
|
||||
) -> Cargo {
|
||||
let mut cargo = self.bare_cargo(compiler, mode, target, cmd);
|
||||
let mut cargo = self.bare_cargo(compiler, mode, target, cmd_kind);
|
||||
let out_dir = self.stage_out(compiler, mode);
|
||||
|
||||
let mut hostflags = HostFlags::default();
|
||||
|
|
@ -1477,7 +1492,7 @@ impl<'a> Builder<'a> {
|
|||
self.clear_if_dirty(&out_dir, &backend);
|
||||
}
|
||||
|
||||
if cmd == "doc" || cmd == "rustdoc" {
|
||||
if cmd_kind == Kind::Doc {
|
||||
let my_out = match mode {
|
||||
// This is the intended out directory for compiler documentation.
|
||||
Mode::Rustc | Mode::ToolRustc => self.compiler_doc_out(target),
|
||||
|
|
@ -1508,7 +1523,7 @@ impl<'a> Builder<'a> {
|
|||
|
||||
// Set a flag for `check`/`clippy`/`fix`, so that certain build
|
||||
// scripts can do less work (i.e. not building/requiring LLVM).
|
||||
if cmd == "check" || cmd == "clippy" || cmd == "fix" {
|
||||
if matches!(cmd_kind, Kind::Check | Kind::Clippy | Kind::Fix) {
|
||||
// If we've not yet built LLVM, or it's stale, then bust
|
||||
// the rustc_llvm cache. That will always work, even though it
|
||||
// may mean that on the next non-check build we'll need to rebuild
|
||||
|
|
@ -1558,7 +1573,7 @@ impl<'a> Builder<'a> {
|
|||
rustflags.arg("--cfg=bootstrap");
|
||||
}
|
||||
|
||||
if cmd == "clippy" {
|
||||
if cmd_kind == Kind::Clippy {
|
||||
// clippy overwrites sysroot if we pass it to cargo.
|
||||
// Pass it directly to clippy instead.
|
||||
// NOTE: this can't be fixed in clippy because we explicitly don't set `RUSTC`,
|
||||
|
|
@ -1654,7 +1669,7 @@ impl<'a> Builder<'a> {
|
|||
Mode::Std | Mode::ToolBootstrap | Mode::ToolStd => {}
|
||||
Mode::Rustc | Mode::Codegen | Mode::ToolRustc => {
|
||||
// Build proc macros both for the host and the target
|
||||
if target != compiler.host && cmd != "check" {
|
||||
if target != compiler.host && cmd_kind != Kind::Check {
|
||||
cargo.arg("-Zdual-proc-macros");
|
||||
rustflags.arg("-Zdual-proc-macros");
|
||||
}
|
||||
|
|
@ -1739,7 +1754,7 @@ impl<'a> Builder<'a> {
|
|||
}
|
||||
cargo.env("__CARGO_DEFAULT_LIB_METADATA", &metadata);
|
||||
|
||||
if cmd == "clippy" {
|
||||
if cmd_kind == Kind::Clippy {
|
||||
rustflags.arg("-Zforce-unstable-if-unmarked");
|
||||
}
|
||||
|
||||
|
|
@ -1755,10 +1770,15 @@ impl<'a> Builder<'a> {
|
|||
//
|
||||
// Only clear out the directory if we're compiling std; otherwise, we
|
||||
// should let Cargo take care of things for us (via depdep info)
|
||||
if !self.config.dry_run() && mode == Mode::Std && cmd == "build" {
|
||||
if !self.config.dry_run() && mode == Mode::Std && cmd_kind == Kind::Build {
|
||||
self.clear_if_dirty(&out_dir, &self.rustc(compiler));
|
||||
}
|
||||
|
||||
let rustdoc_path = match cmd_kind {
|
||||
Kind::Doc | Kind::Test | Kind::MiriTest => self.rustdoc(compiler),
|
||||
_ => PathBuf::from("/path/to/nowhere/rustdoc/not/required"),
|
||||
};
|
||||
|
||||
// Customize the compiler we're running. Specify the compiler to cargo
|
||||
// as our shim and then pass it some various options used to configure
|
||||
// how the actual compiler itself is called.
|
||||
|
|
@ -1772,15 +1792,7 @@ impl<'a> Builder<'a> {
|
|||
.env("RUSTC_SYSROOT", sysroot)
|
||||
.env("RUSTC_LIBDIR", libdir)
|
||||
.env("RUSTDOC", self.bootstrap_out.join("rustdoc"))
|
||||
.env(
|
||||
"RUSTDOC_REAL",
|
||||
// Make sure to handle both `test` and `miri-test` commands.
|
||||
if cmd == "doc" || cmd == "rustdoc" || (cmd.ends_with("test") && want_rustdoc) {
|
||||
self.rustdoc(compiler)
|
||||
} else {
|
||||
PathBuf::from("/path/to/nowhere/rustdoc/not/required")
|
||||
},
|
||||
)
|
||||
.env("RUSTDOC_REAL", rustdoc_path)
|
||||
.env("RUSTC_ERROR_METADATA_DST", self.extended_error_dir())
|
||||
.env("RUSTC_BREAK_ON_ICE", "1");
|
||||
|
||||
|
|
@ -1799,7 +1811,7 @@ impl<'a> Builder<'a> {
|
|||
}
|
||||
|
||||
// If this is for `miri-test`, prepare the sysroots.
|
||||
if cmd == "miri-test" {
|
||||
if cmd_kind == Kind::MiriTest {
|
||||
self.ensure(compile::Std::new(compiler, compiler.host));
|
||||
let host_sysroot = self.sysroot(compiler);
|
||||
let miri_sysroot = test::Miri::build_miri_sysroot(self, compiler, target);
|
||||
|
|
@ -1813,7 +1825,8 @@ impl<'a> Builder<'a> {
|
|||
rustflags.arg(&format!("-Zstack-protector={stack_protector}"));
|
||||
}
|
||||
|
||||
if !(["build", "check", "clippy", "fix", "rustc"].contains(&cmd)) && want_rustdoc {
|
||||
if !matches!(cmd_kind, Kind::Build | Kind::Check | Kind::Clippy | Kind::Fix) && want_rustdoc
|
||||
{
|
||||
cargo.env("RUSTDOC_LIBDIR", self.rustc_libdir(compiler));
|
||||
}
|
||||
|
||||
|
|
@ -2430,9 +2443,9 @@ impl Cargo {
|
|||
mode: Mode,
|
||||
source_type: SourceType,
|
||||
target: TargetSelection,
|
||||
cmd: &str, // FIXME make this properly typed
|
||||
cmd_kind: Kind,
|
||||
) -> Cargo {
|
||||
let mut cargo = builder.cargo(compiler, mode, source_type, target, cmd);
|
||||
let mut cargo = builder.cargo(compiler, mode, source_type, target, cmd_kind);
|
||||
cargo.configure_linker(builder);
|
||||
cargo
|
||||
}
|
||||
|
|
@ -2448,9 +2461,9 @@ impl Cargo {
|
|||
mode: Mode,
|
||||
source_type: SourceType,
|
||||
target: TargetSelection,
|
||||
cmd: &str, // FIXME make this properly typed
|
||||
cmd_kind: Kind,
|
||||
) -> Cargo {
|
||||
builder.cargo(compiler, mode, source_type, target, cmd)
|
||||
builder.cargo(compiler, mode, source_type, target, cmd_kind)
|
||||
}
|
||||
|
||||
pub fn rustdocflag(&mut self, arg: &str) -> &mut Cargo {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue