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
72 changes: 63 additions & 9 deletions src/bootstrap/src/core/build_steps/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use std::io::{self, Write};
use std::path::{Path, PathBuf};
use std::{fs, mem};
use std::{env, fs, mem};

use crate::core::build_steps::compile;
use crate::core::build_steps::tool::{self, prepare_tool_cargo, SourceType, Tool};
Expand Down Expand Up @@ -62,6 +62,7 @@ macro_rules! book {
src: builder.src.join($path),
parent: Some(self),
languages: $lang.into(),
rustdoc: None,
})
}
}
Expand All @@ -80,7 +81,6 @@ book!(
EditionGuide, "src/doc/edition-guide", "edition-guide", &[], submodule;
EmbeddedBook, "src/doc/embedded-book", "embedded-book", &[], submodule;
Nomicon, "src/doc/nomicon", "nomicon", &[], submodule;
Reference, "src/doc/reference", "reference", &[], submodule;
RustByExample, "src/doc/rust-by-example", "rust-by-example", &["ja"], submodule;
RustdocBook, "src/doc/rustdoc", "rustdoc", &[];
StyleGuide, "src/doc/style-guide", "style-guide", &[];
Expand Down Expand Up @@ -112,6 +112,7 @@ impl Step for UnstableBook {
src: builder.md_doc_out(self.target).join("unstable-book"),
parent: Some(self),
languages: vec![],
rustdoc: None,
})
}
}
Expand All @@ -123,6 +124,7 @@ struct RustbookSrc<P: Step> {
src: PathBuf,
parent: Option<P>,
languages: Vec<&'static str>,
rustdoc: Option<PathBuf>,
}

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

builder
.tool_cmd(Tool::Rustbook)
.arg("build")
.arg(&src)
.arg("-d")
.arg(&out)
.run(builder);
let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook);
if let Some(mut rustdoc) = self.rustdoc {
rustdoc.pop();
let old_path = env::var_os("PATH").unwrap_or_default();
let new_path =
env::join_paths(std::iter::once(rustdoc).chain(env::split_paths(&old_path)))
.expect("could not add rustdoc to PATH");

rustbook_cmd.env("PATH", new_path);
}

rustbook_cmd.arg("build").arg(&src).arg("-d").arg(&out).run(builder);

for lang in &self.languages {
let out = out.join(lang);
Expand Down Expand Up @@ -232,6 +239,7 @@ impl Step for TheBook {
src: absolute_path.clone(),
parent: Some(self),
languages: vec![],
rustdoc: None,
});

// building older edition redirects
Expand All @@ -244,6 +252,7 @@ impl Step for TheBook {
// treat the other editions as not having a parent.
parent: Option::<Self>::None,
languages: vec![],
rustdoc: None,
});
}

Expand Down Expand Up @@ -1214,6 +1223,51 @@ impl Step for RustcBook {
src: out_base,
parent: Some(self),
languages: vec![],
rustdoc: None,
});
}
}

#[derive(Ord, PartialOrd, Debug, Clone, Hash, PartialEq, Eq)]
pub struct Reference {
pub compiler: Compiler,
pub target: TargetSelection,
}

impl Step for Reference {
type Output = ();
const DEFAULT: bool = true;
const ONLY_HOSTS: bool = true;
Kobzol marked this conversation as resolved.
Show resolved Hide resolved

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
let builder = run.builder;
run.path("src/doc/reference").default_condition(builder.config.docs)
}

fn make_run(run: RunConfig<'_>) {
run.builder.ensure(Reference {
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
target: run.target,
});
}

