-
Notifications
You must be signed in to change notification settings - Fork 481
Feature request: Support -Zbindeps in crate universe when using a nightly compiler #2031
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
Comments
In general we definitely want to support bindeps, and I'd be excited to review a PR adding support for it. I've had in my to do list for a long time to make sure the In terms of implementation, is the problem here just that we need some extra fields added to a struct in the cargo_metadata crate, and that right now we're losing those fields on round-tripping? If so, I'd recommend roughly the following:
Note that rules_rust/crate_universe/src/metadata.rs Lines 92 to 96 in ca750fa
-Zbindeps flag :)
|
Thanks for all the info. That plan of attack sounds reasonable to me. I guess I'm questioning if we really need to roundtrip through |
It's a reasonable question! In general cargo has a pretty stable API surface, and having a shared set of structured data types we can inspect and verify seems like a useful thing. I think I'd probably lean towards "Let's keep this in the back of our minds and re-consider if we end up frequently being constrained by cargo_metadata lagging behind cargo", as I suspect we'll probably diverge from what's actually in cargo_metadata very rarely. But if it becomes a frequent problem, we can either discuss with the cargo_metadata folks, or start working on the raw toml? |
This issue is a duplicate of #1739. |
I have a patch that enables this within crate_universe when using a nightly version of cargo. See: https://github.com/csmulhern/rules_rust/commit/e48ed839cb9fb7ad6cd4e10878d40ee647182a0c. This depends on landing a patch in cargo_toml that adds support for serializing / deserializing artifact keys in cargo_toml::DependencyDetail. E.g. cargo_toml.patch. |
Very cool @csmulhern, thanks for putting this together! That's a pleasingly small diff :) I'd be happy to merge this ~as-is, with the following steps:
|
No problem! I'm glad it was a small change too.
Sure thing.
Sounds good. I'm hoping we can just land the patch upstream, so have been waiting on the following discussion: https://gitlab.com/lib.rs/cargo_toml/-/issues/27. Will consider a fork depending on the outcome of that discussion. Will update this thread as things develop. |
@illicitonion the upstream changes were landed in cargo_toml, and published in 0.17.0. See: https://gitlab.com/lib.rs/cargo_toml/-/merge_requests/19. I've now updated my patch to use the new version of cargo_toml, and added a test that executes the binary dependency. Link to PR: #2226. |
This would allow easy dependence on binary dependencies (e.g.
bindgen
orwasm-bindgen
) by directly adding a dependency in Cargo.toml, rather than following the convoluted process here: https://bazelbuild.github.io/rules_rust/crate_universe.html#binary-dependencies.For more info on bindeps, see: https://rust-lang.github.io/rfcs/3028-cargo-binary-dependencies.html.
Initially, my idea was just to add "-Zbindeps" to other_options here, when using a nightly version of cargo (we can also add a separate CLI option to splicing to make this more explicitly opt-in):
rules_rust/crate_universe/src/metadata.rs
Lines 77 to 83 in ca750fa
However, this does not work, due to use of cargo_metadata. The actual Cargo.toml file managed by the end user is parsed by
cargo_metadata
(which serializes packages into this struct: https://github.com/oli-obk/cargo_metadata/blob/010cd78751e51dc48d0ca08ca0f4be3ac054a689/src/lib.rs#L289), and then written out as a generated file (which includes various additional attributes used by crate universe). The generated Cargo.toml file is the actual file passed tocargo
when splicing. The serialization / deserialization throughcargo_metadata
is stripping out any unknown fields defined withincargo_metadata
. Critically, this is dropping theartifact
field defined on a bin-only package when using bindeps.Why do we need to add additional fields to a generated Cargo.toml before splicing?
It seems to me like we could generate the generated Cargo.toml with a generic TOML library, rather than round tripping through
cargo_metadata
. Would maintainers be open to such an approach? Are there any concerns about such an approach?The text was updated successfully, but these errors were encountered: