Skip to content

add parallel flag depending on cmake version. As well as MP flag for VS #107

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

Merged
merged 4 commits into from
Dec 3, 2020
Merged

Conversation

MoAlyousef
Copy link
Contributor

No description provided.

@MoAlyousef MoAlyousef mentioned this pull request Dec 1, 2020
@@ -718,7 +718,7 @@ impl Config {
parallel_flags = Some(format!("-j{}", s));
}
Some(ref g) if g.contains("Visual Studio") => {
parallel_flags = Some(format!("/m:{}", s));
parallel_flags = Some(format!("/MP{}", s));
Copy link
Member

Choose a reason for hiding this comment

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

To confirm, you've seen this have parallelized effects locally for yourself? I'm not sure how cmake invokes cl.exe but it looks like this only works if cl.exe is fed multiple files at once? I'm also not sure what the previous /m option was actually...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I haven't come across the m flag before personally.

src/lib.rs Outdated
} else {
let cmake_version = cmake_version();
if cmake_version.0 >= 3 && cmake_version.1 > 12 {
parallel_flags = Some(String::from("--parallel"));
Copy link
Member

Choose a reason for hiding this comment

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

Is --parallel super new? Ideally we wouldn't do a version check since that's an extra process and can take some time, but it's not the end of the world.

Copy link
Member

Choose a reason for hiding this comment

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

Also, to clarify, I think this only gets run outside of Cargo's build scripts since Cargo should always set NUM_JOBS, but are you using the cmake crate in that style?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since cmake 3.12. I use it the cmake crate with 2 other crates of mine. fltk-rs and soloud-rs. For soloud, the c++ code base is small so it builds fast. But with fltk I had noticed slower build times when building on windows-msvc. Manually passing NUM_JOBS didn't seem to help much. So I think it's the m flag thing.

src/lib.rs Outdated
let version = String::from_utf8_lossy(&cmd.stdout);
let version: Vec<&str> = version.split_whitespace().collect();
let version: Vec<&str> = version[2].split(".").collect();
let version: Vec<u8> = version.iter().map(|c| c.parse().unwrap()).collect();
Copy link
Member

Choose a reason for hiding this comment

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

I think these .unwrap() will want to go away and we'll want to return an Option from this function to avoid panicking if something goes wrong here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I can remove this if things work out with the MP flag.
Looking at the microsoft docs, the m flag doesn't seem to be listed:
https://docs.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-alphabetically?view=msvc-160

@alexcrichton
Copy link
Member

Ok looks reasonable to me, thanks!

@alexcrichton alexcrichton merged commit dee2a1b into rust-lang:master Dec 3, 2020
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 this pull request may close these issues.

2 participants