Skip to content

Proper way to use rerun-if-env-changed? #5630

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

Closed
eberkund opened this issue Jun 12, 2018 · 8 comments
Closed

Proper way to use rerun-if-env-changed? #5630

eberkund opened this issue Jun 12, 2018 · 8 comments

Comments

@eberkund
Copy link

What the proper way of using rerun-if-env-changed? I am using a library where I am trying to pass in an env var from my application build.rs using cargo:rustc-env but the problem is the library which depends on the env var fails before it can be rerun. If set the env var prior or if I change the code around in the library then it can compile fine. Just not sure what the intended use case is.

@Eh2406
Copy link
Contributor

Eh2406 commented Jun 26, 2018

I am sorry, I don't quite understand the problem you are hitting. Can you post a minimal reproducible example? Then maybe we can figure out if rerun-if-env-changed is relevant, and how to improve its documentation.

@eberkund
Copy link
Author

eberkund commented Jul 1, 2018

Okay, well this is the 3rd party package which I was talking about: https://github.com/pedrosland/mmal-sys/blob/master/build.rs

The libs are not located in the default path it panics which means it never gets to be rerun since the build stops on a panic.

So I was wondering what is the proper way to communicate this error (not being able to find the libs) while also maintaining compatibility with overriding and rerunning the build script?

@ishitatsuyuki
Copy link
Contributor

See also: rust-lang/rfcs#2391

@Eh2406
Copy link
Contributor

Eh2406 commented Jul 2, 2018

So let me see if I understand. Your code depends on mmal-sys. mmal-sys uses env:MMAL_INCLUDE_DIR and panics if not set correctly. So you want to set env:MMAL_INCLUDE_DIR to the correct value in your build.rs and then have mmal-sys see the value you set. However this is not working, as your build.rs only gets run after your dependencies are built, and mmal-sys panics leading to your build.rs never being run to fix the env:MMAL_INCLUDE_DIR. Do I understand correctly?

@eberkund
Copy link
Author

eberkund commented Jul 2, 2018

@Eh2406 That is exactly correct.

@Eh2406
Copy link
Contributor

Eh2406 commented Jul 2, 2018

I don't think a build.rs can affect the environment for its dependencies. But I am not an expert on this part of the code. @alexcrichton, @jsgf, @matklad Am I correct about this?

If you are building a final artifact than you may need to have a build system around cargo to set the env before the build starts.
If you are building a library you may want to document that the env needs to be set up for your dependencies.
Alternatively if you think it is widely usable you could make a PR to mmal-sys to make it better at finding the correct value.

@alexcrichton
Copy link
Member

@Eh2406 you are indeed correct! This is something that'll need to be set by an outer build system rather than a crate

@eberkund
Copy link
Author

eberkund commented Jul 3, 2018

Okay, thank you for the info everyone.

@eberkund eberkund closed this as completed Jul 3, 2018
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

No branches or pull requests

4 participants