FASTBuild+clang-cl combo emits warnings which Ninja+clang-cl combo doesn't emit with same everything

With the long awaited addition of FASTBuild to the list of supported generators we wanted to transition our game engine from Ninja+clang-cl setup to FASTBuild+clang-cl setup to leverage that sweet distributed compilation on Windows, while preserving our CMake setup.

One of our dependencies failed to build. As I was getting deep in the rabbit hole it was my disappointment to find out that all the signs lead to a bug in CMake’s FASTBuild generator.

CMake version: 4.3.1
FASTBuild version: 1.19
Compiler: clang-cl 19.1.1; x86_64-pc-windows-msvc
OS: Windows 10 Pro, 10.0.19045
Env: x64 Native Tools Command Prompt for VS 2022

Everything boils down to a fact that build with FASTBuild+clang-cl generates warnings, that it shouldn’t generate. The warnings aren’t generated when building with Ninja+clang-cl, or even with FASTBuild+MSVC 19.44.35207 (Visual Studio 2022 Community, version 17.14.28)

The dependency has /WX flag, which basically treats all compiler warnings as errors.

The reproduction steps are following:

1. git clone https://github.com/nicebyte/nicegraf # fantastic library if you're doing graphics btw
2. cd nicegraf
3. cmake -S . -B build-fastbuild -G "FASTBuild" -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_LINKER=lld-link
4. cmake --build build-fastbuild --clean-first # FAILS
5. cmake -S . -B build-ninja -G "Ninja" -DCMAKE_C_COMPILER=clang-cl -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_LINKER=lld-link
6. cmake --build build-ninja --clean-first # SUCCEEDS

If you followed the steps correctly, you should get roughly 126 warnings on SPIRV-reflect target – which doesn’t terminate the build – and 7 errors on nicegraf-vk target – which terminates the build. Errors is casued by-Werror,-Wpointer-bool-conversion warning.

I know that I can just turn off the warnings for that specific target, but that is a temporary solution and I suppose I ask here, before I open an issue on the CMake repo. Thanks.

edit: Added a missing command for repro steps

Cc: @Eduard_Voronkin

I can reproduce this, and the failing command lines have the form

>clang-cl /WX -c example.c /E
clang-cl: error: argument unused during compilation: '-c' [-Werror,-Wunused-command-line-argument]

The fbuild.bff generated by CMake has no mention of the /E flag, so it seems to be something fbuild is adding.

Thanks for the hint, I didn’t notice that flag at all.

Inside FASTBuild - Function Reference - Compiler section .ClangRewriteIncludes, I found following sentance

FASTBuild uses the -E preprocessor option when compiling with Clang to preprocess the source code. In order to improve consistency between this preprocessed source and the original source, FASTBuild also uses the -frewrite-includes option by default.

Inside Clang Compiler User’s Manual section Command-Line Options the -E flag is described as

-E, --preprocess

Only run the preprocessor

So, if understand correctly the warnings are an artifact from macro expansion. Ninja knows it’s a macro expansion and suppresses the warnings. In case of FASTBuild, however, that information is lost, because the input is first preprocessed and the output is supplied to the clang, so it flags them as legit warnings.

It seems that the -E flag is engraved in FASTBuild pipeline when using Clang and I cannot disable it. Furthermore, it’s not a CMake issue per se, because it correctly generates the fbuild.bff file. Two pragmatic options are either to fix the dependency itself or disable the warning. I am not sure which side should address this CMake or FASTBuild, but for me it suffices to know the root cause.

Hey @brad.king

I have hit another wall with FBuild generator and clang-cl which made me return to this discussion. I didn’t notice argument unused during compilation: '-c' warning which you mentioned before, because I didn’t get it on my local machine due to Clang’s long-standing driver bug/workaround. Basically, clang would not warn about -c misuse and they fixed it in Clang 20.0+.

So, the issue was always there and FBuild generator would provide -c flag to preprocessor and render it unused, but it didn’t warn. After I updated to clang version 22.1.4 I got the same error output as you did.

So I believe this is another FBuild generator bug and I don’t know what to do about it.

Regarding the original issue, I believe you will receive the same error output as me if you downgrade your clang version to 19.x.

edit: fixed url formatting

These problems doesn’t seem to be related to CMake’s generator at all.

FASTBuild is not just a build tool, it includes some caching (like ccache/sccache) and distributed build mechanism. And because of that, it does not just compile the source as instructed, but also preprocesses it (and maybe other stuff) on its own.

CMake’s generator makes it possible to disable those mechanisms per target: FASTBUILD_CACHING and FASTBUILD_DISTRIBUTION
This should just compile those files on your local machine, and avoids all your problems.

If it does, then fixing the problems is on FASTBuild’s side, as they incorrectly manipulate the command line for their extra steps.

Hey Josef, thanks for reply.

FASTBuild has caching and distributed compilation disabled by default, which is the case in my repro steps, yet the build fails.