Add CC_PREFER_CLANG_CL_OVER_MSVC environment variable to override prefer_clang_cl_over_msvc#1675
Conversation
2372f80 to
f1c838e
Compare
|
|
||
| const CC_PREFER_CLANG_CL_OVER_MSVC_ENV_VAR: &str = "CC_PREFER_CLANG_CL_OVER_MSVC"; | ||
| fn get_prefer_clang_cl_over_msvc_from_env() -> Option<bool> { | ||
| #[allow(clippy::disallowed_methods)] |
There was a problem hiding this comment.
If I understood correclty, getenv or getenv_boolean won't default to the host environment, so it's not applicable to us here as we actually want to have the host environment leak to us if I'm not mistaken.
However, how can I test that? Because tests are run in parallel, so in my current test implementation it just does not work as tests are leaking that env to one another most probably.
There was a problem hiding this comment.
Thanks I'll implement it that way for now.
Then we can discuss the following here: would it be an acceptable design for you to always propagate CC_PREFER_CLANG_CL_OVER_MSVC to self.env in the Build::new constructor?
There is two advantages to that:
- I don't have to use the
mainfunction trick in tests and rely on settingself.env - I can use
self.getenv_booleanin the implementation ofBuild
CC_FORCE_DISABLE would be under the same regime too, for example.
There was a problem hiding this comment.
I'm not entirely sure I understand the question, but you might wanna wait for #1656 before making too many bold changes to how environment variables work?
src/lib.rs
Outdated
| build_cache: Arc::default(), | ||
| inherit_rustflags: true, | ||
| prefer_clang_cl_over_msvc: false, | ||
| prefer_clang_cl_over_msvc: get_prefer_clang_cl_over_msvc_from_env().unwrap_or(false), |
There was a problem hiding this comment.
I think I'd prefer to do things at the usage site instead, something like:
let prefer_clang_cl_over_msvc_env = self.getenv_boolean("CC_PREFER_CLANG_CL_OVER_MSVC");
let msvc = if prefer_clang_cl_over_msvc_env.unwrap_or(self.prefer_clang_cl_over_msvc) {
"clang-cl.exe"
} else {
"cl.exe"
};6d7cbf4 to
24d85f2
Compare
…prefer_clang_cl_over_msvc` Fixes rust-lang#1673
24d85f2 to
5ef66da
Compare
Fixes #1673