Skip to content

Commit f93991e

Browse files
authored
fix build on clangcl, except for v8 assembly (nodejs#9)
1. To avoid many warnings, this PR declares the C and C++ standards separately. 2. This PR extends gyp so that we can build with AVX-512. Nevertheless, getting runtime dispatching with ClangCl through Visual Studio is challenging, so we disable it. It only affects base64 and one component of zip, so the effect on runtime performance should be negligible. Note that other dependencies such as simdutf do not need to this build support for runtime dispatching (so you still get AVX2, AVX-512 support in these dependencies).
1 parent d7cc22d commit f93991e

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

common.gypi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,13 @@
284284
],
285285
'msvs_settings': {
286286
'VCCLCompilerTool': {
287+
# Node has C and C++ dependencies: we want to specify the standards
288+
# independently. Recent versions of Visual Studio support C11 and C17
289+
# https://learn.microsoft.com/en-us/cpp/overview/install-c17-support?view=msvc-170
290+
'LanguageStandard': 'stdcpp17', # can switch to stdcpp20 or better
291+
'LanguageStandard_C': 'stdc11', # can switch to stdc17 or better
287292
'AdditionalOptions': [
288293
'/Zc:__cplusplus',
289-
'-std:c++17'
290294
],
291295
'BufferSecurityCheck': 'true',
292296
'DebugInformationFormat': 1, # /Z7 embed info in .obj files

deps/base64/base64.gyp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
}],
4343

4444
# Runtime detection will happen for x86 CPUs
45-
[ 'target_arch in "ia32 x64 x32"', {
45+
# Except for ClangCL.
46+
[ 'target_arch in "ia32 x64 x32" and OS!="win"', {
4647
'defines': [
4748
'HAVE_SSSE3=1',
4849
'HAVE_SSE41=1',
@@ -159,9 +160,7 @@
159160
}, {
160161
'msvs_settings': {
161162
'VCCLCompilerTool': {
162-
'AdditionalOptions': [
163-
'/arch:AVX'
164-
],
163+
'EnableEnhancedInstructionSet': '3' # gyp uses a digit instead of a string such as 'AVX'
165164
},
166165
},
167166
}],
@@ -183,9 +182,7 @@
183182
}, {
184183
'msvs_settings': {
185184
'VCCLCompilerTool': {
186-
'AdditionalOptions': [
187-
'/arch:AVX2'
188-
],
185+
'EnableEnhancedInstructionSet': '5' # gyp uses a digit instead of a string such as 'AVX2'
189186
},
190187
},
191188
}],
@@ -207,9 +204,7 @@
207204
}, {
208205
'msvs_settings': {
209206
'VCCLCompilerTool': {
210-
'AdditionalOptions': [
211-
'/arch:AVX512'
212-
],
207+
'EnableEnhancedInstructionSet': '6' # gyp uses a digit instead of a string such as 'AVX512'
213208
},
214209
},
215210
}],

deps/zlib/zlib.gyp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717
'type': 'static_library',
1818
'conditions': [
1919
['target_arch in "ia32 x64" and OS!="ios"', {
20-
'defines': [ 'ADLER32_SIMD_SSSE3' ],
2120
'conditions': [
2221
['OS=="win"', {
2322
'defines': [ 'X86_WINDOWS' ],
2423
},{
25-
'defines': [ 'X86_NOT_WINDOWS' ],
24+
'defines': [ 'X86_NOT_WINDOWS', 'ADLER32_SIMD_SSSE3' ],
2625
}],
2726
['OS!="win" or llvm_version!="0.0"', {
2827
'cflags': [ '-mssse3' ],
@@ -40,12 +39,11 @@
4039
'direct_dependent_settings': {
4140
'conditions': [
4241
['target_arch in "ia32 x64" and OS!="ios"', {
43-
'defines': [ 'ADLER32_SIMD_SSSE3' ],
4442
'conditions': [
4543
['OS=="win"', {
4644
'defines': [ 'X86_WINDOWS' ],
4745
},{
48-
'defines': [ 'X86_NOT_WINDOWS' ],
46+
'defines': [ 'X86_NOT_WINDOWS', 'ADLER32_SIMD_SSSE3' ],
4947
}],
5048
],
5149
}],

tools/gyp/pylib/gyp/MSVSSettings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,8 @@ def _ValidateSettings(validators, settings, stderr):
579579
# Options that have the same name in MSVS and MSBuild
580580
_Same(_compile, "AdditionalIncludeDirectories", _folder_list) # /I
581581
_Same(_compile, "AdditionalOptions", _string_list)
582+
_Same(_compile, "LanguageStandard", _string)
583+
_Same(_compile, "LanguageStandard_C", _string)
582584
_Same(_compile, "AdditionalUsingDirectories", _folder_list) # /AI
583585
_Same(_compile, "AssemblerListingLocation", _file_name) # /Fa
584586
_Same(_compile, "BrowseInformationFile", _file_name)
@@ -675,6 +677,7 @@ def _ValidateSettings(validators, settings, stderr):
675677
"NoExtensions", # /arch:IA32 (vs2012+)
676678
# This one only exists in the new msbuild format.
677679
"AdvancedVectorExtensions2", # /arch:AVX2 (vs2013r2+)
680+
"AdvancedVectorExtensions512", # (vs2019+)
678681
]
679682
),
680683
)

tools/gyp/pylib/gyp/msvs_emulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ def GetCflags(self, config):
531531
cl("AdditionalOptions", prefix="")
532532
cl(
533533
"EnableEnhancedInstructionSet",
534-
map={"1": "SSE", "2": "SSE2", "3": "AVX", "4": "IA32", "5": "AVX2"},
534+
map={"1": "SSE", "2": "SSE2", "3": "AVX", "4": "IA32", "5": "AVX2", "6": "AVX512"},
535535
prefix="/arch:",
536536
)
537537
cflags.extend(

0 commit comments

Comments
 (0)