Skip to content

Commit

Permalink
bazel: Update rules_rust, switching external crate management mode
Browse files Browse the repository at this point in the history
The primary change here is updating rules_rust. In the process, we
also switch from using crates_universe to the new crates_repository
functionality. This is a newer, more structured approach to managing
external crates. The most visible differences are:

- We now specify crates using `{"crate_name": crate.spec(version = "=1.2.3")}`, rather than `[crate.spec(name = "crate_name", version = "=1.2.3")]` when we specify the crates we use in rust.bzl.
- We now specify crates using `"@crates//:crate_name"`, rather than `crate("crate_name")` when we specify dependencies in BUILD files.
- There is now support for disabling default features, rather than having to do that manually.
- There is now a lockfile for external crates, including their cryptographic checksum. For now this has to be updated by using the `CARGO_BAZEL_REPIN=true` environment variable, but in due course we may fix that in update-deps.

In the process, we've also updated a few crates. The only one with
breaking changes was updating chacha20 to 0.9.0.

This also moves most of the crates that previously were fetched
using http_archive (allowing us to customise the BUILD file), rather
than using crates_universe, to now being fetched as normal with the
other crates in crates_repository. This simplifies the dependency
management somewhat. The only two crates still being fetched using
http_archive are compiler-builtins (since we don't build it using
rules_rust) and bootloader (since we both customise the BUILD file
considerably and also patch some files).

A big thank-you is due to @UebelAndre for their patience in helping
me diagnose an issue I had while upgrading. This was due to me having
the `default` feature enabled in smoltcp and wondering why disabling
default features wasn't working. See bazelbuild/rules_rust#1168 for
the details.

Signed-off-by: SlyMarbo <the.sly.marbo@googlemail.com>
  • Loading branch information
SlyMarbo committed Mar 8, 2022
1 parent 6615dd5 commit 70e33fe
Show file tree
Hide file tree
Showing 33 changed files with 2,767 additions and 666 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Once Bazel and the above host tools are prepared, the following commands are com
- `bazel run //:update-deps`: Update managed dependencies.
- `bazel run //:qemu`: Build a bootable disk image and run it in Qemu.

When the set of external Rust crates changes, such as by updating crates, or updating rules_rust, the lockfile for external crates needs to be updated using: `CARGO_BAZEL_REPIN=true bazel build @crates//...`.

## FAQ

### Why make a new OS?
Expand Down
4 changes: 2 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ load("//bazel/deps:defs.bzl", "go_deps", "rust_deps")

rust_deps()

load("@crates//:defs.bzl", "pinned_rust_install")
load("@crates//:defs.bzl", "crate_repositories")

pinned_rust_install()
crate_repositories()

# gazelle:repository go_repository name=org_golang_x_sys importpath=golang.org/x/sys

Expand Down
Loading

0 comments on commit 70e33fe

Please sign in to comment.