-
Couldn't load subscription status.
- Fork 516
Allow opting-out of the 0.0.0 crate version fallback #3659
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
Open
dzbarsky
wants to merge
1
commit into
bazelbuild:main
Choose a base branch
from
dzbarsky:zbarsky/env
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Won't this be unset for normal
rust_*targets?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.
It will, but on the off chance that they actually need this they can either set
env = {"CARGO_PKG_VERSION": version}explicitly or usecargo_toml_env_varsfor proper support, like we do forcargo-bazelin this PR. I think it's confusing to have multiple ways to provide this functionality, and this one is more incomplete compared tocargo_toml_env_varsSee also https://bazelbuild.slack.com/archives/CSV56UT0F/p1759051609743919?thread_ts=1758229364.645099&cid=CSV56UT0F
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.
@UebelAndre another way of looking at it - previously, not setting the 'version' attribute on manually-written rust_library rules would mean they get compiled with CARGO_PKG_VERSION_MAJOR=0 and similar. That's also kinda weird and probably not the desired behavior...
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.
it's useful for things like
clapwhich basically embeds the binary version for free in your crate due to these environment variables. While I can see the argument for separating out cargo environment variables I think the few that are there do offer some convenience folks have already taken advantage of. If this were to change I think it would need an incompatibility flag.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.
+1 to keep the existing defaults
CARGO_PKG_*derived from the rust_* rules in skylark. Many random crates in the ecosystem examine these and we have setup that imports them, generating BUILD files, deriving the crate name and version of the target from the Cargo.toml file in the process, and discarding theCargo.tomlfiles after that. While the defaults are not always correct, these defaults cover a good chunk of crates in our experience.I agree it's super confusing in the presence of cargo_toml_env_vars, and there I think we shouldn't derive the defaults. Instead of a new incompatibility flag, could we make it that the implementation detects the presence of cargo_toml_env_vars dependency and disables the defaults derivation if that's present?
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.
How would you guys feel if we just stopped defaulting the version to 0.0.0 and left the vars unset in case the version wasn't provided? That would match the handling in the build_script rule and would give users an easy way to opt out of this behavior for all the version vars. It would also allow to share the duplicated parsing implementations that are inconsistent.
That would leave only CARGO_PKG_NAME which is sadly used by clap. (Fun fact, that usage is incorrect and it should use CARGO_BIN_NAME to get the right names, but that requires a clap fix...). We can tackle that one another day
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 like this. I think for us internally this will be flexible enough to handle the mix of third party dependencies with-and-without set version.
From broader point of view, still might make sense to put this feature behind an incompatible flag (strictly it feels like it is). Also curious what @UebelAndre thinks.
Sharing another thought I had last week: we could define a custom provider, say
NoDefaultEnvVarsInfo(), and havecargo_toml_env_vars()return it as well as the DefaultInfo, and in rustc.bzl gate the setting of the defaults on any of the rustc_env_files providing it.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 adding a custom provider is a decent idea but since I'm not using it on my end (Creating the .env file in the repo phase) I would then need to write a new rule wrapping those files just to create it, not sure it's worth it? Lets start with the not-defaulting-version suggestion above.
The only change in behavior really is that previously it would manufacture the
0.0.0version which was probably not correct, and if anyone really wants that behavior they can just setversion = "0.0.0"themselves? I don't mind flagging the new behavior if ya'll think there's a risk of this breaking users, but I do think incompatible flags add a tiny bit of cognitive burden so I'd consider avoiding it for something like this which is arguably fixing an inconsistent/weird behavior?Anyway, perhaps @UebelAndre can make the final call here and we can land the 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.
Changing the default seems fine but this should definitely follow https://github.com/bazelbuild/rules_rust/blob/a14b74125e142dbbf968ee47381a1d370bfd2ba6/COMPATIBILITY.md and add an incompatibility flag that gates the change in the default.
But in terms of de-duplication,
crate_universeexplicitly setsversionso won't you still run into duplication there from the cargo extracted variables?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.
OK, I will rework this. I'm ok adding the flag as long as we will be able to followup to flip the default after 3 months, which I'm also happy to do.
It's true that
crate_universewill still setversion(which we could change in a followup), but mycrate_universereplacement won't :)