Skip to content

Commit 458fdc4

Browse files
authored
Unrolled build for rust-lang#128215
Rollup merge of rust-lang#128215 - ehuss:update-reference, r=Kobzol Update the reference This updates the reference to use the new mdbook-spec preprocessor, which is a Cargo library inside the reference submodule. Note that this PR contains a bunch of bootstrap cleanup commits to assist with making sure the submodules are working correctly. All of the cleanup PRs should have a description in their commit. I'd be happy to move those to a separate PR if that makes review easier. The main changes for the reference are: - Move the `doc::Reference` bootstrap step out of the generic macro into a custom step. - This step needs to build rustdoc because the new mdbook-spec plugin uses rustdoc for generating links. - PATH is updated so that the rustdoc binary can be found. - rustbook now includes the mdbook-spec plugin as a dependency. - rustbook enables the mdbook-spec preprocessor. I did a bunch of testing with the various commands and setups, such as: - `submodules=true` and `submodules=false` - having all submodules deinitialized - not in a git repository However, there are probably thousands of different permutations of different commands, settings, and environments, so there is a chance I'm missing something.
2 parents 1b51d80 + 1c98b8f commit 458fdc4

File tree

17 files changed

+255
-94
lines changed

17 files changed

+255
-94
lines changed

src/bootstrap/src/core/build_steps/check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::core::builder::{
99
};
1010
use crate::core::config::TargetSelection;
1111
use crate::{Compiler, Mode, Subcommand};
12-
use std::path::{Path, PathBuf};
12+
use std::path::PathBuf;
1313

