-
Notifications
You must be signed in to change notification settings - Fork 413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add "crate-name={}" tag to Crate Universe targets #1787
Conversation
NB I haven't found a way to test that this fixes the issue; the repo appears to be unusable (ie: when importing the source code artifact via |
Thanks for the PR!
See https://github.com/bazelbuild/rules_rust/blob/main/crate_universe/DEVELOPMENT.md for development tips :) We should also add this tag to generated |
@@ -766,6 +768,7 @@ mod test { | |||
|
|||
assert!(build_file_content.contains("rust_library(")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate crate-name
tag correctness for:
rust_library
cargo_build_script
rust_proc_macro
rust_binary
@@ -379,6 +379,7 @@ impl Renderer { | |||
tags.insert("manual".to_owned()); | |||
tags.insert("noclippy".to_owned()); | |||
tags.insert("norustfmt".to_owned()); | |||
tags.insert(format!("crate-name={}", krate.name)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add tag to cargo_build_script
s
@@ -514,6 +515,7 @@ impl Renderer { | |||
tags.insert("manual".to_owned()); | |||
tags.insert("noclippy".to_owned()); | |||
tags.insert("norustfmt".to_owned()); | |||
tags.insert(format!("crate-name={}", krate.name)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add tag to rust_binary
, rust_library
, rust_proc_macro
Done, tests all passing locally - thanks for the tip! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - thanks!
If you rebase past #1785 we should be able to merge :)
Merged latest upstream changes. |
When interoperating with Cargo, it's useful to have knowledge of the original crate name for a crate downloaded via Crate Universe (e.g: for distributing a crate compiled via Bazel on crates.io).
Unfortunately this name is not currently exposed anywhere, besides (incidentally) via the auto-generated repository name:
@crates__async-trait-0.36.0
(for the target@crates__async-trait-0.36.0//:async_trait
) and via thealias
,@crates//:async-trait
, which (to the best of my knowledge) is not generally visible to a Bazel aspect, as thetarget
field in an aspect implementation refers to the original target being aliased - in this case@crates__async-trait-0.36.0//:async_trait
As a workaround it is possible to retrieve the crate name through string parsing, but this feels like a hack. In this PR we add a tag to each Crate Universe target: for example
"crate-name=async-trait"
.Fixes #1783 .