1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2026-06-11 09:35:35 +02:00
Files
Martin Geisler c092c383ad bazel: Build and cache local tools with Bazel (#3197)
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.
2026-06-09 21:20:58 +02:00

6 lines
69 B
Python

ignore_directories([
"book",
"target",
"third_party",
])