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

Update the reference #128215

Merged
merged 17 commits into from
Jul 28, 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
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; \
Kobzol marked this conversation as resolved.
Show resolved Hide resolved
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
24 changes: 8 additions & 16 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
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);
Kobzol marked this conversation as resolved.
Show resolved Hide resolved

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
10 changes: 5 additions & 5 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 @@ -290,7 +290,7 @@ macro_rules! bootstrap_tool {
fn run(self, builder: &Builder<'_>) -> PathBuf {
$(
for submodule in $submodules {
builder.update_submodule(Path::new(submodule));
builder.require_and_update_submodule(submodule, None);
}
)*
builder.ensure(ToolBuild {
Expand Down Expand Up @@ -373,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 @@ -414,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 @@ -715,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
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
47 changes: 46 additions & 1 deletion src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,13 @@ impl Build {
/// Given a path to the directory of a submodule, update it.
///
/// `relative_path` should be relative to the root of the git repository, not an absolute path.
pub(crate) fn update_submodule(&self, relative_path: &Path) {
///
/// This *does not* update the submodule if `config.toml` explicitly says
/// not to, or if we're not in a git repository (like a plain source
/// tarball). Typically [`Build::require_and_update_submodule`] should be
/// used instead to provide a nice error to the user if the submodule is
/// missing.
fn update_submodule(&self, relative_path: &Path) {
Kobzol marked this conversation as resolved.
Show resolved Hide resolved
if !self.config.submodules() {
return;
}
Expand Down Expand Up @@ -579,6 +585,45 @@ impl Build {
}
}

/// Updates a submodule, and exits with a failure if submodule management
/// is disabled and the submodule does not exist.
///
/// The given `err_hint` will be shown to the user if the submodule is not
/// checked out.
pub fn require_and_update_submodule(&self, submodule: &str, err_hint: Option<&str>) {
Kobzol marked this conversation as resolved.
Show resolved Hide resolved
Kobzol marked this conversation as resolved.
Show resolved Hide resolved
// When testing bootstrap itself, it is much faster to ignore
// submodules. Almost all Steps work fine without their submodules.
if cfg!(test) && !self.config.submodules() {
return;
}
let relative_path = Path::new(submodule);
self.update_submodule(relative_path);
let absolute_path = self.config.src.join(relative_path);
if dir_is_empty(&absolute_path) {
let maybe_enable = if !self.config.submodules()
&& self.config.rust_info.is_managed_git_subrepository()
{
"\nConsider setting `build.submodules = true` or manually initializing the submodules."
} else {
""
};
let err_hint = err_hint.map_or_else(String::new, |e| format!("\n{e}"));
Kobzol marked this conversation as resolved.
Show resolved Hide resolved
eprintln!(
"submodule {submodule} does not appear to be checked out, \
but it is required for this step{maybe_enable}{err_hint}"
);
exit!(1);
}
}

/// Updates all submodules, and exits with an error if submodule
/// management is disabled and the submodule does not exist.
pub fn require_and_update_all_submodules(&self) {
for submodule in build_helper::util::parse_gitmodules(&self.src) {
self.require_and_update_submodule(submodule, None);
}
}

/// If any submodule has been initialized already, sync it unconditionally.
/// This avoids contributors checking in a submodule change by accident.
fn update_existing_submodules(&self) {
Expand Down