Skip to content

Commit 13b7c23

Browse files
authored
Rollup merge of #128276 - ehuss:rustbook-readme, r=Kobzol
Add a README to rustbook to explain its purpose This adds a README to the rustbook tool to help explain what it is for and how to use it.
2 parents a13f40d + bad25e3 commit 13b7c23

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/tools/rustbook/README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Rustbook
2+
3+
This is a wrapper around [`mdbook`](https://github.com/rust-lang/mdBook/), which is used to generate the book-style documentation in the Rust project. This wrapper serves a few purposes:
4+
5+
- Avoids some of mdbook's large, optional dependencies (like tokio, webserver, etc.).
6+
- Makes it a little easier to customize and override some of mdbook's behaviors (like swapping in custom preprocessors).
7+
- Supports vendoring of the source via Rust's normal release process.
8+
9+
This is invoked automatically when building mdbook-style documentation, for example via `./x doc`.
10+
11+
## Cargo workspace
12+
13+
This package defines a separate cargo workspace from the main Rust workspace for a few reasons (ref [#127786](https://github.com/rust-lang/rust/pull/127786):
14+
15+
- Avoids requiring checking out submodules for developers who are not working on the documentation. Otherwise, some submodules such as those that have custom preprocessors would be required for cargo to find the dependencies.
16+
- Avoids problems with updating dependencies. Unfortunately this workspace has a rather large set of dependencies, which can make coordinating updates difficult (see [#127890](https://github.com/rust-lang/rust/issues/127890)).
17+
18+
## Custom preprocessors
19+
20+
Some books have custom mdbook preprocessors that need to be integrated with both the book's repository, and the build system here in the `rust-lang/rust` repository. To add a new preprocessor, there are few things to do:
21+
22+
1. Implement the preprocessor as a cargo library in the book's repository.
23+
2. Add the `[preprocessor]` table to the book's `book.toml` file. I recommend setting the command so that the preprocessor gets built automatically. It may look something like:
24+
```toml
25+
[preprocessor.spec]
26+
command = "cargo run --manifest-path my-cool-extension/Cargo.toml"
27+
28+
[build]
29+
extra-watch-dirs = ["my-cool-extension/src"]
30+
```
31+
3. Add the preprocessor as a dependency in rustbook's `Cargo.toml`.
32+
4. Call `with_preprocessor` in `rustbook/src/main.rs`.
33+
5. Be sure to test that it generates correctly, such as running `./x doc MY-BOOK-NAME --open` and verify the content looks correct.
34+
6. Also test tidy and your book, such as running `./x test tidy` and `./x test MY-BOOK-NAME`.

0 commit comments

Comments
 (0)