-
Notifications
You must be signed in to change notification settings - Fork 570
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
Add support for building with clang-cl #4255
base: master
Are you sure you want to change the base?
Changes from all commits
628f915
6729c44
dbfd7f9
472c6fd
e594267
48aaba9
ce51e6e
dbaf2a6
390a93c
cce2b6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
macro_name CLANGCL | ||
|
||
minimum_supported_version 14.0 | ||
|
||
binary_name clang-cl | ||
linker_name lld-link | ||
|
||
output_to_object "/Fo" | ||
output_to_exe "/OUT:" | ||
|
||
add_include_dir_option "/I" | ||
add_system_include_dir_option "/external:W0 /external:I" | ||
add_lib_dir_option "/LIBPATH:" | ||
add_compile_definition_option "/D" | ||
add_lib_option "%s.lib" | ||
|
||
compile_flags "/nologo /c" | ||
|
||
supports_gcc_inline_asm yes | ||
|
||
optimization_flags "/O2 /Oi" | ||
size_optimization_flags "/O1 /Os" | ||
|
||
# for debug info in the object file (required if using sccache): | ||
#debug_info_flags "/Z7" | ||
|
||
# for using a PDB file: | ||
debug_info_flags "/Zi /FS" | ||
|
||
preproc_flags "/nologo /EP" | ||
|
||
lang_flags "/std:c++20 /EHs /GR" | ||
solemnwarning marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# 4251: STL types used in DLL interface | ||
# 4275: ??? | ||
# 5072: ASan without debug info | ||
warning_flags "/W4 /wd4251 /wd4275 /wd5072" | ||
|
||
werror_flags "/WX" | ||
|
||
visibility_build_flags "/DBOTAN_DLL=__declspec(dllexport)" | ||
visibility_attribute "__declspec(dllimport)" | ||
|
||
# Include dependency tracking for Ninja | ||
# See: https://ninja-build.org/manual.html#ref_headers | ||
ninja_header_deps_style 'msvc' | ||
header_deps_flag '/showIncludes' | ||
|
||
ar_command lib | ||
ar_options "/nologo" | ||
ar_output_to "/OUT:" | ||
|
||
<sanitizers> | ||
default -> address | ||
|
||
iterator -> "/D_ITERATOR_DEBUG_LEVEL=1" | ||
address -> "/fsanitize=address" | ||
</sanitizers> | ||
|
||
<isa_flags> | ||
sse2 -> "-msse2" | ||
ssse3 -> "-mssse3" | ||
sse41 -> "-msse4.1" | ||
sse42 -> "-msse4.2" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that there's a pull request that removes explicit (but unused) support for SSE 4.2. This will likely cause issues on master. Please rebase your patch onto master |
||
avx2 -> "-mavx2" | ||
avx512 -> "-mavx512f -mavx512bw -mavx512dq -mavx512vbmi -mavx512vbmi2 -mavx512bitalg -mavx512vl -mavx512ifma" | ||
|
||
bmi2 -> "-mbmi -mbmi2" | ||
aesni -> "-maes -mpclmul" | ||
rdrand -> "-mrdrnd" | ||
rdseed -> "-mrdseed" | ||
sha -> "-msha" | ||
altivec -> "-maltivec" | ||
|
||
arm64:armv8crypto -> "-march=armv8+crypto" | ||
arm64:armv8sha512 -> "-march=armv8.2-a+sha3" | ||
|
||
arm32:neon -> "-mfpu=neon" | ||
arm64:neon -> "" | ||
</isa_flags> | ||
|
||
<lib_flags> | ||
debug -> "/Fd%{build_dir}/%{libname}.pdb" | ||
</lib_flags> | ||
|
||
<so_link_commands> | ||
default -> "{linker} /DLL" | ||
default-debug -> "{linker} /DLL /DEBUG" | ||
</so_link_commands> | ||
|
||
<binary_link_commands> | ||
default -> "{linker}" | ||
default-debug -> "{linker} /DEBUG" | ||
</binary_link_commands> | ||
|
||
<mach_abi_linking> | ||
all -> "/bigobj" | ||
|
||
# These can be overridden with --msvc-runtime option | ||
rt -> "/MD" | ||
rt-debug -> "/MDd" | ||
</mach_abi_linking> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* configure.py to determine the compilers version number. | ||
*/ | ||
|
||
#if defined(_MSC_VER) | ||
#if defined(_MSC_VER) and !defined(__clang__) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this cause us to detect the compiler as
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This detects the version only. Guessing the compiler happens before even "running" the detect_version.cpp procedure.. That said:
Right now, I wouldn't be surprised if the configure script would only pick up clang-cl when it is asked to do so explicitly. |
||
|
||
/* | ||
_MSC_VER Defined as an integer literal that encodes the major and | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ LANG_EXE_FLAGS = %{cc_lang_binary_linker_flags} | |
CXXFLAGS = %{cc_compile_flags} | ||
WARN_FLAGS = %{cc_warning_flags} | ||
|
||
LDFLAGS = %{ldflags} %{cc_compile_flags} | ||
LDFLAGS = %{ldflags} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
EXE_LINK_CMD = %{exe_link_cmd} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,14 @@ | |
#define CK_DECLARE_FUNCTION(returnType, name) returnType name | ||
#endif | ||
|
||
#if defined(_MSC_VER) | ||
/* When building with clang-cl, specifying this with dllimport causes a warning when defining the | ||
* CK_C_XXX function pointer types in pkcs11.h: | ||
* | ||
* 'dllimport' attribute only applies to functions, variables, classes, and Objective-C interfaces | ||
* | ||
* I'm not convinced the dllimport is needed/approproate for typedefs under MSVC either. | ||
*/ | ||
#if 0 // defined(_MSC_VER) | ||
#define CK_DECLARE_FUNCTION_POINTER(returnType, name) returnType __declspec(dllimport)(*name) | ||
#else | ||
#define CK_DECLARE_FUNCTION_POINTER(returnType, name) returnType(*name) | ||
reneme marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
@@ -40,7 +47,7 @@ | |
#pragma pack(push, cryptoki, 1) | ||
#endif | ||
|
||
#include "pkcs11.h" | ||
#include <pkcs11.h> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can imagine the quote-based include might have been on purpose here. We do ship the upstream pkcs11 headers in the same include directory. There might be a case for preferring those over some system-provided ones. @randombit? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not recall the reasoning on this one. I guess if we end up picking up a system provided header that's ok as long as it's recent enough. |
||
|
||
#if defined(_MSC_VER) | ||
#pragma pack(pop, cryptoki) | ||
|
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.
These shenanigans seem to suggest that we might end up with something that builds in CI but not on a developers machine, which isn't helpful. Is the issue here that Clang really dislikes
/MD
/etc during the link step?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 I'm recalling correctly,
link.exe
ignores (and warns on) those flags, whilelld-link.exe
errors on them.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.
This is relevant to #4424.