rules_rust icon indicating copy to clipboard operation
rules_rust copied to clipboard

crate_universe: Support fetching crates with git branch, tag or rev

Open uhthomas opened this issue 2 years ago • 3 comments

Fixes https://github.com/bazelbuild/rules_rust/issues/1262.

Fortunately the code to support branches and tags already exists, and so it's as simple as adding them to the json blob.

Not only that, but code already exists which enforces the exclusivity of branch, tag and rev.

error: failed to parse manifest at `/var/folders/ws/lyfqx2sn72v223fhz5kb77m40000gp/T/.tmpIq5bdq/Cargo.toml`

Caused by:
  dependency (<redacted>) specification is ambiguous. Only one of `branch`, `tag` or `rev` is allowed.

Would it make sense to enforce this even earlier on though? It might just be a waste of cycles.

uhthomas avatar Apr 20 '22 23:04 uhthomas

I think some tests would be a good idea. Would you be able to offer some guidance on where it would be appropriate to add said tests?

uhthomas avatar Apr 21 '22 17:04 uhthomas

I think some tests would be a good idea. Would you be able to offer some guidance on where it would be appropriate to add said tests?

I think this is gonna require some refactoring, but for any macro that in some way gets written to a file, we should make a target that does explicitly that, and then have a unittest de-serialize it and check that certain values are properly set. This way when new fields are added to the Rust structs, the test will require people to make sure the macros are up to date too. Does that make sense?

UebelAndre avatar Apr 22 '22 18:04 UebelAndre

@uhthomas I think adding onto https://github.com/bazelbuild/rules_rust/pull/1291 would be sufficient testing. Deserialize the struct and make sure the values you set are correctly represented in rust. Passed that I'd say maybe there should be some tests for rendering to ensure tag and branch will actually get rendered. After my PR I think there should be enough prior art to make writing the tests easy. Does that sound reasonable to you? (don't want to hold the change hostage to testing so trying to make adding tests easy 😅)

UebelAndre avatar Apr 25 '22 17:04 UebelAndre

I've opened a pull request expanding the change here with test data to verify the serialization and deserialization of crate.spec(): https://github.com/bazelbuild/rules_rust/pull/1846

ted-logan avatar Feb 23 '23 01:02 ted-logan

Closing this out as the functionality was merged in https://github.com/bazelbuild/rules_rust/pull/1846

UebelAndre avatar Apr 11 '23 13:04 UebelAndre