Skip to content

Commit dd7e458

Browse files
authored
crate_universe rule (#598)
This rule dynamically looks up crate dependencies as a repository rule. See #2 for context. Note that this rule is currently experimental, and offers absolutely no stability guarantees. Expect significant churn in near future.
1 parent 9202569 commit dd7e458

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+9637
-1
lines changed

.bazelignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
docs
22
examples
3+
examples/crate_universe
34
examples/cargo_manifest_dir/external_crate

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# bazel
77
/bazel-*
88
/examples/bazel-*
9-
/examples/*/bazel-*
9+
/examples/crate_universe/*/bazel-*
1010
/docs/bazel-*
1111

1212
# rustfmt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Contributing
2+
3+
## Tour of the codebase
4+
5+
We start at `workspace.bzl`, which invokes the resolver.
6+
7+
The resolver:
8+
* `config.rs`: Deserializes the Config
9+
* `parser.rs`: Parses the Config, any `Cargo.toml` files, and any additional packages, into a single unified `Cargo.toml` file
10+
* `resolver.rs`: Resolves all of the crates.
11+
* `consolidator.rs`: Patches in any WORKSPACE-specified overrides, and deals with platform-specific concerns.
12+
* `renderer.rs`: Generates BUILD files for each crate, as well as functions that can be called from BUILD files.
13+
14+
The code started off as a very hacky Week of Code project, and there are some clear remnants of that in the codebase - nothing is sacred, feel free to improve anything!
15+
16+
Some areas have unit testing, there are a few (very brittle) integration tests, and some examples.
17+
18+
## How to test local changes
19+
20+
To use a local version, first build it:
21+
```console
22+
resolver $ cargo build
23+
```
24+
25+
Then run a bazel build with this environment variable:
26+
```console
27+
RULES_RUST_RESOLVER_URL_OVERRIDE=file:///path/to/resolver/target/debug/resolver bazel build //whatever
28+
```
29+
30+
To get verbose logging, edit `workspace.bzl` to set `RUST_LOG` to `debug` or `trace` instead of `info`. In particular, that will print out the generated Cargo.toml, and the path to the generated workspace file.
31+
32+
Note that you may need to `bazel shutdown` between bazel commands. Hopefully not, but if you're seeing stale results, try it out. This only affects local development.
33+
34+
## Testing
35+
36+
To test with the `resolver` built from source:
37+
38+
```bash
39+
bin/test
40+
```

0 commit comments

Comments
 (0)