Integrate mdbook-spec for the reference.

This updates the reference which is now using a new mdbook plugin. This
requires a little extra work than a normal book because the plugin uses
`rustdoc` to generate links to the standard library. It also ensures
that the submodule is available for *any* command that uses rustbook,
since it is now part of the rustbook workspace.
This commit is contained in:
Eric Huss 2024-07-25 17:38:22 -07:00
parent a20db06d5b
commit 53ef052d45
8 changed files with 102 additions and 13 deletions

View file

@ -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"
@ -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"
@ -1079,6 +1099,7 @@ dependencies = [
"env_logger",
"mdbook",
"mdbook-i18n-helpers",
"mdbook-spec",
"mdbook-trpl-listing",
"mdbook-trpl-note",
]

View file

@ -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"

View file

@ -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;
@ -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);
}
@ -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(())

View file

@ -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