-
Notifications
You must be signed in to change notification settings - Fork 470
rules_rust does not set CARGO_PKG_VERSION to the package version for build script rustc #3250
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
Setting the environment variable is pretty trivial but it will be on users to ensure the version they pass actually matches the consuming crate. I’d be happy to review a PR that sets this 😄 |
Funny, I found this one too, which struggles with the same issue: #3139 |
This is trivially fixed via annotation: ANNOTATIONS = {
"aws-lc-sys" : [
crate.annotation(
patches = [
Label("patch/aws-lc-sys/fix-symbol-versioning.patch")
],
patch_args = ["-p1"],
),
],
# <snipped>
}
crates_repository(
name = "crates_io",
packages = CRATES,
annotations = ANNOTATIONS,
# other fields...
)
diff --git a/builder/main.rs b/builder/main.rs
index 3619a421d1..4bebe1ac57 100644
--- a/builder/main.rs
+++ b/builder/main.rs
@@ -210,7 +210,9 @@ impl OutputLib {
const VERSION: &str = env!("CARGO_PKG_VERSION");
fn prefix_string() -> String {
- format!("aws_lc_{}", VERSION.to_string().replace('.', "_"))
+ let version = std::env::var("CARGO_PKG_VERSION")
+ .expect("CARGO_PKG_VERSION to be set when running the build script");
+ format!("aws_lc_{}", version.replace('.', "_"))
}
#[cfg(feature = "bindgen")] (which is why I never bothered to report it upstream) |
I can still reproduce this issue with a Cargo-workspace setup even if I use |
Thanks for the repro @roman-kashitsyn - #3370 should fix it! |
This was relatively tricky to figure out. We have a dependency on
aws-lc-rs
which in turn depends on a FFI wrapper calledaws-lc-sys
- it works fine building with Cargo, but if built with Bazel we get linker errors similar to this:The problem stems from this line; https://github.com/aws/aws-lc-rs/blob/aws-lc-sys/v0.25.1/aws-lc-sys/builder/main.rs#L211C1-L211C49
where they embed the version during compilation of the build script.
This depends on the version of the package being set during build rule compilation as well as build rule execution.
Strangely, it seems that CARGO_PKG_VERSION is set to 0.0.0 during
rustc
execution, otherwise this line:should've been:
aws_lc_
I could fix it by doing this:
But I assume this should be aligned with Cargo's behaviour, hence making the report.
The text was updated successfully, but these errors were encountered: