Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Set missing env vars from Cargo in a compilation step #337

Merged
merged 1 commit into from Jun 4, 2017

Conversation

Xanewok
Copy link
Member

@Xanewok Xanewok commented Jun 4, 2017

Fixes #290. Although this seems to fix the issue with missing env vars causing compilation failures in some projects, there may be a better way of doing that in the long-term by not having to call rustc to get dep-info, judging from the comment in code.

src/build.rs Outdated
@@ -357,6 +357,12 @@ impl BuildQueue {
cmd_dep_info.arg(a);
}
}
// Compilation may depend on env vars which Cargo sets during compile-time
for (k, v) in cmd.get_envs() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use envs to set all the env vars at once without a for loop

Copy link
Member Author

@Xanewok Xanewok Jun 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would

cmd_dep_info.envs(cmd.get_envs()
.iter()
.map(|(k, v)| (k, v.unwrap_or(OsString::from("")))));

inline be better?
I wanted to retain a value Option and couldn't think of a clean way to do it, but on a second thought providing a default value seems reasonable in this case.
EDIT: That actually doesn't work and I'm not sure how to do it cleanly 😞

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like cmd_dep_info.envs(cmd.get_envs().iter().filter_map(|k, v| v.map(|v| (k, v)))) I think

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for suggestion, didn't know how I could use filter_map with Option being one of tuple vars

@Xanewok
Copy link
Member Author

Xanewok commented Jun 4, 2017

@nrc just pushed the change to use envs instead.

@nrc nrc merged commit cbb31a5 into rust-lang:master Jun 4, 2017
@nrc
Copy link
Member

nrc commented Jun 4, 2017

Thanks!

@Xanewok Xanewok deleted the rustc-env-vars branch June 20, 2017 13:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OUT_DIR not defined
2 participants