xref: /aosp_15_r20/external/bazelbuild-rules_rust/crate_universe/DEVELOPMENT.md (revision d4726bddaa87cc4778e7472feed243fa4b6c267f)
1*d4726bddSHONG Yifan# Developing crate_universe
2*d4726bddSHONG Yifan
3*d4726bddSHONG Yifan## Bootstrapping
4*d4726bddSHONG Yifan
5*d4726bddSHONG YifanCrate Universe repository rules are backed by a binary called `cargo-bazel`.
6*d4726bddSHONG YifanThis can be built using cargo by simply changing directories to
7*d4726bddSHONG Yifan`@rules_rust//crate_universe` and running the following:
8*d4726bddSHONG Yifan
9*d4726bddSHONG Yifan```shell
10*d4726bddSHONG Yifancargo build --bin=cargo-bazel
11*d4726bddSHONG Yifan```
12*d4726bddSHONG Yifan
13*d4726bddSHONG YifanIt's then recommended to export the `CARGO_BAZEL_GENERATOR_URL` environment
14*d4726bddSHONG Yifanvariable to be a `file://` url to the built binary on disk.
15*d4726bddSHONG Yifan
16*d4726bddSHONG Yifan```shell
17*d4726bddSHONG Yifanexport CARGO_BAZEL_GENERATOR_URL=file://$(pwd)/target/debug/cargo-bazel
18*d4726bddSHONG Yifan```
19*d4726bddSHONG Yifan
20*d4726bddSHONG YifanFrom here on, the repository rule can be run
21*d4726bddSHONG Yifan
22*d4726bddSHONG Yifan## Using non-release rules_rust
23*d4726bddSHONG Yifan
24*d4726bddSHONG YifanIf a project does not get `rules_rust` from a release artifact from the Github
25*d4726bddSHONG Yifanreleases page (e.g. using an archive from a commit or branch) then `cargo-bazel`
26*d4726bddSHONG Yifanbinaries will have to manually be specified for repository rules that consume it.
27*d4726bddSHONG YifanIt's highly recommended to build `cargo-bazel` binaries yourself and host them
28*d4726bddSHONG Yifansomewhere the project can safely access them. Without this, repository rules will
29*d4726bddSHONG Yifanattempt to build the binary using [cargo_bootstrap_repository][cbr] as a fallback.
30*d4726bddSHONG YifanThis is very time consuming and in no way the recommended workflow for anything
31*d4726bddSHONG Yifanother than developing `rules_rust` directly.
32*d4726bddSHONG Yifan
33*d4726bddSHONG Yifan[cbr]: https://bazelbuild.github.io/rules_rust/cargo.html#cargo_bootstrap_repository
34*d4726bddSHONG Yifan
35*d4726bddSHONG Yifan## Updating vendored crates
36*d4726bddSHONG Yifan
37*d4726bddSHONG YifanA lot of crates are vendored into this repo, e.g. in examples and tests. To
38*d4726bddSHONG Yifanre-vendor them all, a bash script is provided:
39*d4726bddSHONG Yifan
40*d4726bddSHONG Yifan```sh
41*d4726bddSHONG Yifanbazel run //crate_universe/tools:vendor
42*d4726bddSHONG Yifan```
43