1414
pub fn cargo_subcommand(kind: Kind) -> &'static str {
1515
match kind {
@@ -52,7 +52,7 @@ impl Step for Std {
5252
}
5353

5454
fn run(self, builder: &Builder<'_>) {
55-
builder.update_submodule(&Path::new("library").join("stdarch"));
55+
builder.require_submodule("library/stdarch", None);
5656

5757
let target = self.target;
5858
let compiler = builder.compiler(builder.top_stage, builder.config.build);

src/bootstrap/src/core/build_steps/clippy.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Implementation of running clippy on the compiler, standard library and various tools.
22
3-
use std::path::Path;
4-
53
use crate::builder::Builder;
64
use crate::builder::ShouldRun;
75
use crate::core::builder;
@@ -127,7 +125,7 @@ impl Step for Std {
127125
}
128126

129127
fn run(self, builder: &Builder<'_>) {
130-
builder.update_submodule(&Path::new("library").join("stdarch"));
128+
builder.require_submodule("library/stdarch", None);
131129

132130
let target = self.target;
133131
let compiler = builder.compiler(builder.top_stage, builder.config.build);

src/bootstrap/src/core/build_steps/compile.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,16 @@ impl Step for Std {
182182
return;
183183
}
184184

185-
builder.update_submodule(&Path::new("library").join("stdarch"));
185+
builder.require_submodule("library/stdarch", None);
186186

187187
// Profiler information requires LLVM's compiler-rt
188188
if builder.config.profiler {
189-
builder.update_submodule(Path::new("src/llvm-project"));
189+
builder.require_submodule(
190+
"src/llvm-project",
191+
Some(
192+
"The `build.profiler` config option requires `compiler-rt` sources from LLVM.",
193+
),
194+
);
190195
}
191196

192197
let mut target_deps = builder.ensure(StartupObjects { compiler, target });
@@ -456,13 +461,15 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
456461
// That's probably ok? At least, the difference wasn't enforced before. There's a comment in
457462
// the compiler_builtins build script that makes me nervous, though:
458463
// https://github.com/rust-lang/compiler-builtins/blob/31ee4544dbe47903ce771270d6e3bea8654e9e50/build.rs#L575-L579
459-
builder.update_submodule(&Path::new("src").join("llvm-project"));
464+
builder.require_submodule(
465+
"src/llvm-project",
466+
Some(
467+
"The `build.optimized-compiler-builtins` config option \
468+
requires `compiler-rt` sources from LLVM.",
469+
),
470+
);
460471
let compiler_builtins_root = builder.src.join("src/llvm-project/compiler-rt");
461-
if !compiler_builtins_root.exists() {
462-
panic!(
463-
"need LLVM sources available to build `compiler-rt`, but they weren't present; consider enabling `build.submodules = true` or disabling `optimized-compiler-builtins`"
464-
);
465-
}
472+
assert!(compiler_builtins_root.exists());
466473
// Note that `libprofiler_builtins/build.rs` also computes this so if
467474
// you're changing something here please also change that.
468475
cargo.env("RUST_COMPILER_RT_ROOT", &compiler_builtins_root);

src/bootstrap/src/core/build_steps/dist.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ impl Step for Src {
907907
/// Creates the `rust-src` installer component
908908
fn run(self, builder: &Builder<'_>) -> GeneratedTarball {
909909
if !builder.config.dry_run() {
910-
builder.update_submodule(Path::new("src/llvm-project"));
910+
builder.require_submodule("src/llvm-project", None);
911911
}
912912

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

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

10301027
// Vendor all Cargo dependencies
10311028
let mut cmd = command(&builder.initial_cargo);

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

+70-31
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
1010
use std::io::{self, Write};
1111
use std::path::{Path, PathBuf};
12-
use std::{fs, mem};
12+
use std::{env, fs, mem};
1313

1414
use crate::core::build_steps::compile;
1515
use crate::core::build_steps::tool::{self, prepare_tool_cargo, SourceType, Tool};
1616
use crate::core::builder::{self, crate_description};
1717
use crate::core::builder::{Alias, Builder, Compiler, Kind, RunConfig, ShouldRun, Step};
1818
use crate::core::config::{Config, TargetSelection};
19-
use crate::utils::helpers::{dir_is_empty, symlink_dir, t, up_to_date};
19+
use crate::utils::helpers::{symlink_dir, t, up_to_date};
2020
use crate::Mode;
2121

2222
macro_rules! submodule_helper {
@@ -53,15 +53,16 @@ macro_rules! book {
5353

5454
fn run(self, builder: &Builder<'_>) {
5555
$(
56-
let path = Path::new(submodule_helper!( $path, submodule $( = $submodule )? ));
57-
builder.update_submodule(&path);
56+
let path = submodule_helper!( $path, submodule $( = $submodule )? );
57+
builder.require_submodule(path, None);
5858
)?
5959
builder.ensure(RustbookSrc {
6060
target: self.target,
6161
name: $book_name.to_owned(),
6262
src: builder.src.join($path),
6363
parent: Some(self),
6464
languages: $lang.into(),
65+
rustdoc: None,
6566
})
6667
}
6768
}
@@ -80,7 +81,6 @@ book!(
8081
EditionGuide, "src/doc/edition-guide", "edition-guide", &[], submodule;
8182
EmbeddedBook, "src/doc/embedded-book", "embedded-book", &[], submodule;
8283
Nomicon, "src/doc/nomicon", "nomicon", &[], submodule;
83-
Reference, "src/doc/reference", "reference", &[], submodule;
8484
RustByExample, "src/doc/rust-by-example", "rust-by-example", &["ja"], submodule;
8585
RustdocBook, "src/doc/rustdoc", "rustdoc", &[];
8686
StyleGuide, "src/doc/style-guide", "style-guide", &[];
@@ -112,6 +112,7 @@ impl Step for UnstableBook {
112112
src: builder.md_doc_out(self.target).join("unstable-book"),
113113
parent: Some(self),
114114
languages: vec![],
115+
rustdoc: None,
115116
})
116117
}
117118
}
@@ -123,6 +124,7 @@ struct RustbookSrc<P: Step> {
123124
src: PathBuf,
124125
parent: Option<P>,
125126
languages: Vec<&'static str>,
127+
rustdoc: Option<PathBuf>,
126128
}
127129

128130
impl<P: Step> Step for RustbookSrc<P> {
@@ -153,13 +155,18 @@ impl<P: Step> Step for RustbookSrc<P> {
153155
builder.info(&format!("Rustbook ({target}) - {name}"));
154156
let _ = fs::remove_dir_all(&out);
155157

156-
builder
157-
.tool_cmd(Tool::Rustbook)
158-
.arg("build")
159-
.arg(&src)
160-
.arg("-d")
161-
.arg(&out)
162-
.run(builder);
158+
let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
159+
if let Some(mut rustdoc) = self.rustdoc {
160+
rustdoc.pop();
161+
let old_path = env::var_os("PATH").unwrap_or_default();
162+
let new_path =
163+
env::join_paths(std::iter::once(rustdoc).chain(env::split_paths(&old_path)))
164+
.expect("could not add rustdoc to PATH");
165+
166+
rustbook_cmd.env("PATH", new_path);
167+
}
168+
169+
rustbook_cmd.arg("build").arg(&src).arg("-d").arg(&out).run(builder);
163170

164171
for lang in &self.languages {
165172
let out = out.join(lang);
@@ -217,29 +224,22 @@ impl Step for TheBook {
217224
/// * Index page
218225
/// * Redirect pages
219226
fn run(self, builder: &Builder<'_>) {
220-
let relative_path = Path::new("src").join("doc").join("book");
221-
builder.update_submodule(&relative_path);
227+
builder.require_submodule("src/doc/book", None);
222228

223229
let compiler = self.compiler;
224230
let target = self.target;
225231

226-
let absolute_path = builder.src.join(&relative_path);
232+
let absolute_path = builder.src.join("src/doc/book");
227233
let redirect_path = absolute_path.join("redirects");
228-
if !absolute_path.exists()
229-
|| !redirect_path.exists()
230-
|| dir_is_empty(&absolute_path)
231-
|| dir_is_empty(&redirect_path)
232-
{
233-
eprintln!("Please checkout submodule: {}", relative_path.display());
234-
crate::exit!(1);
235-
}
234+
236235
// build book
237236
builder.ensure(RustbookSrc {
238237
target,
239238
name: "book".to_owned(),
240239
src: absolute_path.clone(),
241240
parent: Some(self),
242241
languages: vec![],
242+
rustdoc: None,
243243
});
244244

245245
// building older edition redirects
@@ -252,6 +252,7 @@ impl Step for TheBook {
252252
// treat the other editions as not having a parent.
253253
parent: Option::<Self>::None,
254254
languages: vec![],
255+
rustdoc: None,
255256
});
256257
}
257258

@@ -932,8 +933,8 @@ macro_rules! tool_doc {
932933
let _ = source_type; // silence the "unused variable" warning
933934
let source_type = SourceType::Submodule;
934935

935-
let path = Path::new(submodule_helper!( $path, submodule $( = $submodule )? ));
936-
builder.update_submodule(&path);
936+
let path = submodule_helper!( $path, submodule $( = $submodule )? );
937+
builder.require_submodule(path, None);
937938
)?
938939

939940
let stage = builder.top_stage;
@@ -1172,12 +1173,6 @@ impl Step for RustcBook {
11721173
/// in the "md-doc" directory in the build output directory. Then
11731174
/// "rustbook" is used to convert it to HTML.
11741175
fn run(self, builder: &Builder<'_>) {
1175-
// These submodules are required to be checked out to build rustbook
1176-
// because they have Cargo dependencies that are needed.
1177-
#[allow(clippy::single_element_loop)] // This will change soon.
1178-
for path in ["src/doc/book"] {
1179-
builder.update_submodule(Path::new(path));
1180-
}
11811176
let out_base = builder.md_doc_out(self.target).join("rustc");
11821177
t!(fs::create_dir_all(&out_base));
11831178
let out_listing = out_base.join("src/lints");
@@ -1228,6 +1223,50 @@ impl Step for RustcBook {
12281223
src: out_base,
12291224
parent: Some(self),
12301225
languages: vec![],
1226+
rustdoc: None,
1227+
});
1228+
}
1229+
}
1230+
1231+
#[derive(Ord, PartialOrd, Debug, Clone, Hash, PartialEq, Eq)]
1232+
pub struct Reference {
1233+
pub compiler: Compiler,
1234+
pub target: TargetSelection,
1235+
}
1236+
1237+
impl Step for Reference {
1238+
type Output = ();
1239+
const DEFAULT: bool = true;
1240+
1241+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1242+
let builder = run.builder;
1243+
run.path("src/doc/reference").default_condition(builder.config.docs)
1244+
}
1245+
1246+
fn make_run(run: RunConfig<'_>) {
1247+
run.builder.ensure(Reference {
1248+
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
1249+
target: run.target,
1250+
});
1251+
}
1252+
1253+
/// Builds the reference book.
1254+
fn run(self, builder: &Builder<'_>) {
1255+
builder.require_submodule("src/doc/reference", None);
1256+
1257+
// This is needed for generating links to the standard library using
1258+
// the mdbook-spec plugin.
1259+
builder.ensure(compile::Std::new(self.compiler, builder.config.build));
1260+
let rustdoc = builder.rustdoc(self.compiler);
1261+
1262+
// Run rustbook/mdbook to generate the HTML pages.
1263+
builder.ensure(RustbookSrc {
1264+
target: self.target,
1265+
name: "reference".to_owned(),
1266+
src: builder.src.join("src/doc/reference"),
1267+
parent: Some(self),
1268+
languages: vec![],
1269+
rustdoc: Some(rustdoc),
12311270
});
12321271
}
12331272
}

src/bootstrap/src/core/build_steps/llvm.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl LdFlags {
8989
/// if not).
9090
pub fn prebuilt_llvm_config(builder: &Builder<'_>, target: TargetSelection) -> LlvmBuildStatus {
9191
// If we have llvm submodule initialized already, sync it.
92-
builder.update_existing_submodule(&Path::new("src").join("llvm-project"));
92+
builder.update_existing_submodule("src/llvm-project");
9393

9494
builder.config.maybe_download_ci_llvm();
9595

@@ -110,7 +110,8 @@ pub fn prebuilt_llvm_config(builder: &Builder<'_>, target: TargetSelection) -> L
110110
}
111111

112112
// Initialize the llvm submodule if not initialized already.
113-
builder.update_submodule(&Path::new("src").join("llvm-project"));
113+
// If submodules are disabled, this does nothing.
114+
builder.update_submodule("src/llvm-project");
114115

115116
let root = "src/llvm-project/llvm";
116117
let out_dir = builder.llvm_out(target);
@@ -1197,7 +1198,10 @@ impl Step for CrtBeginEnd {
11971198

11981199
/// Build crtbegin.o/crtend.o for musl target.
11991200
fn run(self, builder: &Builder<'_>) -> Self::Output {
1200-
builder.update_submodule(Path::new("src/llvm-project"));
1201+
builder.require_submodule(
1202+
"src/llvm-project",
1203+
Some("The LLVM sources are required for the CRT from `compiler-rt`."),
1204+
);
12011205

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

@@ -1270,7 +1274,10 @@ impl Step for Libunwind {
12701274

12711275
/// Build libunwind.a
12721276
fn run(self, builder: &Builder<'_>) -> Self::Output {
1273-
builder.update_submodule(Path::new("src/llvm-project"));
1277+
builder.require_submodule(
1278+
"src/llvm-project",
1279+
Some("The LLVM sources are required for libunwind."),
1280+
);
12741281

12751282
if builder.config.dry_run() {
12761283
return PathBuf::new();

0 commit comments

Comments
 (0)