Skip to content

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

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open

build: Add ClangCL profiles #791

wants to merge 25 commits into from

Conversation

alichraghi
Copy link
Contributor

Also fix some compilation errors catched by clang

Description

Testing

TODO list:

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>
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>")

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++

Copy link
Member

Choose a reason for hiding this comment

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

yes there are and this property has effect only if MSVC ABI is the target

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>")

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

Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines +38 to 40
if(NOT NBL_COMPILER_DYNAMIC_RUNTIME)
message(FATAL_ERROR "Turn NBL_COMPILER_DYNAMIC_RUNTIME on! For dynamic Nabla builds dynamic runtime is mandatory!")
endif()

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++

Copy link
Member

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

Choose a reason for hiding this comment

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

mavx

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

Copy link
Member

Choose a reason for hiding this comment

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

mavx

resolved

Comment on lines 24 to 37
-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

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?

Copy link
Member

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

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 ?

Copy link
Member

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)

Comment on lines 9 to 11
set(NBL_CXX_RELEASE_COMPILE_OPTIONS
-fexpensive-optimizations
)

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 ?

Copy link
Member

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

Comment on lines 13 to 14
# RelWithDebInfo
set(NBL_CXX_RELWITHDEBINFO_COMPILE_OPTIONS "")

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 ?

Choose a reason for hiding this comment

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

or even O2

Copy link
Member

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

Choose a reason for hiding this comment

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

is ggdb3 sufficient?

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?

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

Copy link
Member

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

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

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

Copy link
Member

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

Comment on lines 49 to 51
# 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)

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?

Copy link
Member

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

Comment on lines 1 to 3
include_guard(GLOBAL)

# Debug

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?

Copy link
Member

@AnastaZIuk AnastaZIuk Apr 18, 2025

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)

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

Copy link
Member

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

Comment on lines 3 to 51
# 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)

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 ?

Copy link
Member

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;

Choose a reason for hiding this comment

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

hlsl::ShaderStage`

Copy link
Member

Choose a reason for hiding this comment

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

resolved

Comment on lines 82 to +84
//! 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

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)

Copy link
Member

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

Comment on lines 24 to 25
SSharedCreationParams() {}

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

Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

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)

Copy link
Member

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
…QUEST_COMPILE_OPTION_SUPPORT & build system to correctly handle compile & link options, validate build options at configure time
…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)
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.

3 participants