bazelbuild / rules_rust

Rust rules for Bazel
https://bazelbuild.github.io/rules_rust/
Apache License 2.0
648 stars 399 forks source link

Environment variables Cargo sets for crates #2667

Open n1ght-hunter opened 1 month ago

n1ght-hunter commented 1 month ago

when building with cargo these env variables are injected for crates to use. https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates currently rust rules injects some of them if they exist. To work better with rust crates they all need injecting with an empty string unless the value is read from the cargo toml. many crates use the env!() macro to get these values and wont compile if they dont exist but are fine if they are an empty string

illicitonion commented 1 month ago

For third-party rust crates, I think we should modify cargo-bazel to set these to their actual values which we should be able to extract from the cargo metadata output or Cargo.toml file for the crate, by setting the build_script_env attribute in the generated BUILD files. I agree that empty string fallbacks if it can't be read could be useful.