crates.io dependencies#
This directory is where third party crate dependencies are managed. There are
two sets of crates: ./crates_no_std and ./crates_std. These are
cargo based “null” Rust libraries that exist solely to express which crates
to expose to Bazel via the a single unified hub. ./rust_crates is a Bazel
repository that exposes these crates to Bazel.
Getting started#
Crates are split by whether they use std or no_std. By default,
platforms are otherwise assumed to use std. Embedded platforms typically
need to add @pigweed//pw_build/constraints/rust:no_std to their platform’s
constraint_values:
platform(
name = "mps2_an505",
constraint_values = [
"@pigweed//pw_build/constraints/arm:cortex-m33",
"@pigweed//pw_build/constraints/rust:no_std",
"@platforms//cpu:armv8-m",
"@platforms//os:none",
],
)
Vendoring your own crates#
Pigweed’s pw_rust_crates_extension Bazel module extension allows the
@rust_crates repo used by Pigweed to be overridden so alternative crate
definitions may be used. This can be done by adding the following
to your project’s MODULE.bazel:
local_repository(name = "rust_crates", path = "build/crates_io")
pw_rust_crates = use_extension(
"@pigweed//pw_build:pw_rust_crates_extension.bzl",
"pw_rust_crates_extension",
)
override_repo(pw_rust_crates, rust_crates = "rust_crates")
Adding a third party crate to Pigweed#
Add the crate to either or both of
./crates_no_stdand./crates_stdby running the following command in the appropriate directory:$ cargo add <crate_name> --features <additional_features>
Run cargo deny:
$ (cd crates_std; cargo deny check) && \ (cd crates_no_std; cargo deny check)
Note
Install with
cargo install --locked cargo-denyif not already installed.Update
./rust_crates/alias_hub.BUILDby running the following command in thethird_party/crates_iodirectory:$ cargo run -- --config config.toml > rust_crates/alias_hub.BUILD