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

Explicit method to specify C/C++ standard #565

Closed
alexeyr opened this issue Nov 18, 2020 · 3 comments
Closed

Explicit method to specify C/C++ standard #565

alexeyr opened this issue Nov 18, 2020 · 3 comments

Comments

@alexeyr
Copy link
Contributor

alexeyr commented Nov 18, 2020

It would be nice to specify the standard explicitly as a method on Build, e.g. Build::new().standard("c++14"). This abstracts from difference between GCC/Clang -std= and MSVC /std:. Questions to answer:

  1. What to do if you pass gnu14 on MSVC: translate to the closest c++14 or give an error?
  2. Similarly, MSVC doesn't yet support /std:c++20 and requires /std:c++latest for C++20 features. Should standard("c++20") test if /std:c++20 works and use /std:c++latest if it isn't?
Wilfred added a commit to Wilfred/difftastic that referenced this issue Dec 5, 2021
There's no helper in the cc crate for this, but it's been proposed:
rust-lang/cc-rs#565

Hopefully will improve #67
@hikari-no-yume
Copy link
Contributor

The simplest thing you can do right now is something like this:

if build.get_compiler().is_like_msvc() {
    build.flag("/std:c++17")
} else {
    build.flag("-std=c++17")
}

But it doesn't solve the issues you mention with unusual versions…

Do you think it's be useful to have this even if it only supports the simple cases? If so, I might contribute a fix for this myself, because I need this flag for one of my projects.

@hikari-no-yume
Copy link
Contributor

I decided to just do it :) #761

@thomcc
Copy link
Member

thomcc commented Aug 17, 2023

Fixed by #761, will be in the next release.

@thomcc thomcc closed this as completed Aug 17, 2023
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

3 participants