bazelbuild / rules_rust

Rust rules for Bazel
https://bazelbuild.github.io/rules_rust/
Apache License 2.0
671 stars 435 forks source link

`crate_universe` ignores dependencies between workspace members #2994

Open KoltesDigital opened 1 week ago

KoltesDigital commented 1 week ago

I've just upgraded the rules from 0.30.0 in WORKSPACE to 0.54.1 in bzlmod, on Windows 11. My project does not compile anymore.

The problem is that all_crate_deps does not list workspace siblings, whereas it used to.

I've set up a minimal reproducible example at https://github.com/KoltesDigital/bazel-rust-workspace-members . It's basically a library and a binary, the latter depends on the former. But _/external/rulesrust~~crate~crates/defs.bzl has the following:

...
###############################################################################
# WORKSPACE MEMBER DEPS AND ALIASES
###############################################################################

_NORMAL_DEPENDENCIES = {
    "mybin": {
    },
    "mylib": {
    },
}
...

which means all_crate_deps in mybin/BUILD does not declare a dependency to mylib, and thus build fails.

The workaround is to manually add + ["//mylib:library"] to mybin/BUILD.

It used to work, but now that I've written the previous sentence, I'm wondering whether it was working by mistake and was never intended to. I don't know any way for crate_universe to know the precise target name of a library in the user project.

So, is the workaround the actual way to go? If so, you may consider integrating my example into examples/bzlmod to let people know.

Update: well... even the workaround doesn't work. Build still fails! What should I do?

Update 2: workaround works when targets are named exactly like the crates. Check branch works out.