Replies: 3 comments 22 replies
-
(disclaimer, I work with Chris, so it won't come as a surprise what I write next :) I FWIW like this approach - it makes Rust fit a little bit better into bigger monorepos, while staying compatible with OSS workflows depending on crates.io (since those names won't be mangled by the macro). We wanted to share this work with other rules_rust users to get feedback and potentially contribute the macro and a build_setting that would enable this mode in rules_rust. We don't plan to remove the existing mode. There is some work to be done in the rules (to set the right flags to rustc etc.). If this turns out useful, we may try to talk to rust-analyzer folks about some further goodies like automatically adding crates to the macro. And a small caveat, we will need some time to stabilize the implementation, it should be considered experimental at the moment. But we do plan to use it internally, so it will reach stability soon. |
Beta Was this translation helpful? Give feedback.
-
If #1013 is the tracking issue, could it be a bit more descriptive? 😅 🙏 |
Beta Was this translation helpful? Give feedback.
-
Haven't thought through it entirely, but relying on just a particular file seems to be somewhat fragile. What happens for tooling in the multi file rust_library case? Would a user need to specify these macro blocks in each file for them to work? It also makes rust look quite different between inside and outside of google. Copybara-ing is always a nightmare, but the distinction between first and third party and the macro seem like it would make that quite difficult. |
Beta Was this translation helpful? Give feedback.
-
Hello!
Google has some Rust in its source repository, and we have realized that rules_rust's current approach to naming crates (i.e., using the target name as the crate name) will not work for us. We need to use a naming scheme that uniquely identifies each first-party crate, and associates it with the entire Bazel label that it was built from; for third-party crates, we can use the crate's actual name (without modification).
We're experimenting with an approach that embeds the Bazel label of a dependency crate in Rust source code, and uses a proc macro to transform the Bazel labels into valid Rust identifiers corresponding to the crates listed in the target's
deps
(following a particular encoding scheme that must be agreed upon between the proc macro and the rules_rust implementation).An example of this usage is the following:
This would expand to:
Note that the two crates imported from the //third_party directory were not renamed, but otherwise, that the whole Bazel label was visible in source, and encoded in the dependency crate's name.
I've written a prototype of this macro (uploaded in this commit - currently broken due to missing deps, but you can play around with it and see the idea), so now I'd like to add the ability to do this renaming in rules_rust (behind a flag), to continue experimenting.
I plan to add a flag to allow a project to opt-in to this new naming scheme soon, but wanted to open up for discussion :)
Beta Was this translation helpful? Give feedback.
All reactions