Skip to content
Latchkey

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

Terminal
mdbook build
# write to a custom directory
mdbook build --dest-dir dist
# verify Rust code samples compile and pass
mdbook test

Options

Command / flagWhat it does
mdbook buildRender the book to static HTML
--dest-dir / -d <dir>Output directory (default book)
mdbook testRun Rust code samples in the book
mdbook serveServe with live reload (dev only)
--open / -oOpen 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.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →