Skip to content

Commit

Permalink
crate_universe rule
Browse files Browse the repository at this point in the history
This rule dynamically looks up crate dependencies as a repository rule.

See #2 for context.
  • Loading branch information
illicitonion committed Feb 19, 2021
1 parent fee3b3c commit d91ac45
Show file tree
Hide file tree
Showing 50 changed files with 9,535 additions and 2 deletions.
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ examples_repositories()

load("@examples//:examples_deps.bzl", examples_deps = "deps")

examples_deps()
examples_deps(is_top_level = True)

load("@examples//:examples_transitive_deps.bzl", examples_transitive_deps = "transitive_deps")

Expand Down
40 changes: 40 additions & 0 deletions cargo/crate_universe_resolver/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Contributing

## Tour of the codebase

We start at `workspace.bzl`, which invokes the resolver.

The resolver:
* `config.rs`: Deserializes the Config
* `parser.rs`: Parses the Config, any `Cargo.toml` files, and any additional packages, into a single unified `Cargo.toml` file
* `resolver.rs`: Resolves all of the crates.
* `consolidator.rs`: Patches in any WORKSPACE-specified overrides, and deals with platform-specific concerns.
* `renderer.rs`: Generates BUILD files for each crate, as well as functions that can be called from BUILD files.

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!

Some areas have unit testing, there are a few (very brittle) integration tests, and some examples.

## How to test local changes

To use a local version, first build it:
```console
resolver $ cargo build
```

Then run a bazel build with this environment variable:
```console
RULES_RUST_RESOLVER_URL_OVERRIDE=file:///path/to/resolver/target/debug/resolver bazel build //whatever
```

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.

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.

## Testing

To test with the `resolver` built from source:

```bash
bin/test
```
Loading

0 comments on commit d91ac45

Please sign in to comment.