Build script cannot set custom env by println rustc-env
Closed this issue · 1 comments
lazystitan commented
Checklist
- I've looked through the issues and pull requests for similar reports
Describe your issue
build.rs
fn main() {
let version = get_git_version();
println!("cargo:rustc-env=INNER_API_RS_V={}", version)
}
main.rs
let version = std::env::var("INNER_API_RS_V").unwrap().to_string();
error
called `Result::unwrap()` on an `Err` value: NotPresent
What target(s) are you cross-compiling for?
x86_64-unknown-linux-gnu
Which operating system is the host (e.g computer cross is on) running?
- macOS
- Windows
- Linux / BSD
- other OS (specify in description)
What architecture is the host?
- x86_64 / AMD64
- arm32
- arm64 (including Mac M1)
What container engine is cross using?
- docker
- podman
- other container engine (specify in description)
cross version
cross 0.2.5 (53a45db 2024-05-11)
Example
No response
Additional information / notes
No response
Emilgardis commented
This is working as expected, rustc-env only sets the var during compilation
https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-env
As such, its retrievable with the compile time env!
macro but not in runtime
If you have the envvar in your current shell/session you need to tell Docker to import it.
https://github.com/cross-rs/cross/blob/main/docs/config_file.md#buildenv
Im going to close this issue, if you feel like this is not correct or if you want some clarification please tell me! 😄