vaticle / bazel-distribution

Bazel rules for assembling and deploying software distributions (see @vaticle for usage example)
https://bazel.build
Apache License 2.0
155 stars 53 forks source link

Support proc macros and fix dependency name detection in `assemble_crate` #367

Closed alexjpwalker closed 1 year ago

alexjpwalker commented 1 year ago

What is the goal of this PR?

assemble_crate now supports procedural macro dependencies, and is more reliable at correctly detecting the crate names of all dependencies. In particular, crates with hyphens (such as async-trait) should no longer cause issues.

What are the changes implemented in this PR?

Previously assemble_crate aggregated dependency info via only the deps attribute of a rust_* target. Now, proc_macro_deps is traversed as well.

Also, crate name detection has been reworked. Because rules_rust doesn't expose the original name of the crate downloaded from Cargo anywhere, we were unable to reliably get that crate name and put it into Cargo.toml. Now, we use string parsing against the target's label. This works because the label is (e.g):

@crates__async-trait-0.36.0//:async_trait

We take everything up to + excluding the first ., then take everything up to + excluding the last -, then strip @crates__ from the front.

It looks like a dumb hack (and it is), but it works. I've raised:

vaticle-bot commented 1 year ago

PR Review Checklist

Do not edit the content of this comment. The PR reviewer should simply update this comment by ticking each review item below, as they get completed.


Trivial Change

Code

Architecture