Skip to content

Commit 29555f5

Browse files
authored
Unrolled build for rust-lang#126470
Rollup merge of rust-lang#126470 - onur-ozkan:optional-cargo-submodule, r=Kobzol make cargo submodule optional Right now, we fetch the cargo submodule no matter what, even if the command we are running doesn't need it (e.g., `x build compiler library`). This PR changes that to only fetch the cargo submodule when it's necessary. For more context, see the zulip thread: https://rust-lang.zulipchat.com/#narrow/stream/326414-t-infra.2Fbootstrap/topic/Why.20is.20cargo.20always.20checked.20out.3F
2 parents 42add88 + 3457ecc commit 29555f5

File tree

6 files changed

+32
-39
lines changed

6 files changed

+32
-39
lines changed

src/bootstrap/src/core/build_steps/doc.rs

+18-24
Original file line numberDiff line numberDiff line change
@@ -888,12 +888,11 @@ impl Step for Rustc {
888888
macro_rules! tool_doc {
889889
(
890890
$tool: ident,
891-
$should_run: literal,
892891
$path: literal,
893892
$(rustc_tool = $rustc_tool:literal, )?
894-
$(in_tree = $in_tree:literal ,)?
895893
$(is_library = $is_library:expr,)?
896894
$(crates = $crates:expr)?
895+
$(, submodule $(= $submodule:literal)? )?
897896
) => {
898897
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
899898
pub struct $tool {
@@ -907,7 +906,7 @@ macro_rules! tool_doc {
907906

908907
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
909908
let builder = run.builder;
910-
run.crate_or_deps($should_run).default_condition(builder.config.compiler_docs)
909+
run.path($path).default_condition(builder.config.compiler_docs)
911910
}
912911

913912
fn make_run(run: RunConfig<'_>) {
@@ -921,6 +920,15 @@ macro_rules! tool_doc {
921920
/// we do not merge it with the other documentation from std, test and
922921
/// proc_macros. This is largely just a wrapper around `cargo doc`.
923922
fn run(self, builder: &Builder<'_>) {
923+
let source_type = SourceType::InTree;
924+
$(
925+
let _ = source_type; // silence the "unused variable" warning
926+
let source_type = SourceType::Submodule;
927+
928+
let path = Path::new(submodule_helper!( $path, submodule $( = $submodule )? ));
929+
builder.update_submodule(&path);
930+
)?
931+
924932
let stage = builder.top_stage;
925933
let target = self.target;
926934

@@ -941,12 +949,6 @@ macro_rules! tool_doc {
941949
builder.ensure(compile::Rustc::new(compiler, target));
942950
}
943951

944-
let source_type = if true $(&& $in_tree)? {
945-
SourceType::InTree
946-
} else {
947-
SourceType::Submodule
948-
};
949-
950952
// Build cargo command.
951953
let mut cargo = prepare_tool_cargo(
952954
builder,
@@ -1008,21 +1010,14 @@ macro_rules! tool_doc {
10081010
}
10091011
}
10101012

1011-
tool_doc!(Rustdoc, "rustdoc-tool", "src/tools/rustdoc", crates = ["rustdoc", "rustdoc-json-types"]);
1012-
tool_doc!(
1013-
Rustfmt,
1014-
"rustfmt-nightly",
1015-
"src/tools/rustfmt",
1016-
crates = ["rustfmt-nightly", "rustfmt-config_proc_macro"]
1017-
);
1018-
tool_doc!(Clippy, "clippy", "src/tools/clippy", crates = ["clippy_config", "clippy_utils"]);
1019-
tool_doc!(Miri, "miri", "src/tools/miri", crates = ["miri"]);
1013+
tool_doc!(Rustdoc, "src/tools/rustdoc", crates = ["rustdoc", "rustdoc-json-types"]);
1014+
tool_doc!(Rustfmt, "src/tools/rustfmt", crates = ["rustfmt-nightly", "rustfmt-config_proc_macro"]);
1015+
tool_doc!(Clippy, "src/tools/clippy", crates = ["clippy_config", "clippy_utils"]);
1016+
tool_doc!(Miri, "src/tools/miri", crates = ["miri"]);
10201017
tool_doc!(
10211018
Cargo,
1022-
"cargo",
10231019
"src/tools/cargo",
10241020
rustc_tool = false,
1025-
in_tree = false,
10261021
crates = [
10271022
"cargo",
10281023
"cargo-credential",
@@ -1034,20 +1029,19 @@ tool_doc!(
10341029
"crates-io",
10351030
"mdman",
10361031
"rustfix",
1037-
]
1032+
],
1033+
submodule = "src/tools/cargo"
10381034
);
1039-
tool_doc!(Tidy, "tidy", "src/tools/tidy", rustc_tool = false, crates = ["tidy"]);
1035+
tool_doc!(Tidy, "src/tools/tidy", rustc_tool = false, crates = ["tidy"]);
10401036
tool_doc!(
10411037
Bootstrap,
1042-
"bootstrap",
10431038
"src/bootstrap",
10441039
rustc_tool = false,
10451040
is_library = true,
10461041
crates = ["bootstrap"]
10471042
);
10481043
tool_doc!(
10491044
RunMakeSupport,
1050-
"run_make_support",
10511045
"src/tools/run-make-support",
10521046
rustc_tool = false,
10531047
is_library = true,

src/bootstrap/src/core/build_steps/test.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2983,6 +2983,9 @@ impl Step for Bootstrap {
29832983
let compiler = builder.compiler(0, host);
29842984
let _guard = builder.msg(Kind::Test, 0, "bootstrap", host, host);
29852985

2986+
// Some tests require cargo submodule to be present.
2987+
builder.build.update_submodule(Path::new("src/tools/cargo"));
2988+
29862989
let mut check_bootstrap = Command::new(builder.python());
29872990
check_bootstrap
29882991
.args(["-m", "unittest", "bootstrap_test.py"])

src/bootstrap/src/core/build_steps/tool.rs

+2
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,8 @@ impl Step for Cargo {
656656
}
657657

658658
fn run(self, builder: &Builder<'_>) -> PathBuf {
659+
builder.build.update_submodule(Path::new("src/tools/cargo"));
660+
659661
builder.ensure(ToolBuild {
660662
compiler: self.compiler,
661663
target: self.target,

src/bootstrap/src/core/build_steps/vendor.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
2-
use std::path::PathBuf;
2+
use std::path::{Path, PathBuf};
33
use std::process::Command;
44

55
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
@@ -34,6 +34,9 @@ impl Step for Vendor {
3434
cmd.arg("--versioned-dirs");
3535
}
3636

37+
// cargo submodule must be present for `x vendor` to work.
38+
builder.build.update_submodule(Path::new("src/tools/cargo"));
39+
3740
// Sync these paths by default.
3841
for p in [
3942
"src/tools/cargo/Cargo.toml",

src/bootstrap/src/core/metadata.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ pub fn build(build: &mut Build) {
6767

6868
/// Invokes `cargo metadata` to get package metadata of each workspace member.
6969
///
70-
/// Note that `src/tools/cargo` is no longer a workspace member but we still
71-
/// treat it as one here, by invoking an additional `cargo metadata` command.
72-
fn workspace_members(build: &Build) -> impl Iterator<Item = Package> {
70+
/// This is used to resolve specific crate paths in `fn should_run` to compile
71+
/// particular crate (e.g., `x build sysroot` to build library/sysroot).
72+
fn workspace_members(build: &Build) -> Vec<Package> {
7373
let collect_metadata = |manifest_path| {
7474
let mut cargo = Command::new(&build.initial_cargo);
7575
cargo
@@ -88,13 +88,5 @@ fn workspace_members(build: &Build) -> impl Iterator<Item = Package> {
8888
};
8989

9090
// Collects `metadata.packages` from all workspaces.
91-
let packages = collect_metadata("Cargo.toml");
92-
let cargo_packages = collect_metadata("src/tools/cargo/Cargo.toml");
93-
let ra_packages = collect_metadata("src/tools/rust-analyzer/Cargo.toml");
94-
let bootstrap_packages = collect_metadata("src/bootstrap/Cargo.toml");
95-
96-
// We only care about the root package from `src/tool/cargo` workspace.
97-
let cargo_package = cargo_packages.into_iter().find(|pkg| pkg.name == "cargo").into_iter();
98-
99-
packages.into_iter().chain(cargo_package).chain(ra_packages).chain(bootstrap_packages)
91+
collect_metadata("Cargo.toml")
10092
}

src/bootstrap/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,7 @@ impl Build {
469469

470470
// Make sure we update these before gathering metadata so we don't get an error about missing
471471
// Cargo.toml files.
472-
let rust_submodules =
473-
["src/tools/cargo", "src/doc/book", "library/backtrace", "library/stdarch"];
472+
let rust_submodules = ["src/doc/book", "library/backtrace", "library/stdarch"];
474473
for s in rust_submodules {
475474
build.update_submodule(Path::new(s));
476475
}

0 commit comments

Comments
 (0)