-
Notifications
You must be signed in to change notification settings - Fork 393
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
Fix (+) In vendored crates semver metadata #2579
Fix (+) In vendored crates semver metadata #2579
Conversation
…_rust into fix-vendored-manifests
crate_universe/src/rendering.rs
Outdated
.expect("All file paths should have valid directories") | ||
.to_str() | ||
.expect("All file paths should be strings"); | ||
if original_path_str.contains('+') { |
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.
Are worried about someones path on their computer having a + sign in it? If so i may need to not re use the sanitize function
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.
Why not have this logic happen in the place where we decide the output name?
https://github.com/bazelbuild/rules_rust/blob/0.41.0/crate_universe/src/rendering.rs#L286
That way we don't need to bother with an additional file op and this code function would be unchanged, right?
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.
I think I tried this and it had side effects somewhere . Let me change this line and make sure. Im all for smaller code changes.
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.
If you just change the label, it will put the build file in the correct path, but the Crate itself will be stored in the + file path, due to how cargo vendors the dep. I tried this my first attempt, and thats how I ended up with my current solution. We use cargo to run the vendor command, and it will auto generate the semver metadata with the plus sign
libbpf-sys-1.3.0+v1.3.0
libbpf-sys-1.3.0-v1.3.0
> ls libbpf-sys-1.3.0+v1.3.0
bindings.h build.rs Cargo.toml elfutils libbpf LICENSE README.md rebuild.sh src tests zlib
> ls libbpf-sys-1.3.0-v1.3.0
BUILD.bazel
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.
What if you did the rename here?
https://github.com/bazelbuild/rules_rust/blob/0.41.0/crate_universe/src/rendering.rs#L292
If all this new code is doing is renaming a file, it seems like we could update the code to have a correct name in the first place. If the label shouldn't change then perhaps we can update just the output file? But the thing I'd like to avoid is renaming a file. We should be producing the correct data before writing.
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.
I agree with you 100 percent, but changing those labels only change the files for the BUILD files to be generated in.
https://github.com/bazelbuild/rules_rust/blob/0.41.1/crate_universe/src/metadata.rs#L423
This line of code the rules are using Cargo to generate versioned directories. This is where the libbpf-sys-1.3.0+v1.3.0
is coming from, not the rules or rendering themselves.
https://doc.rust-lang.org/cargo/commands/cargo-vendor.html
I dont see any options in there to allow the changing of the names. Unless im missing something here, the Cargo.lock file and cargo command is the source of truth here when generating the vendored, versioned directories and thats why I had to add that code.
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.
AAAAH! I see now!! Thank you for helping me and for being so patient!
In this case, could you make a new function that does the renames? I'd totally forgotten cargo is what writes the directory names. I think it would be much clearer to future readers if there was something that consumed the outputs
value from the render, and then looked to rename existing directories as well as mutate the target output path and we hand that off to write_outputs
just as we do today. That rename function could have a nice and noticeable docstring that can communicate what's going on.
Hopefully this isn't too much of a detour but if I know myself I'll forget about this in a month and be just as confused for similar changes 😅
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.
Awesome, I will get on it! And no problem. Took me a while to grok it too. I went down the exact same path as you so I know exactly the thought pattern you were going down 😅
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.
Thanks! Could you also add a unit test for this? 🙏
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.
Thank you! I had just one question
crate_universe/src/rendering.rs
Outdated
.expect("All file paths should have valid directories") | ||
.to_str() | ||
.expect("All file paths should be strings"); | ||
if original_path_str.contains('+') { |
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.
Why not have this logic happen in the place where we decide the output name?
https://github.com/bazelbuild/rules_rust/blob/0.41.0/crate_universe/src/rendering.rs#L286
That way we don't need to bother with an additional file op and this code function would be unchanged, right?
crate_universe/src/rendering.rs
Outdated
.expect("All file paths should have valid directories") | ||
.to_str() | ||
.expect("All file paths should be strings"); | ||
if original_path_str.contains('+') { |
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.
AAAAH! I see now!! Thank you for helping me and for being so patient!
In this case, could you make a new function that does the renames? I'd totally forgotten cargo is what writes the directory names. I think it would be much clearer to future readers if there was something that consumed the outputs
value from the render, and then looked to rename existing directories as well as mutate the target output path and we hand that off to write_outputs
just as we do today. That rename function could have a nice and noticeable docstring that can communicate what's going on.
Hopefully this isn't too much of a detour but if I know myself I'll forget about this in a month and be just as confused for similar changes 😅
…_rust into fix-vendored-manifests
outputs: BTreeMap<PathBuf, String>, | ||
out_dir: &Path, | ||
) -> BTreeMap<PathBuf, String> { | ||
outputs |
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.
I moved the re mapping of the outputs from write_outputs into this function, that way the iteration still only happens one time. So it combines
let outputs: BTreeMap<PathBuf, String> = outputs
.into_iter()
.map(|(path, content)| (out_dir.join(path), content))
.collect();
With the renaming of the files if needed.
if nothing needs to be renamed, it simply just does the out_dir
join, previously in the write_outputs
function
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.
Example of SemVer change
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.
Awesome! Thank you so much!
Head branch was pushed to by a user without write access
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [rules_rust](https://togithub.com/bazelbuild/rules_rust) | http_archive | minor | `0.41.1` -> `0.42.0` | --- ### Release Notes <details> <summary>bazelbuild/rules_rust (rules_rust)</summary> ### [`v0.42.0`](https://togithub.com/bazelbuild/rules_rust/releases/tag/0.42.0) [Compare Source](https://togithub.com/bazelbuild/rules_rust/compare/0.41.1...0.42.0) ### 0.42.0 ```python load("@​bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "rules_rust", integrity = "sha256-XT1YVJ6FHJTXBr1v3px2fV37/OCS3dQk3ul+XvfIIf8=", urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.42.0/rules_rust-v0.42.0.tar.gz"], ) ``` Additional documentation can be found at: https://bazelbuild.github.io/rules_rust/#setup #### What's Changed - Fix crates.io URL by [@​ericmcbride](https://togithub.com/ericmcbride) in [bazelbuild/rules_rust#2597 - Add support for `--compile_one_dependency` by [@​william-smith-skydio](https://togithub.com/william-smith-skydio) in [bazelbuild/rules_rust#2598 - Update rules_apple by [@​sgowroji](https://togithub.com/sgowroji) in [bazelbuild/rules_rust#2602 - Support building more things with bzlmod by [@​matts1](https://togithub.com/matts1) in [bazelbuild/rules_rust#2601 - Make bazel lock file cross-platform by [@​cameron-martin](https://togithub.com/cameron-martin) in [bazelbuild/rules_rust#2453 - Added Rust 1.77.1 by [@​UebelAndre](https://togithub.com/UebelAndre) in [bazelbuild/rules_rust#2591 - Fix (+) In vendored crates semver metadata by [@​ericmcbride](https://togithub.com/ericmcbride) in [bazelbuild/rules_rust#2579 - Keep default_features parity from bzlmod to workspace by [@​Lev1ty](https://togithub.com/Lev1ty) in [bazelbuild/rules_rust#2606 - clippy: use --cap-lints=warn; apply clippy_flags when capture_output=True by [@​goffrie](https://togithub.com/goffrie) in [bazelbuild/rules_rust#2451 - Added Rust 1.77.2 by [@​UebelAndre](https://togithub.com/UebelAndre) in [bazelbuild/rules_rust#2608 - Re-vendor crate_universe outputs by [@​UebelAndre](https://togithub.com/UebelAndre) in [bazelbuild/rules_rust#2609 - Release 0.42.0 by [@​UebelAndre](https://togithub.com/UebelAndre) in [bazelbuild/rules_rust#2610 #### New Contributors - [@​Lev1ty](https://togithub.com/Lev1ty) made their first contribution in [bazelbuild/rules_rust#2606 **Full Changelog**: bazelbuild/rules_rust@0.41.1...0.42.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/bazel-contrib/toolchains_llvm). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yNjkuMiIsInVwZGF0ZWRJblZlciI6IjM3LjI2OS4yIiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIn0=--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
foo-1.2.3-1.2.3
which does not work.vendor_local_manifests
examplerender_build_files
call, it fixes the version in terms of theoutputs
andfiles
declared in the vendor cli file, but then we do not have a handle to the generated vendor files from cargo, meaning we cant move the contents over near as easily. I also didn't want to break anything downstream that may rely on that info.