Rollup merge of #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 https://github.com/rust-lang/rust/issues/128180.
This commit is contained in:
Matthias Krüger 2024-07-29 07:11:16 +02:00 committed by GitHub
commit 9b82536776
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 151 additions and 117 deletions

View File

@ -12,16 +12,6 @@
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,
@ -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 }
}
}
@ -49,7 +50,7 @@ fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
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<'_>) {
@ -64,7 +65,7 @@ fn run(self, builder: &Builder<'_>) {
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);
@ -118,7 +119,7 @@ fn run(self, builder: &Builder<'_>) {
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
@ -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 }
}
}
@ -183,7 +199,7 @@ fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
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.
@ -204,7 +220,7 @@ fn run(self, builder: &Builder<'_>) {
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(
@ -213,7 +229,7 @@ fn run(self, builder: &Builder<'_>) {
Mode::Rustc,
SourceType::InTree,
target,
cargo_subcommand(builder.kind),
self.override_build_kind.unwrap_or(builder.kind),
);
rustc_cargo(builder, &mut cargo, target, &compiler);
@ -291,7 +307,7 @@ fn run(self, builder: &Builder<'_>) {
Mode::Codegen,
SourceType::InTree,
target,
cargo_subcommand(builder.kind),
builder.kind,
);
cargo
@ -349,7 +365,7 @@ fn run(self, builder: &Builder<'_>) {
compiler,
Mode::ToolRustc,
target,
cargo_subcommand(builder.kind),
builder.kind,
"src/tools/rust-analyzer",
SourceType::InTree,
&["in-rust-tree".to_owned()],
@ -417,7 +433,7 @@ fn run(self, builder: &Builder<'_>) {
compiler,
Mode::ToolRustc,
target,
cargo_subcommand(builder.kind),
builder.kind,
$path,
$source_type,
&[],

View File

@ -11,7 +11,7 @@
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 @@ fn make_run(run: RunConfig<'_>) {
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

View File

@ -116,8 +116,14 @@ fn run(self, builder: &Builder<'_>) {
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);
@ -178,7 +184,7 @@ fn run(self, builder: &Builder<'_>) {
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(
@ -187,7 +193,7 @@ fn run(self, builder: &Builder<'_>) {
Mode::Rustc,
SourceType::InTree,
target,
"clippy",
Kind::Clippy,
);
rustc_cargo(builder, &mut cargo, target, &compiler);
@ -245,14 +251,14 @@ fn run(self, builder: &Builder<'_>) -> Self::Output {
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,
&[],

View File

@ -247,7 +247,7 @@ fn run(self, builder: &Builder<'_>) {
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"));
@ -259,7 +259,7 @@ fn run(self, builder: &Builder<'_>) {
Mode::Std,
SourceType::InTree,
target,
"build",
Kind::Build,
);
std_cargo(builder, target, compiler.stage, &mut cargo);
for krate in &*self.crates {
@ -919,7 +919,7 @@ fn run(self, builder: &Builder<'_>) -> u32 {
Mode::Rustc,
SourceType::InTree,
target,
"build",
Kind::Build,
);
rustc_cargo(builder, &mut cargo, target, &compiler);
@ -1359,7 +1359,7 @@ fn run(self, builder: &Builder<'_>) {
Mode::Codegen,
SourceType::InTree,
target,
"build",
Kind::Build,
);
cargo
.arg("--manifest-path")

View File

@ -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
@ -816,8 +816,14 @@ fn run(self, builder: &Builder<'_>) {
);
// 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.
@ -964,7 +970,7 @@ fn run(self, builder: &Builder<'_>) {
compiler,
Mode::ToolRustc,
target,
"doc",
Kind::Doc,
$path,
source_type,
&[],

View File

@ -8,7 +8,7 @@
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 @@ fn run(self, builder: &Builder<'_>) {
host_compiler,
Mode::ToolRustc,
host,
"run",
Kind::Run,
"src/tools/miri",
SourceType::InTree,
&[],

View File

@ -68,7 +68,7 @@ fn run(self, builder: &Builder<'_>) {
compiler,
Mode::ToolBootstrap,
bootstrap_host,
"test",
Kind::Test,
path,
SourceType::InTree,
&[],
@ -119,7 +119,7 @@ fn run(self, builder: &Builder<'_>) {
compiler,
Mode::ToolBootstrap,
bootstrap_host,
"test",
Kind::Test,
"src/tools/linkchecker",
SourceType::InTree,
&[],
@ -284,7 +284,7 @@ fn run(self, builder: &Builder<'_>) {
compiler,
Mode::ToolRustc,
self.host,
"test",
Kind::Test,
"src/tools/cargo",
SourceType::Submodule,
&[],
@ -355,7 +355,7 @@ fn run(self, builder: &Builder<'_>) {
compiler,
Mode::ToolRustc,
host,
"test",
Kind::Test,
crate_path,
SourceType::InTree,
&["in-rust-tree".to_owned()],
@ -407,7 +407,7 @@ fn run(self, builder: &Builder<'_>) {
compiler,
Mode::ToolRustc,
host,
"test",
Kind::Test,
"src/tools/rustfmt",
SourceType::InTree,
&[],
@ -442,7 +442,7 @@ pub fn build_miri_sysroot(
Mode::Std,
SourceType::Submodule,
target,
"miri-setup",
Kind::MiriSetup,
);
// Tell `cargo miri setup` where to find the sources.
@ -527,7 +527,7 @@ fn run(self, builder: &Builder<'_>) {
host_compiler,
Mode::ToolRustc,
host,
"test",
Kind::Test,
"src/tools/miri",
SourceType::InTree,
&[],
@ -617,7 +617,7 @@ fn run(self, builder: &Builder<'_>) {
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,
&[],
@ -677,7 +677,7 @@ fn run(self, builder: &Builder<'_>) {
// when std sources change.
Mode::ToolStd,
host,
"test",
Kind::Test,
"src/tools/compiletest",
SourceType::InTree,
&[],
@ -727,7 +727,7 @@ fn run(self, builder: &Builder<'_>) {
compiler,
Mode::ToolRustc,
host,
"test",
Kind::Test,
"src/tools/clippy",
SourceType::InTree,
&[],
@ -1277,7 +1277,7 @@ fn run(self, builder: &Builder<'_>) -> PathBuf {
self.compiler,
Mode::ToolStd,
self.target,
"build",
Kind::Build,
"src/tools/run-make-support",
SourceType::InTree,
&[],
@ -1321,7 +1321,7 @@ fn run(self, builder: &Builder<'_>) {
compiler,
Mode::ToolBootstrap,
host,
"test",
Kind::Test,
"src/tools/run-make-support",
SourceType::InTree,
&[],
@ -1367,7 +1367,7 @@ fn run(self, builder: &Builder<'_>) {
compiler,
Mode::ToolBootstrap,
host,
"test",
Kind::Test,
"src/tools/build_helper",
SourceType::InTree,
&[],
@ -2631,7 +2631,7 @@ fn run(self, builder: &Builder<'_>) {
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 @@ fn run(self, builder: &Builder<'_>) {
}
// 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 @@ fn run(self, builder: &Builder<'_>) {
compiler,
Mode::ToolRustc,
target,
builder.kind.as_str(),
builder.kind,
"src/tools/rustdoc",
SourceType::InTree,
&[],
@ -2845,7 +2838,7 @@ fn run(self, builder: &Builder<'_>) {
compiler,
Mode::ToolRustc,
target,
builder.kind.as_str(),
builder.kind,
"src/rustdoc-json-types",
SourceType::InTree,
&[],
@ -3079,7 +3072,7 @@ fn run(self, builder: &Builder<'_>) {
self.compiler,
Mode::ToolStd,
self.compiler.host,
"run",
Kind::Run,
"src/tools/tier-check",
SourceType::InTree,
&[],
@ -3151,7 +3144,7 @@ fn run(self, builder: &Builder<'_>) {
compiler,
Mode::ToolBootstrap,
bootstrap_host,
"test",
Kind::Test,
"src/tools/rust-installer",
SourceType::InTree,
&[],
@ -3321,7 +3314,7 @@ fn run(self, builder: &Builder<'_>) {
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"));
@ -3453,7 +3446,7 @@ fn run(self, builder: &Builder<'_>) {
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"));
@ -3541,7 +3534,7 @@ fn run(self, builder: &Builder<'_>) {
compiler,
Mode::ToolStd,
bootstrap_host,
"test",
Kind::Test,
path,
SourceType::InTree,
&[],
@ -3564,7 +3557,7 @@ fn run(self, builder: &Builder<'_>) {
compiler,
Mode::ToolStd,
bootstrap_host,
"run",
Kind::Run,
path,
SourceType::InTree,
&[],

View File

@ -90,7 +90,7 @@ fn run(self, builder: &Builder<'_>) -> PathBuf {
compiler,
self.mode,
target,
"build",
Kind::Build,
path,
self.source_type,
&self.extra_features,
@ -136,12 +136,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"));
@ -646,7 +646,7 @@ fn run(self, builder: &Builder<'_>) -> PathBuf {
build_compiler,
Mode::ToolRustc,
target,
"build",
Kind::Build,
"src/tools/rustdoc",
SourceType::InTree,
features.as_slice(),
@ -905,7 +905,7 @@ fn run(self, builder: &Builder<'_>) -> PathBuf {
self.compiler,
Mode::ToolRustc,
self.target,
"build",
Kind::Build,
"src/tools/llvm-bitcode-linker",
SourceType::InTree,
&self.extra_features,

View File

@ -689,7 +689,7 @@ fn pathset_for_paths_removing_matches(
}
}
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
#[derive(Debug, Copy, Clone, Eq, Hash, PartialEq, PartialOrd, Ord, ValueEnum)]
pub enum Kind {
#[value(alias = "b")]
Build,
@ -701,6 +701,8 @@ pub enum Kind {
#[value(alias = "t")]
Test,
Miri,
MiriSetup,
MiriTest,
Bench,
#[value(alias = "d")]
Doc,
@ -725,6 +727,8 @@ pub fn as_str(&self) -> &'static str {
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 @@ macro_rules! describe {
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 @@ pub fn bare_cargo(
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 @@ pub fn bare_cargo(
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,10 +1452,13 @@ pub fn bare_cargo(
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-") {
match cmd_kind {
Kind::Bench | Kind::Install | Kind::Miri | Kind::MiriSetup | Kind::MiriTest => {}
_ => {
cargo.arg("--release");
}
}
}
// Remove make-related flags to ensure Cargo can correctly set things up
cargo.env_remove("MAKEFLAGS");
@ -1464,9 +1479,9 @@ fn cargo(
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 @@ fn cargo(
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 @@ fn cargo(
// 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 @@ fn cargo(
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 @@ fn cargo(
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 @@ fn cargo(
}
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 @@ fn cargo(
//
// 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 @@ fn cargo(
.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 @@ fn cargo(
}
// 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 @@ fn cargo(
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 @@ pub fn new(
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 @@ pub fn new_for_mir_opt_tests(
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 {