-
Notifications
You must be signed in to change notification settings - Fork 406
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
Provide CARGO_PKG_NAME and CARGO_PKG_VERSION* for build scripts #366
Conversation
Hi, Although I think it make senses to have |
@damienmg thanks for looking into it. My goal is to make all the crates compilable without having a need to put anything into the Besides that it is hard to maintain the settings in this section, as it requires putting exact crate versions that in fact may change on every |
@a1ph I think what @damienmg is suggesting is that instead of teaching cargo_build_script(
...
version = "2.1.0",
...
) and having cargo_build_script(
...
build_script_env = {
"CARGO_PKG_VERSION": "2.1.0",
"CARGO_PKG_VERSION_MAJOR": "2",
...
},
...
) which will Just Work with no modification to the rules. I guess there's a philosophical question as to whether I have no real preference for whether the |
Yes @illicitonion explained well what I was thinking. I agree that version is nicer but however this is a duplicate feature, since it is always easier to add feature than to remove them, I would err on the side of not adding a feature. So I would prefer if this PR would just add the |
I'm ok with moving the logic to cargo-raze. However please note it already generates |
Oh indeed I forgot that. I need to double check what the version in
rust_binary do but in that case that make sense to keep your pr as-is.
…On Sat, Jul 4, 2020, 4:30 AM Alexei Filippov ***@***.***> wrote:
I'm ok with moving the logic to cargo-raze. However please note it already
generates version in cargo_build_script invocation, that I believe is
required by rust_binary.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#366 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA4MO7YLZXKUS5VU5I2D62TRZ2H43ANCNFSM4OPRRAEQ>
.
|
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.
Sorry for all the push back, I totally missed this was a feature of rust_binary. This does not change any API in fact so LGTM.
cargo/cargo_build_script.bzl
Outdated
if ctx.attr.version: | ||
version = ctx.attr.version.split(".") | ||
env["CARGO_PKG_VERSION"] = ctx.attr.version | ||
env["CARGO_PKG_VERSION_MAJOR"] = version[0] | ||
env["CARGO_PKG_VERSION_MINOR"] = version[1] if len(version) > 1 else "" | ||
env["CARGO_PKG_VERSION_PATCH"] = version[2] if len(version) > 2 else "" |
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 about when there is a label (e.g. 1.2.3-blah
or 2.3.4+bleh
)?
if ctx.attr.version: | |
version = ctx.attr.version.split(".") | |
env["CARGO_PKG_VERSION"] = ctx.attr.version | |
env["CARGO_PKG_VERSION_MAJOR"] = version[0] | |
env["CARGO_PKG_VERSION_MINOR"] = version[1] if len(version) > 1 else "" | |
env["CARGO_PKG_VERSION_PATCH"] = version[2] if len(version) > 2 else "" | |
if ctx.attr.version: | |
version = ctx.attr.version.split("+")[0].split("-")[0].split(".") | |
env["CARGO_PKG_VERSION"] = ctx.attr.version | |
env["CARGO_PKG_VERSION_MAJOR"] = version[0] | |
env["CARGO_PKG_VERSION_MINOR"] = version[1] if len(version) > 1 else "" | |
env["CARGO_PKG_VERSION_PATCH"] = version[2] if len(version) > 2 else "" |
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.
done. slightly different though.
This is used e.g. by the protobuf crate build script.
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!
This is used e.g. by the protobuf crate build script.