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

Add a way for build scripts to be re-run if specific environment variables change #2776

Closed
luser opened this issue Jun 7, 2016 · 8 comments · Fixed by #4125
Closed

Add a way for build scripts to be re-run if specific environment variables change #2776

luser opened this issue Jun 7, 2016 · 8 comments · Fixed by #4125

Comments

@luser
Copy link
Contributor

luser commented Jun 7, 2016

I hit an error building rust-openssl, and it looks like it's not fixable without adding functionality to Cargo:
sfackler/rust-openssl#406

The build script there uses OPENSSL_{LIB,INCLUDE}_DIR as inputs, but it doesn't get re-run if those variables were unset and are later set, or if their values change.

It would be good if build scripts could tell Cargo about environment variables they use as input, and then Cargo could record the status of those env vars upon build script invocation, and use them as dependencies for re-running the build script.

@alexcrichton
Copy link
Member

Yeah this is kinda an unfortunate situation that this is in where in theory build scripts shouldn't rely on magical environment variables like this but in practice it's what ends up happening. I know that I've definitely run into this problem quite a few times and always have to remember to clean the right package, so it's definitely annoying!

cc @wycats

@zv
Copy link
Contributor

zv commented Jun 9, 2016

I seem to remember there being a POSIX API for "shimming" a fake environment and then jumping back to a procedure with the "real" environment on the stack with a setjmp.

@gkoz
Copy link
Contributor

gkoz commented Jun 10, 2016

Yeah this is kinda an unfortunate situation that this is in where in theory build scripts shouldn't rely on magical environment variables like this but in practice it's what ends up happening.

Any user of pkg-config relies on env variables (e.g. PKG_CONFIG_PATH) by extension.

@retep998
Copy link
Member

Well there currently isn't any other way to provide information to a build script, so environment variables are a necessity. This issue has bit me before, and many other people as well.

@retep998
Copy link
Member

We even have rerun-if-changed already for depending on files, so surely we can just add another key for environment variables?

@jethrogb
Copy link
Contributor

jethrogb commented Apr 4, 2017

Would love to see rerun-if-changed-env=FOO or something similar)

@alexcrichton
Copy link
Member

In theory this shouldn't be too hard to implement, so tagging E-help-wanted

@matklad
Copy link
Member

matklad commented Jun 7, 2017

What do you all think about opt-in whitelisting of environment variables, visible in build.rs (as proposed here)? That way, we'll make builds a little more deterministic, and will avoid a problem when someone (perhaps transitively) uses an env variable, but does not specify it in rerun-if-env-changed.

alexcrichton added a commit to alexcrichton/cargo that referenced this issue Jun 14, 2017
This commit implements a new method of rerunning a build script if an
environment variable changes. Environment variables are one of the primary
methods of giving inputs to a build script today, and this'll help situations
where if you change an env var you don't have to remember to clean out an old
build directory to ensure fresh results.

Closes rust-lang#2776
bors added a commit that referenced this issue Jun 15, 2017
Implement `cargo:rerun-if-env-changed=FOO`

This commit implements a new method of rerunning a build script if an
environment variable changes. Environment variables are one of the primary
methods of giving inputs to a build script today, and this'll help situations
where if you change an env var you don't have to remember to clean out an old
build directory to ensure fresh results.

Closes #2776
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants