Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a97ff75

Browse filesBrowse files
targoslemireStefanStojanovic
committed
build: add option to enable clang-cl on Windows
Most changes are gated by the `clang==1` condition to avoid breaking MSVC builds. Select C/C++ language standard with ClCompile options. This avoids passing the `-std:c++20` flag while compiling C code. Do it only under clang option to avoid breaking addons until node-gyp supports the new LanguageStandard options. Disable precompiled header configuration for now as it doesn't seem to work with clang-cl. Disable C++20 warnings emitted by the Visual Studio C++ STL. They're very noisy and not our responsibility to fix. Co-authored-by: Daniel Lemire <daniel@lemire.me> Co-authored-by: Stefan Stojanovic <stefan.stojanovic@janeasystems.com> PR-URL: #52870 Reviewed-By: Daniel Lemire <daniel@lemire.me> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 609d90b commit a97ff75
Copy full SHA for a97ff75

File tree

Expand file treeCollapse file tree

8 files changed

+120
-53
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

8 files changed

+120
-53
lines changed
Open diff view settings
Collapse file

‎common.gypi‎

Copy file name to clipboardExpand all lines: common.gypi
+26-6Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@
152152
'cflags': [ '-fPIC' ],
153153
'ldflags': [ '-fPIC' ]
154154
}],
155+
['clang==1', {
156+
'msbuild_toolset': 'ClangCL',
157+
}],
155158
],
156159
'msvs_settings': {
157160
'VCCLCompilerTool': {
@@ -240,6 +243,9 @@
240243
'cflags': [ '-fPIC', '-I<(android_ndk_path)/sources/android/cpufeatures' ],
241244
'ldflags': [ '-fPIC' ]
242245
}],
246+
['clang==1', {
247+
'msbuild_toolset': 'ClangCL',
248+
}],
243249
],
244250
'msvs_settings': {
245251
'VCCLCompilerTool': {
@@ -282,12 +288,26 @@
282288
],
283289
'msvs_settings': {
284290
'VCCLCompilerTool': {
285-
'AdditionalOptions': [
286-
'/Zc:__cplusplus',
287-
# The following option enables c++20 on Windows. This is needed for V8 v12.4+
288-
'-std:c++20',
289-
# The following option reduces the "error C1060: compiler is out of heap space"
290-
'/Zm2000',
291+
# TODO(targos): Remove condition and always use LanguageStandard options
292+
# once node-gyp supports them.
293+
'conditions': [
294+
['clang==1', {
295+
'LanguageStandard': 'stdcpp20',
296+
'LanguageStandard_C': 'stdc11',
297+
'AdditionalOptions': [
298+
'/Zc:__cplusplus',
299+
# The following option reduces the "error C1060: compiler is out of heap space"
300+
'/Zm2000',
301+
],
302+
}, {
303+
'AdditionalOptions': [
304+
'/Zc:__cplusplus',
305+
# The following option enables c++20 on Windows. This is needed for V8 v12.4+
306+
'-std:c++20',
307+
# The following option reduces the "error C1060: compiler is out of heap space"
308+
'/Zm2000',
309+
],
310+
}],
291311
],
292312
'BufferSecurityCheck': 'true',
293313
'DebugInformationFormat': 1, # /Z7 embed info in .obj files
Collapse file

‎configure.py‎

Copy file name to clipboardExpand all lines: configure.py
+14-2Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,13 @@
946946
default=None,
947947
help=argparse.SUPPRESS)
948948

949+
parser.add_argument('--clang-cl',
950+
action='store',
951+
dest='clang_cl',
952+
default=None,
953+
help='Configure for clang-cl on Windows. This flag sets the GYP "clang" ' +
954+
'variable to 1 and "llvm_version" to the specified value.')
955+
949956
(options, args) = parser.parse_known_args()
950957

951958
# Expand ~ in the install prefix now, it gets written to multiple files.
@@ -1122,8 +1129,13 @@ def get_gas_version(cc):
11221129
# quite prepared to go that far yet.
11231130
def check_compiler(o):
11241131
if sys.platform == 'win32':
1125-
o['variables']['clang'] = 0
1126-
o['variables']['llvm_version'] = '0.0'
1132+
if options.clang_cl:
1133+
o['variables']['clang'] = 1
1134+
o['variables']['llvm_version'] = options.clang_cl
1135+
else:
1136+
o['variables']['clang'] = 0
1137+
o['variables']['llvm_version'] = '0.0'
1138+
11271139
if not options.openssl_no_asm and options.dest_cpu in ('x86', 'x64'):
11281140
nasm_version = get_nasm_version('nasm')
11291141
o['variables']['nasm_version'] = nasm_version
Collapse file

‎deps/zlib/zlib.gyp‎

Copy file name to clipboardExpand all lines: deps/zlib/zlib.gyp
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
'xcode_settings': {
2929
'OTHER_CFLAGS': [ '-mssse3' ],
3030
},
31+
'msvs_settings': {
32+
'VCCLCompilerTool': {
33+
'AdditionalOptions': [ '-mssse3' ],
34+
},
35+
},
3136
}],
3237
],
3338
}],
Collapse file

‎node.gyp‎

Copy file name to clipboardExpand all lines: node.gyp
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,8 @@
610610
'msvs_settings': {
611611
'VCLinkerTool': {
612612
'AdditionalOptions': [
613-
'/WHOLEARCHIVE:<(node_lib_target_name)<(STATIC_LIB_SUFFIX)',
614-
'/WHOLEARCHIVE:<(STATIC_LIB_PREFIX)v8_base_without_compiler<(STATIC_LIB_SUFFIX)',
613+
'/WHOLEARCHIVE:<(PRODUCT_DIR)/lib/<(node_lib_target_name)<(STATIC_LIB_SUFFIX)',
614+
'/WHOLEARCHIVE:<(PRODUCT_DIR)/lib/<(STATIC_LIB_PREFIX)v8_base_without_compiler<(STATIC_LIB_SUFFIX)',
615615
],
616616
},
617617
},
Collapse file

‎node.gypi‎

Copy file name to clipboardExpand all lines: node.gypi
+12-8Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,15 @@
6565
'NODE_PLATFORM="win32"',
6666
'_UNICODE=1',
6767
],
68-
'msvs_precompiled_header': 'tools/msvs/pch/node_pch.h',
69-
'msvs_precompiled_source': 'tools/msvs/pch/node_pch.cc',
70-
'sources': [
71-
'<(_msvs_precompiled_header)',
72-
'<(_msvs_precompiled_source)',
68+
'conditions': [
69+
['clang==0', {
70+
'msvs_precompiled_header': 'tools/msvs/pch/node_pch.h',
71+
'msvs_precompiled_source': 'tools/msvs/pch/node_pch.cc',
72+
'sources': [
73+
'<(_msvs_precompiled_header)',
74+
'<(_msvs_precompiled_source)',
75+
],
76+
}],
7377
],
7478
}, { # POSIX
7579
'defines': [ '__POSIX__' ],
@@ -148,7 +152,7 @@
148152
'msvs_settings': {
149153
'VCLinkerTool': {
150154
'AdditionalOptions': [
151-
'/WHOLEARCHIVE:zlib<(STATIC_LIB_SUFFIX)',
155+
'/WHOLEARCHIVE:<(PRODUCT_DIR)/lib/zlib<(STATIC_LIB_SUFFIX)',
152156
],
153157
},
154158
},
@@ -187,7 +191,7 @@
187191
'msvs_settings': {
188192
'VCLinkerTool': {
189193
'AdditionalOptions': [
190-
'/WHOLEARCHIVE:libuv<(STATIC_LIB_SUFFIX)',
194+
'/WHOLEARCHIVE:<(PRODUCT_DIR)/lib/libuv<(STATIC_LIB_SUFFIX)',
191195
],
192196
},
193197
},
@@ -370,7 +374,7 @@
370374
'msvs_settings': {
371375
'VCLinkerTool': {
372376
'AdditionalOptions': [
373-
'/WHOLEARCHIVE:<(openssl_product)',
377+
'/WHOLEARCHIVE:<(PRODUCT_DIR)/lib/<(openssl_product)',
374378
],
375379
},
376380
},
Collapse file

‎tools/v8_gypfiles/toolchain.gypi‎

Copy file name to clipboardExpand all lines: tools/v8_gypfiles/toolchain.gypi
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@
160160
# -Wno-invalid-offsetof
161161
'GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO': 'NO',
162162
},
163+
'msvs_settings': {
164+
'VCCLCompilerTool': {
165+
'AdditionalOptions': ['-Wno-invalid-offsetof'],
166+
},
167+
},
163168
}],
164169
['v8_target_arch=="arm"', {
165170
'defines': [
@@ -536,6 +541,7 @@
536541
'WIN32',
537542
'NOMINMAX', # Refs: https://chromium-review.googlesource.com/c/v8/v8/+/1456620
538543
'_WIN32_WINNT=0x0602', # Windows 8
544+
'_SILENCE_ALL_CXX20_DEPRECATION_WARNINGS',
539545
],
540546
# 4351: VS 2005 and later are warning us that they've fixed a bug
541547
# present in VS 2003 and earlier.
Collapse file

‎tools/v8_gypfiles/v8.gyp‎

Copy file name to clipboardExpand all lines: tools/v8_gypfiles/v8.gyp
+50-34Lines changed: 50 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
'type': 'none',
4949
'toolsets': ['host', 'target'],
5050
'conditions': [
51-
['OS=="win"', {
51+
['OS=="win" and clang==0', {
5252
'direct_dependent_settings': {
5353
'msvs_precompiled_header': '<(V8_ROOT)/../../tools/msvs/pch/v8_pch.h',
5454
'msvs_precompiled_source': '<(V8_ROOT)/../../tools/msvs/pch/v8_pch.cc',
@@ -381,38 +381,6 @@
381381
'target_name': 'v8_snapshot',
382382
'type': 'static_library',
383383
'toolsets': ['target'],
384-
'conditions': [
385-
['want_separate_host_toolset', {
386-
'conditions': [
387-
['v8_target_arch=="arm64"', {
388-
'msvs_enable_marmasm': 1,
389-
}]
390-
],
391-
'dependencies': [
392-
'generate_bytecode_builtins_list',
393-
'run_torque',
394-
'mksnapshot#host',
395-
'v8_maybe_icu',
396-
# [GYP] added explicitly, instead of inheriting from the other deps
397-
'v8_base_without_compiler',
398-
'v8_compiler_for_mksnapshot',
399-
'v8_initializers',
400-
'v8_libplatform',
401-
]
402-
}, {
403-
'dependencies': [
404-
'generate_bytecode_builtins_list',
405-
'run_torque',
406-
'mksnapshot',
407-
'v8_maybe_icu',
408-
# [GYP] added explicitly, instead of inheriting from the other deps
409-
'v8_base_without_compiler',
410-
'v8_compiler_for_mksnapshot',
411-
'v8_initializers',
412-
'v8_libplatform',
413-
]
414-
}],
415-
],
416384
'sources': [
417385
'<(V8_ROOT)/src/init/setup-isolate-deserialize.cc',
418386
],
@@ -488,6 +456,54 @@
488456
],
489457
},
490458
],
459+
'conditions': [
460+
['want_separate_host_toolset', {
461+
'dependencies': [
462+
'generate_bytecode_builtins_list',
463+
'run_torque',
464+
'mksnapshot#host',
465+
'v8_maybe_icu',
466+
# [GYP] added explicitly, instead of inheriting from the other deps
467+
'v8_base_without_compiler',
468+
'v8_compiler_for_mksnapshot',
469+
'v8_initializers',
470+
'v8_libplatform',
471+
]
472+
}, {
473+
'dependencies': [
474+
'generate_bytecode_builtins_list',
475+
'run_torque',
476+
'mksnapshot',
477+
'v8_maybe_icu',
478+
# [GYP] added explicitly, instead of inheriting from the other deps
479+
'v8_base_without_compiler',
480+
'v8_compiler_for_mksnapshot',
481+
'v8_initializers',
482+
'v8_libplatform',
483+
]
484+
}],
485+
['OS=="win" and clang==1', {
486+
'actions': [
487+
{
488+
'action_name': 'asm_to_inline_asm',
489+
'message': 'generating: >@(_outputs)',
490+
'inputs': [
491+
'<(INTERMEDIATE_DIR)/embedded.S',
492+
],
493+
'outputs': [
494+
'<(INTERMEDIATE_DIR)/embedded.cc',
495+
],
496+
'process_outputs_as_sources': 1,
497+
'action': [
498+
'<(python)',
499+
'<(V8_ROOT)/tools/snapshot/asm_to_inline_asm.py',
500+
'<@(_inputs)',
501+
'<(INTERMEDIATE_DIR)/embedded.cc',
502+
],
503+
},
504+
],
505+
}],
506+
],
491507
}, # v8_snapshot
492508
{
493509
'target_name': 'v8_version',
@@ -1928,7 +1944,7 @@
19281944
}],
19291945
]
19301946
}],
1931-
['OS=="win"', {
1947+
['OS=="win" and clang==0', {
19321948
'conditions': [
19331949
['_toolset == "host" and host_arch == "x64" or _toolset == "target" and target_arch=="x64"', {
19341950
'sources': [
Collapse file

‎vcbuild.bat‎

Copy file name to clipboardExpand all lines: vcbuild.bat
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ set ltcg=
3232
set target_env=
3333
set noprojgen=
3434
set projgen=
35+
set clang_cl=
3536
set nobuild=
3637
set sign=
3738
set nosnapshot=
@@ -87,6 +88,7 @@ if /i "%1"=="arm64" set target_arch=arm64&goto arg-ok
8788
if /i "%1"=="vs2022" set target_env=vs2022&goto arg-ok
8889
if /i "%1"=="noprojgen" set noprojgen=1&goto arg-ok
8990
if /i "%1"=="projgen" set projgen=1&goto arg-ok
91+
if /i "%1"=="clang-cl" set clang_cl=1&goto arg-ok
9092
if /i "%1"=="nobuild" set nobuild=1&goto arg-ok
9193
if /i "%1"=="nosign" set "sign="&echo Note: vcbuild no longer signs by default. "nosign" is redundant.&goto arg-ok
9294
if /i "%1"=="sign" set sign=1&goto arg-ok
@@ -190,6 +192,8 @@ if defined nosnapshot set configure_flags=%configure_flags% --without-snap
190192
if defined nonpm set configure_flags=%configure_flags% --without-npm
191193
if defined nocorepack set configure_flags=%configure_flags% --without-corepack
192194
if defined ltcg set configure_flags=%configure_flags% --with-ltcg
195+
:: If clang-cl build is requested, set it to 17.0, which is the version shipped with VS 2022.
196+
if defined clang_cl set configure_flags=%configure_flags% --clang-cl=17.0
193197
if defined release_urlbase set configure_flags=%configure_flags% --release-urlbase=%release_urlbase%
194198
if defined download_arg set configure_flags=%configure_flags% %download_arg%
195199
if defined enable_vtune_arg set configure_flags=%configure_flags% --enable-vtune-profiling
@@ -750,7 +754,7 @@ set exit_code=1
750754
goto exit
751755

752756
:help
753-
echo vcbuild.bat [debug/release] [msi] [doc] [test/test-all/test-addons/test-doc/test-js-native-api/test-node-api/test-internet/test-tick-processor/test-known-issues/test-node-inspect/test-check-deopts/test-npm/test-v8/test-v8-intl/test-v8-benchmarks/test-v8-all] [ignore-flaky] [static/dll] [noprojgen] [projgen] [small-icu/full-icu/without-intl] [nobuild] [nosnapshot] [nonpm] [nocorepack] [ltcg] [licensetf] [sign] [ia32/x86/x64/arm64] [vs2022] [download-all] [enable-vtune] [lint/lint-ci/lint-js/lint-md] [lint-md-build] [format-md] [package] [build-release] [upload] [no-NODE-OPTIONS] [link-module path-to-module] [debug-http2] [debug-nghttp2] [clean] [cctest] [no-cctest] [openssl-no-asm]
757+
echo vcbuild.bat [debug/release] [msi] [doc] [test/test-all/test-addons/test-doc/test-js-native-api/test-node-api/test-internet/test-tick-processor/test-known-issues/test-node-inspect/test-check-deopts/test-npm/test-v8/test-v8-intl/test-v8-benchmarks/test-v8-all] [ignore-flaky] [static/dll] [noprojgen] [projgen] [clang-cl] [small-icu/full-icu/without-intl] [nobuild] [nosnapshot] [nonpm] [nocorepack] [ltcg] [licensetf] [sign] [ia32/x86/x64/arm64] [vs2022] [download-all] [enable-vtune] [lint/lint-ci/lint-js/lint-md] [lint-md-build] [format-md] [package] [build-release] [upload] [no-NODE-OPTIONS] [link-module path-to-module] [debug-http2] [debug-nghttp2] [clean] [cctest] [no-cctest] [openssl-no-asm]
754758
echo Examples:
755759
echo vcbuild.bat : builds release build
756760
echo vcbuild.bat debug : builds debug build

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.