This PR is the first step of several aiming at introducing better caching and reproducibility with Bazel. It will eventually fix #1168. I have been introducing Bazel for a large polyglot build at work, and this gave me hands on experience with building Rust with Bazel. In this project, we have so far been using shell scripts. YAML files, and a bit of `cargo xtask` to keep the build here going. However, it's time to admit that we have a non-trivial build process: - we build several `mdbook` plugins, some from our repository, some from external repositories (we install them globally with `cargo install`). - we use `build.sh` to backdate the sources for translations (we leave behnd a dirty working copy). - we have end-to-end tests which rely on NodeJS being installed on the system. All this complexity can be rained in with Bazel: we can build our `mdbook` plugins hermetically and put them on the `PATH` only for the final `mdbook build` invocation. We can put our backdated sources into temporary directories and keep the working copy clean. This will let us skip building translations that haven't changed, thus speeding up local and CI builds. I have not yet looked at the NodeJS parts, but I'm sure that can be integrated with Bazel as well. The approach used lets `rules_rust` read the `Cargo.lock` file: ```python crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate") crate.from_cargo( name = "crates", cargo_lockfile = "//:Cargo.lock", manifests = ["//:Cargo.toml"], ) use_repo(crate, "crates") ``` This is the documented on https://bazelbuild.github.io/rules_rust/crate_universe_bzlmod.html. It build on the existing Cargo setup and is thus compatible with it. We can discuss later if we want to keep Cargo compatibility or move completely to Bazel.
4.8 KiB
How to Contribute
We'd love to accept your patches and contributions to this project. There are just a few small guidelines you need to follow.
Make sure you can build the book with mdbook build, that mdbook serve works,
and that dprint fmt formats the code. Please use cargo xtask install-tools
to install the necessary dependencies, following the
instructions in the README.
Writing Exercises
Each segment ends with an exercise. Exercises are typically structured as an
exercise.rs containing the problem and solution. This is referenced from
exercise.md and solution.md, using {{#include exercise.rs:anchor_name}} to
match ANCHOR comments in the exercise.rs file. Each segment also has a
Cargo.toml file containing a [[bin]] or [lib] section referring to
exercise.rs, and that Cargo package is referenced from the workspace the root
Cargo.toml. The result is that exercise.rs is built and tested by
cargo test.
For segments on day 1, exercises should use fn main() { .. } and dbg! or
println!, with students visually verifying the correct output. On subsequent
days, prefer tests and omit fn main() { .. }. However, where tests would be
difficult and visual verification is more natural (such as in the Logger
exercise), using fn main { .. } is OK.
Especially for exercises without tests, consider including tests in
exercise.rs that do not appear in either exercise.md or solution.md, as
these can ensure the solution is correct.
Testing
We test the course material in several ways:
mdbook test: This will test the code samples. Some code samples are marked withignorein the Markdown file because the Playground is missing some of the crates we use. For this we havecargo test: This will build and test the Rust code found in our tooling, as well as the code samples which cannot be tested using the Playground.npm test: This will test the functionality of the rendered web pages. See the testing README for details.
Formatting
Please ensure that your files are formatted consistently. We use a few tools for this:
dprintfor driving the formatting.rustfmtfor formatting Rust code.yapffor formatting Python code.msgcatfor formatting PO files.
Run dprint fmt to automatically format all files.
Note: To make sure you have the correct version of rustfmt installed,
please run:
cargo xtask install-tools
This will install the pinned nightly toolchain and add the rustfmt component,
so your local formatting will match the CI.
Linux
Install dprint using their
installation instructions and install rustfmt
via rustup.
Install Bazel via the Bazelisk version manager.
Install pandoc 3.7.0.1.
On Debian, you can install the other tools using:
sudo apt install yapf3 gettext texlive texlive-luatex texlive-lang-cjk texlive-lang-arabic librsvg2-bin fonts-noto
MacOS
On MacOS with Homebrew, you can install the necessary tools with:
brew install dprint yapf gettext bazelisk
Windows
On Windows, you can should install Gettext tools for Windows.
Install dprint using their
installation instructions and install rustfmt
via rustup.
Install Bazel via the Bazelisk version manager.
TODO: fill in how to install
yapfon Windows.
Contributor License Agreement
Contributions to this project must be accompanied by a Contributor License Agreement. You (or your employer) retain the copyright to your contribution; this simply gives us permission to use and redistribute your contributions as part of the project. Head over to https://cla.developers.google.com/ to see your current agreements on file or to sign a new one.
You generally only need to submit a CLA once, so if you've already submitted one (even if it was for a different project), you probably don't need to do it again.
Code Reviews
All submissions, including submissions by project members, require review. We use GitHub pull requests for this purpose. Consult GitHub Help for more information on using pull requests.
Community Guidelines
This project follows Google's Open Source Community Guidelines.