This documentation is for anyone managing the repo to remember how to do occasional maintenance tasks.
rustc
versiontarget
directory, you're about to recompile everything anyway.github/workflows/main.yml
rust-toolchain
, which should change the version you're using locally with rustup
src/title-page.md
./tools/update-rustc.sh
(see its commented code for details on what it does)tmp/book-before
and tmp/book-after
) and commit them if they look goodmanual-regeneration
and follow the instructions in those places to update output that cannot be generated by a scriptedition
in all listingsTo update the edition = "[year]"
metadata in all the listings' Cargo.toml
s, run the ./tools/update-editions.sh
script. Check the diff to make sure it looks reasonable, and in particular check whether the updates necessitate any changes to the text. Then commit the changes.
edition
in mdBook configOpen book.toml
and nostarch/book.toml
and set the edition
value in the [rust]
table to the new edition.
We now make .tar
files of complete projects containing every listing available as GitHub Releases. To create a new release artifact, for example if there have been code changes due to edits or due to updating Rust and rustfmt
, do the following:
cargo run --bin release_listings
, which will generate tmp/listings.tar.gz
tmp/listings.tar.gz
in the GitHub UI for the draft releaseTo facilitate the scripts that run rustfmt
on all the listings, update the output when the compiler is updated, and produce release artifacts containing full projects for the listings, any listing beyond the most trivial should be extracted into a file. To do that:
listings
directory.listing-[chapter num]-[listing num]
for their directory names.no-listing-
followed by a number that indicates its position in the chapter relative to the other listings without numbers in the chapter, then a short description that someone could read to find the code they're looking for.output-only-
followed by a number that indicates its position in the chapter relative to the other listings used only for output, then a short description that authors or contributors could read to find the code they’re looking for.cargo new
or copying another listing as a starting point.// ANCHOR: some_tag
and // ANCHOR_END: some_tag
) to mark the parts of the file you want to show.{{#rustdoc_include [filename:some_tag]}}
directive within the code blocks in the text. The rustdoc_include
directive gives the code that doesn't get displayed to rustdoc
for mdbook test
purposes.{{#include [filename:some_tag]}}
directive.output.txt
file in the listing's directory as follows:cargo run
or cargo test
, and copy all of the output.output.txt
file with the first line $ [the command you ran]
../tools/update-rustc.sh
, which should perform some normalization on the compiler output.{{#include [filename]}}
directive.manual-regeneration
and instructions for manually updating the inline output.rustfmt
(for example because the example doesn’t parse on purpose), add a rustfmt-ignore
file in the listing‘s directory and the reason it’s not being formatted as the contents of that file (in case it's a rustfmt bug that might get fixed someday).To check, say, updating mdbook
or changing the way files get included:
mdbook build -d tmp/book-before
mdbook build -d tmp/book-after
./tools/megadiff.sh
tmp/book-before
and tmp/book-after
have differences you can manually inspect with your favorite diff viewing mechanism./tools/nostarch.sh
nostarch
directorytmp/chapterXX.docx
../tools/doc-to-md.sh
nostarch/chapterXX.md
. Adjust the XSL in tools/doc-to-md.xsl
and run ./tools/doc-to-md.sh
again if needed.We're using Graphviz for some of the diagrams in the book. The source for those files live in the dot
directory. To turn a dot
file, for example, dot/trpl04-01.dot
into an svg
, run:
$ dot dot/trpl04-01.dot -Tsvg > src/img/trpl04-01.svg
In the generated SVG, remove the width and the height attributes from the svg
element and set the viewBox
attribute to 0.00 0.00 1000.00 1000.00
or other values that don't cut off the image.
We sometimes publish to GitHub Pages for in-progress previews. The recommended flow for publishing is:
ghp-import
tool by running pip install ghp-import
(or pipx install ghp-import
, using pipx).tools/generate-preview.sh