/// Builds the reference book.
fn run(self, builder: &Builder<'_>) {
builder.require_and_update_submodule("src/doc/reference", None);

// This is needed for generating links to the standard library using
// the mdbook-spec plugin.
builder.ensure(compile::Std::new(self.compiler, builder.config.build));
let rustdoc = builder.rustdoc(self.compiler);

// Run rustbook/mdbook to generate the HTML pages.
builder.ensure(RustbookSrc {
target: self.target,
name: "reference".to_owned(),
src: builder.src.join("src/doc/reference"),
parent: Some(self),
languages: vec![],
rustdoc: Some(rustdoc),
});
}
}
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ bootstrap_tool!(

/// 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"];
pub static SUBMODULES_FOR_RUSTBOOK: &[&str] = &["src/doc/book", "src/doc/reference"];

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct OptimizedDist {
Expand Down
3 changes: 2 additions & 1 deletion src/bootstrap/src/core/build_steps/vendor.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::core::build_steps::tool::SUBMODULES_FOR_RUSTBOOK;
use crate::core::builder::{Builder, RunConfig, ShouldRun, Step};
use crate::utils::exec::command;
use std::path::PathBuf;
Expand Down Expand Up @@ -35,7 +36,7 @@ impl Step for Vendor {
}

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

Expand Down
21 changes: 21 additions & 0 deletions src/tools/rustbook/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,20 @@ dependencies = [
"textwrap",
]

[[package]]
name = "mdbook-spec"
version = "0.1.2"
dependencies = [
"anyhow",
"mdbook",
"once_cell",
"pathdiff",
"regex",
"semver",
"serde_json",
"tempfile",
]

[[package]]
name = "mdbook-trpl-listing"
version = "0.1.0"
Expand Down Expand Up @@ -794,6 +808,12 @@ dependencies = [
"windows-targets 0.52.6",
]

[[package]]
name = "pathdiff"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd"

[[package]]
name = "percent-encoding"
version = "2.3.1"
Expand Down Expand Up @@ -1079,6 +1099,7 @@ dependencies = [
"env_logger",
"mdbook",
"mdbook-i18n-helpers",
"mdbook-spec",
"mdbook-trpl-listing",
"mdbook-trpl-note",
]
Expand Down
1 change: 1 addition & 0 deletions src/tools/rustbook/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ env_logger = "0.11"
mdbook-trpl-listing = { path = "../../doc/book/packages/mdbook-trpl-listing" }
mdbook-trpl-note = { path = "../../doc/book/packages/mdbook-trpl-note" }
mdbook-i18n-helpers = "0.3.3"
mdbook-spec = { path = "../../doc/reference/mdbook-spec"}

[dependencies.mdbook]
version = "0.4.37"
Expand Down
12 changes: 12 additions & 0 deletions src/tools/rustbook/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use mdbook::errors::Result as Result3;
use mdbook::MDBook;
use mdbook_i18n_helpers::preprocessors::Gettext;

use mdbook_spec::Spec;
use mdbook_trpl_listing::TrplListing;
use mdbook_trpl_note::TrplNote;

Expand Down Expand Up @@ -83,6 +84,13 @@ pub fn build(args: &ArgMatches) -> Result3<()> {
book.config.build.build_dir = dest_dir.into();
}

// NOTE: Replacing preprocessors using this technique causes error
// messages to be displayed when the original preprocessor doesn't work
// (but it otherwise succeeds).
//
// This should probably be fixed in mdbook to remove the existing
// preprocessor, or this should modify the config and use
// MDBook::load_with_config.
if book.config.get_preprocessor("trpl-note").is_some() {
book.with_preprocessor(TrplNote);
}
Expand All @@ -91,6 +99,10 @@ pub fn build(args: &ArgMatches) -> Result3<()> {
book.with_preprocessor(TrplListing);
}

if book.config.get_preprocessor("spec").is_some() {
book.with_preprocessor(Spec::new());
}

book.build()?;

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/tools/tidy/src/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub(crate) const WORKSPACES: &[(&str, ExceptionList, Option<(&[&str], &[&str])>,
//("src/tools/miri/test-cargo-miri", &[], None), // FIXME uncomment once all deps are vendored
//("src/tools/miri/test_dependencies", &[], None), // FIXME uncomment once all deps are vendored
("src/tools/rust-analyzer", EXCEPTIONS_RUST_ANALYZER, None, &[]),
("src/tools/rustbook", EXCEPTIONS_RUSTBOOK, None, &["src/doc/book"]),
("src/tools/rustbook", EXCEPTIONS_RUSTBOOK, None, &["src/doc/book", "src/doc/reference"]),
("src/tools/rustc-perf", EXCEPTIONS_RUSTC_PERF, None, &["src/tools/rustc-perf"]),
("src/tools/x", &[], None, &[]),
// tidy-alphabetical-end
Expand Down
Loading