Skip to content

Conversation

cwshugg
Copy link

@cwshugg cwshugg commented Nov 14, 2024

While the ability to build libfuzzer-sys on Windows systems is already supported and does indeed work, there are certain build environments on Windows where the C++17 standard is not chosen by default. When this happens, errors like this may occur during build:

libfuzzer\FuzzerLoop.cpp(802): error C2039: 'clamp': is not a member of 'std'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\include\mutex(29): note: see declaration of 'std'
libfuzzer\FuzzerLoop.cpp(802): error C3861: 'clamp': identifier not found

The C++17 standard is selected in the current build.rs script, but because it's written in GCC-friendly syntax (-std=c++17), MSVC ignores it and doesn't apply the preference (warning D9002):

cl : Command line warning D9002 : ignoring unknown option '-std=c++17'

This PR adds code that checks for builds on a Windows system and instead uses the MSVC-friendly syntax (/std:c++17). When not on Windows, the original -std=c++17 is still used. (See this page for information on the MSVC /std option.)

Temporary Workaround for Devs

For anyone else facing this issue, a temporary workaround is to set the CL environment variable to specify the /std:c++17 argument; this will pass it to the compiler. (See here for more information)

$env:CL = "/std:c++17"

…han '-std=c++17'. MSVC ignores the Linux-friendly syntax and does not apply the C++ standard preference
@nagisa
Copy link
Member

nagisa commented Nov 25, 2024

Using cfg! here is incorrect. That said #127 implements an alternative approach that's simpler, less error prone and actually takes advantage of APIs made available to us since the last time the relevant code has been changed. I'm inclined to close this change as a result.

@cwshugg
Copy link
Author

cwshugg commented Nov 27, 2024

Hey @nagisa - thanks for the review and the correct solution. Good to know that cc::Build has a function specifically for setting the C/C++ standard. I'll close this.

@cwshugg cwshugg closed this Nov 27, 2024
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