-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Forwarding a build.rs env var and running cargo build
within the binary causes rebuilds
#12403
Comments
The first run of Not sure what you would like to achieve. Just call out the notice here in
|
Ah, I think I messed up minimising the issue, I'll look at it again tomorrow morning |
Sorry about that I changed the example at the last minute to try to make the issue clearer but ended up making it into a non issue. I've now edited the example back to what I think is an actual issue. |
Sorry for the late reply. If you set the env var, everything works as expected — Let's break down it a bit.
|
I'd say it works perfectly correct on how env changes are detected. If you can share what you were working on, we may come up with a better idea :) |
Ah! Thankyou for writing it out like that, I've now found my misunderstanding. I think we should document this on https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorerun-if-env-changedname |
Sorry I don't really understand what isn't accessible to FWIW, here is a list of environment variables Cargo sets for build scripts. |
Maybe this? - The rerun-if-env-changed instruction tells Cargo to re-run the build script if the value of an environment variable of the given name has changed.
+ The rerun-if-env-changed instruction tells Cargo to re-run the build script if the value of an environment variable of the given name that Cargo received has changed. |
I was thinking like this: The `rerun-if-env-changed` instruction tells Cargo to re-run the build script
if the value of an environment variable of the given name has changed.
Note that the environment variables here are intended for global environment
-variables like `CC` and such, it is not necessary to use this for environment
+variables like `CC` and such, it is not possible to use this for environment
variables like `TARGET` that Cargo sets.
+That is because the environment variables used are those received by cargo
+not those received by the build.rs executable. The main thing for me is that |
Hmm… now I see what you mean. Thanks for the reply! It is not necessary since Cargo already handles recompile when target changes. The What about this? Note that the environment variables here are intended for global environment
-variables like `CC` and such, it is not necessary to use this for environment
-variables like `TARGET` that Cargo sets.
+variables like `CC` and such, it is not possible to use this for environment
+variables like `TARGET` that [Cargo sets for build scripts][build-env]. The
+environment variables in use are those received by `cargo` invocations, not
+those received by the executable of the build script. (Sorry a bit picky and feel free to submit a pull request!!) |
that looks excellent, thanks for working through this with me, I'll make a PR. |
Problem
In some of my projects I do the following:
cargo build
from a test or example, this is useful for certain integration tests.However the combination of these things is causing my application to be rebuilt.
Steps
build.rs:
main.rs:
Then run
cargo run -vv
to get the following output every time it reruns:the reason for the crate being considered dirty is because
the env variable PROFILE changed
, however you can see in both the outer and inner cargo it is set to the samedebug
value.Possible Solution(s)
No response
Notes
No response
Version
The text was updated successfully, but these errors were encountered: