-
Notifications
You must be signed in to change notification settings - Fork 65
build: Add ClangCL profiles #791
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
base: master
Are you sure you want to change the base?
Conversation
Also fix some compilation errors catched by clang Signed-off-by: Ali Cheraghi <alichraghi@proton.me>
Signed-off-by: Ali Cheraghi <alichraghi@proton.me>
Signed-off-by: Ali Cheraghi <alichraghi@proton.me>
Signed-off-by: Ali Cheraghi <alichraghi@proton.me>
else() | ||
set_property(TARGET ${trgt} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") | ||
endif() | ||
set_property(TARGET ${trgt} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>$<$<BOOL:${NBL_COMPILER_DYNAMIC_RUNTIME}>:DLL>") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK in Clang and GCC there are options about static linking of libstd-c++
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
else() | ||
list(APPEND NBL_DXC_CMAKE_OPTIONS "-DCMAKE_MSVC_RUNTIME_LIBRARY:STATIC=MultiThreaded$<$<CONFIG:Debug>:Debug>") | ||
endif() | ||
list(APPEND NBL_DXC_CMAKE_OPTIONS "-DCMAKE_MSVC_RUNTIME_LIBRARY:STATIC=MultiThreaded$<$<CONFIG:Debug>:Debug>$<$<BOOL:${NBL_COMPILER_DYNAMIC_RUNTIME}>:DLL>") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as with the general nabla comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if(NOT NBL_COMPILER_DYNAMIC_RUNTIME) | ||
message(FATAL_ERROR "Turn NBL_COMPILER_DYNAMIC_RUNTIME on! For dynamic Nabla builds dynamic runtime is mandatory!") | ||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aah ok so we want to ban compiling with static-libstdc++
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes we agreed it must match
list(APPEND NBL_CXX_COMPILE_OPTIONS | ||
-Wextra | ||
-fno-strict-aliasing | ||
-msse4.2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mavx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you might also need a flag for stripping debug symbols
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mavx
resolved
-Wno-sequence-point | ||
-Wno-unused-parameter | ||
-Wno-unused-but-set-parameter | ||
-Wno-c++98-compat | ||
-Wno-c++98-compat-pedantic | ||
-Wno-padded | ||
-Wno-unsafe-buffer-usage | ||
-Wno-switch-enum | ||
-Wno-error=ignored-attributes | ||
-Wno-error=unused-function | ||
-Wno-error=unused-variable | ||
-Wno-error=unused-parameter | ||
-Wno-error=ignored-attributes | ||
-Wno-error=non-pod-varargs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take it that we'll remove this over time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, @YasInvolved is going to kill all warnings
-Wno-error=unused-parameter | ||
-Wno-error=ignored-attributes | ||
-Wno-error=non-pod-varargs | ||
-fno-exceptions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think we can compile without exceptions, there are some try-catch block in our code IIRC ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think we can compile without exceptions, there are some try-catch block in our code IIRC ?
resolved, -fno-exceptions
should not be there + its possible to compile with this flag but it changes runtime behaviour which we don't want (asserts)
set(NBL_CXX_RELEASE_COMPILE_OPTIONS | ||
-fexpensive-optimizations | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think O3 enables this by default ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes however -fexpensive-optimizations
is not Clang's option but GCC's
# RelWithDebInfo | ||
set(NBL_CXX_RELWITHDEBINFO_COMPILE_OPTIONS "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about O1 or something ? Alos don't you need ggdb3
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or even O2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about O1 or something ? Alos don't you need
ggdb3
?
#791 (comment) + resolved
|
||
# Debug | ||
set(NBL_CXX_DEBUG_COMPILE_OPTIONS | ||
-ggdb3 -Wall -fno-omit-frame-pointer -fstack-protector-strong |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is ggdb3
sufficient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't -g
also be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw GCC/Clang have an equivalent of ffast math that we use in MSVC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually ggdb3
doesn't exist on clang and it throws a warning about unknown arg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I swear it was a GCC / Emscripten thing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also ggdb3 is for GDB, I think on Clang one is supposed to use LLDB
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on windows ClangCL
which is Clang frontend compatible with MSVC CLI uses lld-link
linker
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\Llvm\bin>lld.exe
lld is a generic driver.
Invoke ld.lld (Unix), ld64.lld (macOS), lld-link (Windows), wasm-ld (WebAssembly) instead
# our pervious flags-set function called this, does not affect flags nor configs so I will keep it here temporary | ||
# TODO: move it out from the profile | ||
link_libraries(-fuse-ld=gold) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about incremental linking and stuff?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved, we use incremental linking
include_guard(GLOBAL) | ||
|
||
# Debug |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about macro definitions like NDEBUG
?
P.S. should MSVC even define should macros from commandline instead of configuring theminto the header?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about macro definitions like
NDEBUG
?
in theory we set them in MSVC frontend profile but we could skip doing so both for this profile & Clang since CMake sets NDEBUG
at the very beginning with CMAKE_<LANG>_FLAGS_<CONFIG>_INIT
within some defaults (ofc, it can be overwritten)
- https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/Platform/Windows-MSVC.cmake#L504
- https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/Platform/Windows-Clang.cmake#L117
instead of configuring theminto the header?
to be discussed but we already generate a set of defines which is included in nabla.h iirc, we could remove defines from CLI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a2a7e72 I stay at defining it myself though
# Debug | ||
set(NBL_C_DEBUG_COMPILE_OPTIONS | ||
-ggdb3 -Wall -fno-omit-frame-pointer -fstack-protector-strong | ||
) | ||
|
||
# Release | ||
set(NBL_C_RELEASE_COMPILE_OPTIONS | ||
-fexpensive-optimizations | ||
) | ||
|
||
# RelWithDebInfo | ||
set(NBL_C_RELWITHDEBINFO_COMPILE_OPTIONS "") | ||
|
||
# Global | ||
list(APPEND NBL_C_COMPILE_OPTIONS | ||
-Wextra | ||
-fno-strict-aliasing | ||
-msse4.2 | ||
-maes | ||
-mfpmath=sse | ||
-Wextra | ||
-Wno-sequence-point | ||
-Wno-unused-parameter | ||
-Wno-unused-but-set-parameter | ||
-Wno-c++98-compat | ||
-Wno-c++98-compat-pedantic | ||
-Wno-padded | ||
-Wno-unsafe-buffer-usage | ||
-Wno-switch-enum | ||
-Wno-error=ignored-attributes | ||
-Wno-error=unused-function | ||
-Wno-error=unused-variable | ||
-Wno-error=unused-parameter | ||
-Wno-error=ignored-attributes | ||
-Wno-error=non-pod-varargs | ||
-fno-exceptions | ||
) | ||
|
||
if(NBL_SANITIZE_ADDRESS) | ||
list(APPEND NBL_C_COMPILE_OPTIONS -fsanitize=address) | ||
endif() | ||
|
||
if(NBL_SANITIZE_THREAD) | ||
list(APPEND NBL_C_COMPILE_OPTIONS -fsanitize=thread) | ||
endif() | ||
|
||
# our pervious flags-set function called this, does not affect flags nor configs so I will keep it here temporary | ||
# TODO: move it out from the profile | ||
link_libraries(-fuse-ld=gold) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comments as for C++, maybe unify a bit with a common cmake include ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved
@@ -330,7 +330,7 @@ class IDescriptorSetLayout : public IDescriptorSetLayoutBase | |||
bindings[i].binding = i; | |||
bindings[i].type = type; | |||
bindings[i].createFlags = SBinding::E_CREATE_FLAGS::ECF_NONE; | |||
bindings[i].stageFlags = stageAccessFlags ? stageAccessFlags[i]:asset::IShader::ESS_ALL_OR_LIBRARY; | |||
bindings[i].stageFlags = stageAccessFlags ? stageAccessFlags[i]:asset::IShader::E_SHADER_STAGE::ESS_ALL_OR_LIBRARY; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hlsl::ShaderStage`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved
//! Workarounds for compiler specific bugs | ||
// MSVC 2019 is a special snowflake | ||
#if defined(_MSC_VER) && _MSC_VER>=1920 | ||
#if defined(_MSC_VER) && !defined(__clang__) && _MSC_VER>=1920 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we just ban old MSC_VER and old GCC ? and not do weird macro tricks ( or less)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can ban old compilers at header level, there are a few headers checking for compiler version and doing weird tricks so imo we should do it in another PR and delegate @YasInvolved
include/nbl/video/ISwapchain.h
Outdated
SSharedCreationParams() {} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we'll lose designated initializers with a default ctor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved, though
25>D:\repositories\DevshGraphicsProgramming\Nabla\include\nbl/video/ISwapchain.h(457,90): error : default member initializer for 'imageUsage' needed within definition of enclosing class 'ISwapchain' outside of member functions
hence we cannot
inline core::smart_refctd_ptr<ISwapchain> recreate(SSharedCreationParams params={})
and I added an overload to use default initializers
inline core::smart_refctd_ptr<ISwapchain> recreate(SSharedCreationParams params) { /*body*/ }
inline core::smart_refctd_ptr<ISwapchain> recreate() { return recreate({}); }
…er new compile errors after upgrading VS and toolsets (coming from DXC source files)
… NBL_REQUEST_COMPILE_OPTION_SUPPORT, add required instruction set features for simdjson explicitly; now I hit GLI errors due to bad templates
|
||
# also instead of enabling single options maybe we could consider requesting an | ||
# instruction implementation set instead, eg -march=haswel, though this approach | ||
# could add a few more flags then we actually need while building - to rethink |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-march
is a bad idea unless you're deploying on a particular CPU (i.e. renderfarm or amazon AWS)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-march
is a bad idea unless you're deploying on a particular CPU (i.e. renderfarm or amazon AWS)
understood, also found it too much - resolved
… (to latest and our own fork not mine, this one was 6 years old) submodules
…ons which must be passed with proxy XClang arg (they were ignored before), use NBL_REQUEST_COMPILE_OPTION_SUPPORT for Clang profile hence enforce flags validation at configure time (TODO: do the same for MSVC). It still crashes at JIT loader's cpp with -1073741819 - windooze access violation, I need to attach diagnostic outputs for LLVM team
…ngstream for generated line, make it build with Clang(CL) 19.1.1
…stem + apply workaround for CLang(CL) 19.1.1 due to error : use of undeclared label "errhandler"; for some reason if in single translation unit we have identical label names (goto) in separate function bodies we hit this error
…errors with goto statements (8f454a9)
…QUEST_COMPILE_OPTION_SUPPORT & build system to correctly handle compile & link options, validate build options at configure time
…lly specify the flag
…CMAKE_<LANG>_COMPILER_FRONTEND_VARIANT, fix issues with /DELAYLOAD & debug info format for ClangCL, use MSVC-frontend checking logic, inherit default MSVC frontend options in Clang profile if using Windows' ClangCL; upgrade minimum CMake version to 3.31
…use hlsl::ShaderStage in IDescriptorSetLayout.h
…without need to specify debug format flags with ClangCL by hand, enforce ProgramDatabase regardless the case (https://gitlab.kitware.com/cmake/cmake/-/issues/26879#note_1649970)
Also fix some compilation errors catched by clang
Description
Testing
TODO list: