Skip to content
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

Build scripts don't rerun if [env] in config.toml is changed #14350

Closed
Radbuglet opened this issue Aug 4, 2024 · 1 comment
Closed

Build scripts don't rerun if [env] in config.toml is changed #14350

Radbuglet opened this issue Aug 4, 2024 · 1 comment
Labels
A-build-scripts Area: build.rs scripts A-environment-variables Area: environment variables A-rebuild-detection Area: rebuild detection and fingerprinting C-bug Category: bug

Comments

@Radbuglet
Copy link

Radbuglet commented Aug 4, 2024

Problem

Build scripts should automatically re-run if environment variables registered with cargo::rerun-if-env-changed directives change. While this feature works well with environment variables inherited by the cargo process, it doesn't work with environment variables provided by the [env] section of a cargo.toml file.

Steps

Here's my .cargo/config.toml:

[env]
MY_ENV_VAR = "value 1"

...here's my build.rs:

println!("cargo::warning={:?}", std::env::var("MY_ENV_VAR").ok());
println!("cargo::rerun-if-env-changed=MY_ENV_VAR");

...and here's a sample shell session:

$ cargo clean
     Removed 0 files
$ cargo build
   Compiling foo v0.1.0 (/Users/riley/Desktop/foo)
warning: [email protected]: Some("value 1")
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.98s
$ # `MY_ENV_VAR` in `config.toml` updated to "value 2"
$ cargo build
warning: [email protected]: Some("value 1")
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.03s
$ cargo clean
     Removed 59 files, 2.1MiB total
$ cargo build
   Compiling foo v0.1.0 (/Users/riley/Desktop/foo)
warning: [email protected]: Some("value 2")
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.45s

Possible Solution(s)

No response

Notes

Profile environment variables are not read until apply_env_config is ran since that function is the sole caller of GlobalContext::env_config() and that's the only method which references the EnvConfig type. Perhaps only the process environment was processed at a previous step?

Version

cargo 1.80.0 (376290515 2024-07-16)
release: 1.80.0
commit-hash: 37629051518c3df9ac2c1744589362a02ecafa99
commit-date: 2024-07-16
host: aarch64-apple-darwin
libgit2: 1.7.2 (sys:0.18.3 vendored)
libcurl: 8.4.0 (sys:0.4.72+curl-8.6.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Mac OS 14.3.1 [64-bit]
@Radbuglet Radbuglet added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Aug 4, 2024
@weihanglo
Copy link
Member

Thanks for the report and reproduction example. This is a duplicate of #10358, and we have #14058. Close in favor of those.

@weihanglo weihanglo closed this as not planned Won't fix, can't repro, duplicate, stale Aug 4, 2024
@weihanglo weihanglo added A-rebuild-detection Area: rebuild detection and fingerprinting A-build-scripts Area: build.rs scripts A-environment-variables Area: environment variables and removed S-triage Status: This issue is waiting on initial triage. labels Aug 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-scripts Area: build.rs scripts A-environment-variables Area: environment variables A-rebuild-detection Area: rebuild detection and fingerprinting C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants