Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
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
4 changes: 2 additions & 2 deletions src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::core::builder::{
};
use crate::core::config::TargetSelection;
use crate::{Compiler, Mode, Subcommand};
use std::path::{Path, PathBuf};
use std::path::PathBuf;

pub fn cargo_subcommand(kind: Kind) -> &'static str {
match kind {
Expand Down Expand Up @@ -52,7 +52,7 @@ impl Step for Std {
}

fn run(self, builder: &Builder<'_>) {
builder.update_submodule(&Path::new("library").join("stdarch"));
builder.require_and_update_submodule("library/stdarch", None);

let target = self.target;
let compiler = builder.compiler(builder.top_stage, builder.config.build);
Expand Down
4 changes: 1 addition & 3 deletions src/bootstrap/src/core/build_steps/clippy.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Implementation of running clippy on the compiler, standard library and various tools.

use std::path::Path;

use crate::builder::Builder;
use crate::builder::ShouldRun;
use crate::core::builder;
Expand Down Expand Up @@ -127,7 +125,7 @@ impl Step for Std {
}

fn run(self, builder: &Builder<'_>) {
builder.update_submodule(&Path::new("library").join("stdarch"));
builder.require_and_update_submodule("library/stdarch", None);

let target = self.target;
let compiler = builder.compiler(builder.top_stage, builder.config.build);
Expand Down
21 changes: 13 additions & 8 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,14 @@ impl Step for Std {
return;
}

builder.update_submodule(&Path::new("library").join("stdarch"));
builder.require_and_update_submodule("library/stdarch", None);

// Profiler information requires LLVM's compiler-rt
if builder.config.profiler {
builder.update_submodule(Path::new("src/llvm-project"));
builder.require_and_update_submodule(
"src/llvm-project",
Some("The `build.profiler` config option requires compiler-rt sources."),
);
}

let mut target_deps = builder.ensure(StartupObjects { compiler, target });
Expand Down Expand Up @@ -456,13 +459,15 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
// That's probably ok? At least, the difference wasn't enforced before. There's a comment in
// the compiler_builtins build script that makes me nervous, though:
// https://github.com/rust-lang/compiler-builtins/blob/31ee4544dbe47903ce771270d6e3bea8654e9e50/build.rs#L575-L579
builder.update_submodule(&Path::new("src").join("llvm-project"));
builder.require_and_update_submodule(
"src/llvm-project",
Some(
"need LLVM sources available to build `compiler-rt`, but they weren't present; \
consider disabling `optimized-compiler-builtins`",
),
);
let compiler_builtins_root = builder.src.join("src/llvm-project/compiler-rt");
if !compiler_builtins_root.exists() {
panic!(
"need LLVM sources available to build `compiler-rt`, but they weren't present; consider enabling `build.submodules = true` or disabling `optimized-compiler-builtins`"
);
}
assert!(compiler_builtins_root.exists());
// Note that `libprofiler_builtins/build.rs` also computes this so if
// you're changing something here please also change that.
cargo.env("RUST_COMPILER_RT_ROOT", &compiler_builtins_root);
Expand Down
7 changes: 2 additions & 5 deletions src/bootstrap/src/core/build_steps/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ impl Step for Src {
/// Creates the `rust-src` installer component
fn run(self, builder: &Builder<'_>) -> GeneratedTarball {
if !builder.config.dry_run() {
builder.update_submodule(Path::new("src/llvm-project"));
builder.require_and_update_submodule("src/llvm-project", None);
}

let tarball = Tarball::new_targetless(builder, "rust-src");
Expand Down Expand Up @@ -1022,10 +1022,7 @@ impl Step for PlainSourceTarball {
// FIXME: This code looks _very_ similar to what we have in `src/core/build_steps/vendor.rs`
// perhaps it should be removed in favor of making `dist` perform the `vendor` step?

// Ensure we have all submodules from src and other directories checked out.
for submodule in build_helper::util::parse_gitmodules(&builder.src) {
builder.update_submodule(Path::new(submodule));
}
builder.require_and_update_all_submodules();

// Vendor all Cargo dependencies
let mut cmd = command(&builder.initial_cargo);
Expand Down
30 changes: 8 additions & 22 deletions src/bootstrap/src/core/build_steps/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::core::build_steps::tool::{self, prepare_tool_cargo, SourceType, Tool}
use crate::core::builder::{self, crate_description};
use crate::core::builder::{Alias, Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
use crate::core::config::{Config, TargetSelection};
use crate::utils::helpers::{dir_is_empty, symlink_dir, t, up_to_date};
use crate::utils::helpers::{symlink_dir, t, up_to_date};
use crate::Mode;

macro_rules! submodule_helper {
Expand Down Expand Up @@ -53,8 +53,8 @@ macro_rules! book {

fn run(self, builder: &Builder<'_>) {
$(
let path = Path::new(submodule_helper!( $path, submodule $( = $submodule )? ));
builder.update_submodule(&path);
let path = submodule_helper!( $path, submodule $( = $submodule )? );
builder.require_and_update_submodule(path, None);
)?
builder.ensure(RustbookSrc {
target: self.target,
Expand Down Expand Up @@ -217,22 +217,14 @@ impl Step for TheBook {
/// * Index page
/// * Redirect pages
fn run(self, builder: &Builder<'_>) {
let relative_path = Path::new("src").join("doc").join("book");
builder.update_submodule(&relative_path);
builder.require_and_update_submodule("src/doc/book", None);

let compiler = self.compiler;
let target = self.target;

let absolute_path = builder.src.join(&relative_path);
let absolute_path = builder.src.join("src/doc/book");
let redirect_path = absolute_path.join("redirects");
if !absolute_path.exists()
|| !redirect_path.exists()
|| dir_is_empty(&absolute_path)
|| dir_is_empty(&redirect_path)
{
eprintln!("Please checkout submodule: {}", relative_path.display());
crate::exit!(1);
}

// build book
builder.ensure(RustbookSrc {
target,
Expand Down Expand Up @@ -932,8 +924,8 @@ macro_rules! tool_doc {
let _ = source_type; // silence the "unused variable" warning
let source_type = SourceType::Submodule;

let path = Path::new(submodule_helper!( $path, submodule $( = $submodule )? ));
builder.update_submodule(&path);
let path = submodule_helper!( $path, submodule $( = $submodule )? );
builder.require_and_update_submodule(path, None);
)?

let stage = builder.top_stage;
Expand Down Expand Up @@ -1172,12 +1164,6 @@ impl Step for RustcBook {
/// in the "md-doc" directory in the build output directory. Then
/// "rustbook" is used to convert it to HTML.
fn run(self, builder: &Builder<'_>) {
// These submodules are required to be checked out to build rustbook
// because they have Cargo dependencies that are needed.
#[allow(clippy::single_element_loop)] // This will change soon.
for path in ["src/doc/book"] {
builder.update_submodule(Path::new(path));
}
let out_base = builder.md_doc_out(self.target).join("rustc");
t!(fs::create_dir_all(&out_base));
let out_listing = out_base.join("src/lints");
Expand Down
6 changes: 3 additions & 3 deletions src/bootstrap/src/core/build_steps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub fn prebuilt_llvm_config(builder: &Builder<'_>, target: TargetSelection) -> L
}

// Initialize the llvm submodule if not initialized already.
builder.update_submodule(&Path::new("src").join("llvm-project"));
builder.require_and_update_submodule("src/llvm-project", None);

let root = "src/llvm-project/llvm";
let out_dir = builder.llvm_out(target);
Expand Down Expand Up @@ -1197,7 +1197,7 @@ impl Step for CrtBeginEnd {

/// Build crtbegin.o/crtend.o for musl target.
fn run(self, builder: &Builder<'_>) -> Self::Output {
builder.update_submodule(Path::new("src/llvm-project"));
builder.require_and_update_submodule("src/llvm-project", None);

let out_dir = builder.native_dir(self.target).join("crt");

Expand Down Expand Up @@ -1270,7 +1270,7 @@ impl Step for Libunwind {

/// Build libunwind.a
fn run(self, builder: &Builder<'_>) -> Self::Output {
builder.update_submodule(Path::new("src/llvm-project"));
builder.require_and_update_submodule("src/llvm-project", None);

if builder.config.dry_run() {
return PathBuf::new();
Expand Down
6 changes: 3 additions & 3 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2398,8 +2398,8 @@ impl Step for RustcGuide {
}

fn run(self, builder: &Builder<'_>) {
let relative_path = Path::new("src").join("doc").join("rustc-dev-guide");
builder.update_submodule(&relative_path);
let relative_path = "src/doc/rustc-dev-guide";
builder.require_and_update_submodule(relative_path, None);

let src = builder.src.join(relative_path);
let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook).delay_failure();
Expand Down Expand Up @@ -3009,7 +3009,7 @@ impl Step for Bootstrap {
let _guard = builder.msg(Kind::Test, 0, "bootstrap", host, host);

// Some tests require cargo submodule to be present.
builder.build.update_submodule(Path::new("src/tools/cargo"));
builder.build.require_and_update_submodule("src/tools/cargo", None);

let mut check_bootstrap = command(builder.python());
check_bootstrap
Expand Down
22 changes: 15 additions & 7 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::env;
use std::fs;
use std::path::{Path, PathBuf};
use std::path::PathBuf;

use crate::core::build_steps::compile;
use crate::core::build_steps::toolstate::ToolState;
Expand Down Expand Up @@ -241,6 +241,7 @@ macro_rules! bootstrap_tool {
$(,is_external_tool = $external:expr)*
$(,is_unstable_tool = $unstable:expr)*
$(,allow_features = $allow_features:expr)?
$(,submodules = $submodules:expr)?
;
)+) => {
#[derive(PartialEq, Eq, Clone)]
Expand Down Expand Up @@ -287,6 +288,11 @@ macro_rules! bootstrap_tool {
}

fn run(self, builder: &Builder<'_>) -> PathBuf {
$(
for submodule in $submodules {
builder.require_and_update_submodule(submodule, None);
}
)*
builder.ensure(ToolBuild {
compiler: self.compiler,
target: self.target,
Expand Down Expand Up @@ -314,7 +320,7 @@ macro_rules! bootstrap_tool {
}

bootstrap_tool!(
Rustbook, "src/tools/rustbook", "rustbook";
Rustbook, "src/tools/rustbook", "rustbook", submodules = SUBMODULES_FOR_RUSTBOOK;
UnstableBookGen, "src/tools/unstable-book-gen", "unstable-book-gen";
Tidy, "src/tools/tidy", "tidy";
Linkchecker, "src/tools/linkchecker", "linkchecker";
Expand All @@ -340,6 +346,10 @@ bootstrap_tool!(
WasmComponentLd, "src/tools/wasm-component-ld", "wasm-component-ld", is_unstable_tool = true, allow_features = "min_specialization";
);

/// These are the submodules that are required for rustbook to work due to
/// depending on mdbook plugins.
pub static SUBMODULES_FOR_RUSTBOOK: &[&str] = &["src/doc/book"];

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct OptimizedDist {
pub compiler: Compiler,
Expand All @@ -363,7 +373,7 @@ impl Step for OptimizedDist {
fn run(self, builder: &Builder<'_>) -> PathBuf {
// We need to ensure the rustc-perf submodule is initialized when building opt-dist since
// the tool requires it to be in place to run.
builder.update_submodule(Path::new("src/tools/rustc-perf"));
builder.require_and_update_submodule("src/tools/rustc-perf", None);

builder.ensure(ToolBuild {
compiler: self.compiler,
Expand Down Expand Up @@ -404,7 +414,7 @@ impl Step for RustcPerf {

fn run(self, builder: &Builder<'_>) -> PathBuf {
// We need to ensure the rustc-perf submodule is initialized.
builder.update_submodule(Path::new("src/tools/rustc-perf"));
builder.require_and_update_submodule("src/tools/rustc-perf", None);

let tool = ToolBuild {
compiler: self.compiler,
Expand Down Expand Up @@ -705,7 +715,7 @@ impl Step for Cargo {
}

fn run(self, builder: &Builder<'_>) -> PathBuf {
builder.build.update_submodule(Path::new("src/tools/cargo"));
builder.build.require_and_update_submodule("src/tools/cargo", None);

builder.ensure(ToolBuild {
compiler: self.compiler,
Expand Down Expand Up @@ -1087,8 +1097,6 @@ macro_rules! tool_extended {

// NOTE: tools need to be also added to `Builder::get_step_descriptions` in `builder.rs`
// to make `./x.py build <tool>` work.
// NOTE: Most submodule updates for tools are handled by bootstrap.py, since they're needed just to
// invoke Cargo to build bootstrap. See the comment there for more details.
tool_extended!((self, builder),
Cargofmt, "src/tools/rustfmt", "cargo-fmt", stable=true;
CargoClippy, "src/tools/clippy", "cargo-clippy", stable=true;
Expand Down
6 changes: 3 additions & 3 deletions src/bootstrap/src/core/build_steps/vendor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
use crate::utils::exec::command;
use std::path::{Path, PathBuf};
use std::path::PathBuf;

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub(crate) struct Vendor {
Expand Down Expand Up @@ -35,8 +35,8 @@ impl Step for Vendor {
}

// These submodules must be present for `x vendor` to work.
for path in ["src/tools/cargo", "src/doc/book"] {
builder.build.update_submodule(Path::new(path));
for submodule in ["src/tools/cargo", "src/doc/book"] {
builder.build.require_and_update_submodule(submodule, None);
}

// Sync these paths by default.
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn configure_with_args(cmd: &[String], host: &[&str], target: &[&str]) -> Config
rust_codegen_backends: vec![],
..Config::parse(&["check".to_owned()])
});
submodule_build.update_submodule(Path::new("src/doc/book"));
submodule_build.require_and_update_submodule("src/doc/book", None);
config.submodules = Some(false);

config.ninja_in_file = false;
Expand Down
7 changes: 5 additions & 2 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2404,8 +2404,11 @@ impl Config {
.unwrap_or_else(|| SplitDebuginfo::default_for_platform(target))
}

pub fn submodules(&self, rust_info: &GitInfo) -> bool {
self.submodules.unwrap_or(rust_info.is_managed_git_subrepository())
/// Returns whether or not submodules should be managed by bootstrap.
pub fn submodules(&self) -> bool {
// If not specified in config, the default is to only manage
// submodules if we're currently inside a git repository.
self.submodules.unwrap_or(self.rust_info.is_managed_git_subrepository())
}

pub fn codegen_backends(&self, target: TargetSelection) -> &[String] {
Expand Down
Loading