-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
cargo:rerun-if-env-changed
doesn't work with env
configuration
#10358
Comments
This is somehow similar to #10094. Cargo does not take into account the new configurable-env when calculating local fingerprint of cargo/src/cargo/core/compiler/fingerprint.rs Lines 1571 to 1577 in 07e9d46
When dealing with this issue, perhaps we should consider corner cases mentioned it this comment as well. |
To share my experience: This is a really nasty bug. We finally found this issue and are now aware of it, but we actually faced this issue often in the past, e.g. when configuring logging levels by the Looks like a small thing, but should be of high priority, I think - maybe add a warning? |
+1. Kept debugging and debugging, just to end up finding this issue. Cargo doesn't compile with the right envs as the configuration file writes, quite annoying and tricky... |
If I understand correctly, this shares the same root cause with #12434. Just two different ways to get hurt by the bug. |
Copying my comment in #12434 (comment):
However, there are at least two hard things needing to consider.
|
I ran into this today, this is quite troublesome and rather annoying. |
Also just ran into this while building a Rust-Ruby library using rb-sys. |
The problem seemed very annoying and lingered for a relatively long time. I've looked into it today, and I'm not sure if it's the optimal solution: I think this modification has the least impact, but what I'm not sure about is whether it has any impact on the overall plan for |
Ran into this issue today, and took a while to figure out why things where not working correctly. Regarding your question about the config-relative paths. Rebuilding more often then absolutely needed is in my opinion preferably over not rebuilding when things have changed. And this could be solved in two steps. First the absolute path is used and we accept the fact that if a user moves the directory around a rebuild will occur. This seams like minor inconvenience, and later upgrade to make handling of config-relative paths more efficient. |
Keep in mind that for a lot of CIs, every build is in a unique directory so this would preclude CI caching until its fixed.
And, if its determined that we can fix it later in a compatible way, then doing this incrementally is preferred so long as it doesn't affect people not using this feature. |
For the quick fix I'm assuming its possible to add the value of the ENV var to the fingerprint. And that it would only trigger a rebuild of the libraries that use that environment variable. But let me know if I'm wrong here. Looking at the code in fingerprint/mod.rs the compile produces a .d file that contains the env variables used ( Edit:
And as can be seen, it only tries to find the environment variable in the process environment variables and does not look at the configuration. (Wonder if this also means that the cargo::rustc-env=VAR=VALUE in combination with the "rerun-if-env-changed" will not work correctly)
My assumption is that we would need to change the And this is basically what @weihanglo already commented ... |
Problem
When a
build.rs
script emitscargo:rerun-if-env-changed
, it is not re-run when the value of the specified variable is changed via theenv
configuration.Steps
build.rs
:.cargo/config.toml
:cargo build
, it succeeds..cargo/config.toml
to this:cargo build
again, and it uses the cached build and succeeds. It should runbuild.rs
again, and it should fail.Workaround
FOO=bar cargo build
, ignore the result.cargo build
again, now it runsbuild.rs
withFOO=bad
from the config and fails as expected.Possible Solution(s)
No response
Notes
No response
Version
The text was updated successfully, but these errors were encountered: