Support module discovery for lib.rs crate roots#25
Support module discovery for lib.rs crate roots#25isaacparker0 wants to merge 3 commits intoCalsign:mainfrom
Conversation
19b41e2 to
a093aea
Compare
|
Thanks for the PR! I think subdirs still aren't handled correctly by this approach. The test case you provided won't work. The parent package references I haven't read the implementation in your PR, but I'd like to pin down the correct way to handle this first. Some options:
I'm not sure which of these I like best, presumably 4 or 5 but I think these are also more difficult to implement. I'm curious if you have other suggestions or which idea among these you prefer. When I worked in a bazel monorepo, whenever we had singular targets that contained sources for subdirectories, this was an exceptional circumstance and we generally didn't create more than one target containing sources in those subdirectories. We would often use gazelle directives to prevent the creation of targets in the subdirectories (something like Perhaps rust encourages more subdirectories than other languages due to the implicit creation of modules, so maybe this is more of a problem for gazelle_rust than it was for the languages we used primarily at my former company. I would also believe that not supporting this properly for now is the correct course of action since most users won't need it anyway. I would just like to cap this off with useful error messages, i.e. option 2 rather than option 1. This would likely be in combination with a directive like |
In "pure bazel" mode, when Gazelle encounters a lib.rs file, it should follow mod declarations to discover all module files and includes them in a single
rust_librarytarget. Also remove deleted source files from targets.EDIT: After reading the discussion in #13 (Gazelle creating broken BUILD files in subdirectories hadn't occurred to me because I typically use
update_onlygeneration mode), I took a stab at handling claimed files in subdirectories. The approach is O(depth), and handles both traditionalsubdir/mod.rsstyle and Rust 2018+ adjacentsubdir.rsstyle, all with generation test coverage. @Calsign let me know if this aligns with what you were imagining, or if there are any other edge cases that need to be handled.