mdbook build: Build a Rust mdBook
mdbook build reads book.toml and SUMMARY.md and renders the Markdown chapters into a static HTML book under book/.
mdBook is the tool behind the Rust book and many project handbooks. mdbook build produces the site; mdbook test runs Rust code samples so your docs stay correct.
What it does
mdbook build loads book.toml, reads the chapter list from src/SUMMARY.md, renders each Markdown file, and writes the HTML book to book/ (or --dest-dir). mdbook test compiles and runs Rust code blocks against a crate.
Common usage
mdbook build
# write to a custom directory
mdbook build --dest-dir dist
# verify Rust code samples compile and pass
mdbook testOptions
| Command / flag | What it does |
|---|---|
| mdbook build | Render the book to static HTML |
| --dest-dir / -d <dir> | Output directory (default book) |
| mdbook test | Run Rust code samples in the book |
| mdbook serve | Serve with live reload (dev only) |
| --open / -o | Open the built book in a browser |
In CI
Run mdbook build then mdbook test so code samples never drift from reality. Install mdbook via cargo or a pinned release binary; cache it between runs. Deploy the book/ directory to Pages the same way as any static site.
Common errors in CI
Nonexistent files in SUMMARY.md or error: Failed to parse SUMMARY.md means a chapter link points at a missing file or the summary syntax is wrong. mdbook test reports test failed, to rerun pass ... when a code sample does not compile; mark examples that should not run as ignore or no_run. Couldn't open book.toml means you ran outside the book root.