mirror of
https://github.com/nodejs/node.git
synced 2025-04-28 21:46:48 +00:00
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: https://github.com/nodejs/node/pull/52870 Reviewed-By: Daniel Lemire <daniel@lemire.me> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
parent
dcd8b82e15
commit
efa63f3d05
32
common.gypi
32
common.gypi
@ -152,6 +152,9 @@
|
|||||||
'cflags': [ '-fPIC' ],
|
'cflags': [ '-fPIC' ],
|
||||||
'ldflags': [ '-fPIC' ]
|
'ldflags': [ '-fPIC' ]
|
||||||
}],
|
}],
|
||||||
|
['clang==1', {
|
||||||
|
'msbuild_toolset': 'ClangCL',
|
||||||
|
}],
|
||||||
],
|
],
|
||||||
'msvs_settings': {
|
'msvs_settings': {
|
||||||
'VCCLCompilerTool': {
|
'VCCLCompilerTool': {
|
||||||
@ -240,6 +243,9 @@
|
|||||||
'cflags': [ '-fPIC', '-I<(android_ndk_path)/sources/android/cpufeatures' ],
|
'cflags': [ '-fPIC', '-I<(android_ndk_path)/sources/android/cpufeatures' ],
|
||||||
'ldflags': [ '-fPIC' ]
|
'ldflags': [ '-fPIC' ]
|
||||||
}],
|
}],
|
||||||
|
['clang==1', {
|
||||||
|
'msbuild_toolset': 'ClangCL',
|
||||||
|
}],
|
||||||
],
|
],
|
||||||
'msvs_settings': {
|
'msvs_settings': {
|
||||||
'VCCLCompilerTool': {
|
'VCCLCompilerTool': {
|
||||||
@ -282,12 +288,26 @@
|
|||||||
],
|
],
|
||||||
'msvs_settings': {
|
'msvs_settings': {
|
||||||
'VCCLCompilerTool': {
|
'VCCLCompilerTool': {
|
||||||
'AdditionalOptions': [
|
# TODO(targos): Remove condition and always use LanguageStandard options
|
||||||
'/Zc:__cplusplus',
|
# once node-gyp supports them.
|
||||||
# The following option enables c++20 on Windows. This is needed for V8 v12.4+
|
'conditions': [
|
||||||
'-std:c++20',
|
['clang==1', {
|
||||||
# The following option reduces the "error C1060: compiler is out of heap space"
|
'LanguageStandard': 'stdcpp20',
|
||||||
'/Zm2000',
|
'LanguageStandard_C': 'stdc11',
|
||||||
|
'AdditionalOptions': [
|
||||||
|
'/Zc:__cplusplus',
|
||||||
|
# The following option reduces the "error C1060: compiler is out of heap space"
|
||||||
|
'/Zm2000',
|
||||||
|
],
|
||||||
|
}, {
|
||||||
|
'AdditionalOptions': [
|
||||||
|
'/Zc:__cplusplus',
|
||||||
|
# The following option enables c++20 on Windows. This is needed for V8 v12.4+
|
||||||
|
'-std:c++20',
|
||||||
|
# The following option reduces the "error C1060: compiler is out of heap space"
|
||||||
|
'/Zm2000',
|
||||||
|
],
|
||||||
|
}],
|
||||||
],
|
],
|
||||||
'BufferSecurityCheck': 'true',
|
'BufferSecurityCheck': 'true',
|
||||||
'DebugInformationFormat': 1, # /Z7 embed info in .obj files
|
'DebugInformationFormat': 1, # /Z7 embed info in .obj files
|
||||||
|
16
configure.py
16
configure.py
@ -946,6 +946,13 @@ parser.add_argument('-C',
|
|||||||
default=None,
|
default=None,
|
||||||
help=argparse.SUPPRESS)
|
help=argparse.SUPPRESS)
|
||||||
|
|
||||||
|
parser.add_argument('--clang-cl',
|
||||||
|
action='store',
|
||||||
|
dest='clang_cl',
|
||||||
|
default=None,
|
||||||
|
help='Configure for clang-cl on Windows. This flag sets the GYP "clang" ' +
|
||||||
|
'variable to 1 and "llvm_version" to the specified value.')
|
||||||
|
|
||||||
(options, args) = parser.parse_known_args()
|
(options, args) = parser.parse_known_args()
|
||||||
|
|
||||||
# Expand ~ in the install prefix now, it gets written to multiple files.
|
# Expand ~ in the install prefix now, it gets written to multiple files.
|
||||||
@ -1122,8 +1129,13 @@ def get_gas_version(cc):
|
|||||||
# quite prepared to go that far yet.
|
# quite prepared to go that far yet.
|
||||||
def check_compiler(o):
|
def check_compiler(o):
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
o['variables']['clang'] = 0
|
if options.clang_cl:
|
||||||
o['variables']['llvm_version'] = '0.0'
|
o['variables']['clang'] = 1
|
||||||
|
o['variables']['llvm_version'] = options.clang_cl
|
||||||
|
else:
|
||||||
|
o['variables']['clang'] = 0
|
||||||
|
o['variables']['llvm_version'] = '0.0'
|
||||||
|
|
||||||
if not options.openssl_no_asm and options.dest_cpu in ('x86', 'x64'):
|
if not options.openssl_no_asm and options.dest_cpu in ('x86', 'x64'):
|
||||||
nasm_version = get_nasm_version('nasm')
|
nasm_version = get_nasm_version('nasm')
|
||||||
o['variables']['nasm_version'] = nasm_version
|
o['variables']['nasm_version'] = nasm_version
|
||||||
|
5
deps/zlib/zlib.gyp
vendored
5
deps/zlib/zlib.gyp
vendored
@ -28,6 +28,11 @@
|
|||||||
'xcode_settings': {
|
'xcode_settings': {
|
||||||
'OTHER_CFLAGS': [ '-mssse3' ],
|
'OTHER_CFLAGS': [ '-mssse3' ],
|
||||||
},
|
},
|
||||||
|
'msvs_settings': {
|
||||||
|
'VCCLCompilerTool': {
|
||||||
|
'AdditionalOptions': [ '-mssse3' ],
|
||||||
|
},
|
||||||
|
},
|
||||||
}],
|
}],
|
||||||
],
|
],
|
||||||
}],
|
}],
|
||||||
|
4
node.gyp
4
node.gyp
@ -610,8 +610,8 @@
|
|||||||
'msvs_settings': {
|
'msvs_settings': {
|
||||||
'VCLinkerTool': {
|
'VCLinkerTool': {
|
||||||
'AdditionalOptions': [
|
'AdditionalOptions': [
|
||||||
'/WHOLEARCHIVE:<(node_lib_target_name)<(STATIC_LIB_SUFFIX)',
|
'/WHOLEARCHIVE:<(PRODUCT_DIR)/lib/<(node_lib_target_name)<(STATIC_LIB_SUFFIX)',
|
||||||
'/WHOLEARCHIVE:<(STATIC_LIB_PREFIX)v8_base_without_compiler<(STATIC_LIB_SUFFIX)',
|
'/WHOLEARCHIVE:<(PRODUCT_DIR)/lib/<(STATIC_LIB_PREFIX)v8_base_without_compiler<(STATIC_LIB_SUFFIX)',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
20
node.gypi
20
node.gypi
@ -65,11 +65,15 @@
|
|||||||
'NODE_PLATFORM="win32"',
|
'NODE_PLATFORM="win32"',
|
||||||
'_UNICODE=1',
|
'_UNICODE=1',
|
||||||
],
|
],
|
||||||
'msvs_precompiled_header': 'tools/msvs/pch/node_pch.h',
|
'conditions': [
|
||||||
'msvs_precompiled_source': 'tools/msvs/pch/node_pch.cc',
|
['clang==0', {
|
||||||
'sources': [
|
'msvs_precompiled_header': 'tools/msvs/pch/node_pch.h',
|
||||||
'<(_msvs_precompiled_header)',
|
'msvs_precompiled_source': 'tools/msvs/pch/node_pch.cc',
|
||||||
'<(_msvs_precompiled_source)',
|
'sources': [
|
||||||
|
'<(_msvs_precompiled_header)',
|
||||||
|
'<(_msvs_precompiled_source)',
|
||||||
|
],
|
||||||
|
}],
|
||||||
],
|
],
|
||||||
}, { # POSIX
|
}, { # POSIX
|
||||||
'defines': [ '__POSIX__' ],
|
'defines': [ '__POSIX__' ],
|
||||||
@ -148,7 +152,7 @@
|
|||||||
'msvs_settings': {
|
'msvs_settings': {
|
||||||
'VCLinkerTool': {
|
'VCLinkerTool': {
|
||||||
'AdditionalOptions': [
|
'AdditionalOptions': [
|
||||||
'/WHOLEARCHIVE:zlib<(STATIC_LIB_SUFFIX)',
|
'/WHOLEARCHIVE:<(PRODUCT_DIR)/lib/zlib<(STATIC_LIB_SUFFIX)',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -187,7 +191,7 @@
|
|||||||
'msvs_settings': {
|
'msvs_settings': {
|
||||||
'VCLinkerTool': {
|
'VCLinkerTool': {
|
||||||
'AdditionalOptions': [
|
'AdditionalOptions': [
|
||||||
'/WHOLEARCHIVE:libuv<(STATIC_LIB_SUFFIX)',
|
'/WHOLEARCHIVE:<(PRODUCT_DIR)/lib/libuv<(STATIC_LIB_SUFFIX)',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -370,7 +374,7 @@
|
|||||||
'msvs_settings': {
|
'msvs_settings': {
|
||||||
'VCLinkerTool': {
|
'VCLinkerTool': {
|
||||||
'AdditionalOptions': [
|
'AdditionalOptions': [
|
||||||
'/WHOLEARCHIVE:<(openssl_product)',
|
'/WHOLEARCHIVE:<(PRODUCT_DIR)/lib/<(openssl_product)',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -160,6 +160,11 @@
|
|||||||
# -Wno-invalid-offsetof
|
# -Wno-invalid-offsetof
|
||||||
'GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO': 'NO',
|
'GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO': 'NO',
|
||||||
},
|
},
|
||||||
|
'msvs_settings': {
|
||||||
|
'VCCLCompilerTool': {
|
||||||
|
'AdditionalOptions': ['-Wno-invalid-offsetof'],
|
||||||
|
},
|
||||||
|
},
|
||||||
}],
|
}],
|
||||||
['v8_target_arch=="arm"', {
|
['v8_target_arch=="arm"', {
|
||||||
'defines': [
|
'defines': [
|
||||||
@ -536,6 +541,7 @@
|
|||||||
'WIN32',
|
'WIN32',
|
||||||
'NOMINMAX', # Refs: https://chromium-review.googlesource.com/c/v8/v8/+/1456620
|
'NOMINMAX', # Refs: https://chromium-review.googlesource.com/c/v8/v8/+/1456620
|
||||||
'_WIN32_WINNT=0x0602', # Windows 8
|
'_WIN32_WINNT=0x0602', # Windows 8
|
||||||
|
'_SILENCE_ALL_CXX20_DEPRECATION_WARNINGS',
|
||||||
],
|
],
|
||||||
# 4351: VS 2005 and later are warning us that they've fixed a bug
|
# 4351: VS 2005 and later are warning us that they've fixed a bug
|
||||||
# present in VS 2003 and earlier.
|
# present in VS 2003 and earlier.
|
||||||
|
@ -48,7 +48,7 @@
|
|||||||
'type': 'none',
|
'type': 'none',
|
||||||
'toolsets': ['host', 'target'],
|
'toolsets': ['host', 'target'],
|
||||||
'conditions': [
|
'conditions': [
|
||||||
['OS=="win"', {
|
['OS=="win" and clang==0', {
|
||||||
'direct_dependent_settings': {
|
'direct_dependent_settings': {
|
||||||
'msvs_precompiled_header': '<(V8_ROOT)/../../tools/msvs/pch/v8_pch.h',
|
'msvs_precompiled_header': '<(V8_ROOT)/../../tools/msvs/pch/v8_pch.h',
|
||||||
'msvs_precompiled_source': '<(V8_ROOT)/../../tools/msvs/pch/v8_pch.cc',
|
'msvs_precompiled_source': '<(V8_ROOT)/../../tools/msvs/pch/v8_pch.cc',
|
||||||
@ -381,38 +381,6 @@
|
|||||||
'target_name': 'v8_snapshot',
|
'target_name': 'v8_snapshot',
|
||||||
'type': 'static_library',
|
'type': 'static_library',
|
||||||
'toolsets': ['target'],
|
'toolsets': ['target'],
|
||||||
'conditions': [
|
|
||||||
['want_separate_host_toolset', {
|
|
||||||
'conditions': [
|
|
||||||
['v8_target_arch=="arm64"', {
|
|
||||||
'msvs_enable_marmasm': 1,
|
|
||||||
}]
|
|
||||||
],
|
|
||||||
'dependencies': [
|
|
||||||
'generate_bytecode_builtins_list',
|
|
||||||
'run_torque',
|
|
||||||
'mksnapshot#host',
|
|
||||||
'v8_maybe_icu',
|
|
||||||
# [GYP] added explicitly, instead of inheriting from the other deps
|
|
||||||
'v8_base_without_compiler',
|
|
||||||
'v8_compiler_for_mksnapshot',
|
|
||||||
'v8_initializers',
|
|
||||||
'v8_libplatform',
|
|
||||||
]
|
|
||||||
}, {
|
|
||||||
'dependencies': [
|
|
||||||
'generate_bytecode_builtins_list',
|
|
||||||
'run_torque',
|
|
||||||
'mksnapshot',
|
|
||||||
'v8_maybe_icu',
|
|
||||||
# [GYP] added explicitly, instead of inheriting from the other deps
|
|
||||||
'v8_base_without_compiler',
|
|
||||||
'v8_compiler_for_mksnapshot',
|
|
||||||
'v8_initializers',
|
|
||||||
'v8_libplatform',
|
|
||||||
]
|
|
||||||
}],
|
|
||||||
],
|
|
||||||
'sources': [
|
'sources': [
|
||||||
'<(V8_ROOT)/src/init/setup-isolate-deserialize.cc',
|
'<(V8_ROOT)/src/init/setup-isolate-deserialize.cc',
|
||||||
],
|
],
|
||||||
@ -488,6 +456,54 @@
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
'conditions': [
|
||||||
|
['want_separate_host_toolset', {
|
||||||
|
'dependencies': [
|
||||||
|
'generate_bytecode_builtins_list',
|
||||||
|
'run_torque',
|
||||||
|
'mksnapshot#host',
|
||||||
|
'v8_maybe_icu',
|
||||||
|
# [GYP] added explicitly, instead of inheriting from the other deps
|
||||||
|
'v8_base_without_compiler',
|
||||||
|
'v8_compiler_for_mksnapshot',
|
||||||
|
'v8_initializers',
|
||||||
|
'v8_libplatform',
|
||||||
|
]
|
||||||
|
}, {
|
||||||
|
'dependencies': [
|
||||||
|
'generate_bytecode_builtins_list',
|
||||||
|
'run_torque',
|
||||||
|
'mksnapshot',
|
||||||
|
'v8_maybe_icu',
|
||||||
|
# [GYP] added explicitly, instead of inheriting from the other deps
|
||||||
|
'v8_base_without_compiler',
|
||||||
|
'v8_compiler_for_mksnapshot',
|
||||||
|
'v8_initializers',
|
||||||
|
'v8_libplatform',
|
||||||
|
]
|
||||||
|
}],
|
||||||
|
['OS=="win" and clang==1', {
|
||||||
|
'actions': [
|
||||||
|
{
|
||||||
|
'action_name': 'asm_to_inline_asm',
|
||||||
|
'message': 'generating: >@(_outputs)',
|
||||||
|
'inputs': [
|
||||||
|
'<(INTERMEDIATE_DIR)/embedded.S',
|
||||||
|
],
|
||||||
|
'outputs': [
|
||||||
|
'<(INTERMEDIATE_DIR)/embedded.cc',
|
||||||
|
],
|
||||||
|
'process_outputs_as_sources': 1,
|
||||||
|
'action': [
|
||||||
|
'<(python)',
|
||||||
|
'<(V8_ROOT)/tools/snapshot/asm_to_inline_asm.py',
|
||||||
|
'<@(_inputs)',
|
||||||
|
'<(INTERMEDIATE_DIR)/embedded.cc',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}],
|
||||||
|
],
|
||||||
}, # v8_snapshot
|
}, # v8_snapshot
|
||||||
{
|
{
|
||||||
'target_name': 'v8_version',
|
'target_name': 'v8_version',
|
||||||
@ -1928,7 +1944,7 @@
|
|||||||
}],
|
}],
|
||||||
]
|
]
|
||||||
}],
|
}],
|
||||||
['OS=="win"', {
|
['OS=="win" and clang==0', {
|
||||||
'conditions': [
|
'conditions': [
|
||||||
['_toolset == "host" and host_arch == "x64" or _toolset == "target" and target_arch=="x64"', {
|
['_toolset == "host" and host_arch == "x64" or _toolset == "target" and target_arch=="x64"', {
|
||||||
'sources': [
|
'sources': [
|
||||||
|
@ -32,6 +32,7 @@ set ltcg=
|
|||||||
set target_env=
|
set target_env=
|
||||||
set noprojgen=
|
set noprojgen=
|
||||||
set projgen=
|
set projgen=
|
||||||
|
set clang_cl=
|
||||||
set nobuild=
|
set nobuild=
|
||||||
set sign=
|
set sign=
|
||||||
set nosnapshot=
|
set nosnapshot=
|
||||||
@ -87,6 +88,7 @@ if /i "%1"=="arm64" set target_arch=arm64&goto arg-ok
|
|||||||
if /i "%1"=="vs2022" set target_env=vs2022&goto arg-ok
|
if /i "%1"=="vs2022" set target_env=vs2022&goto arg-ok
|
||||||
if /i "%1"=="noprojgen" set noprojgen=1&goto arg-ok
|
if /i "%1"=="noprojgen" set noprojgen=1&goto arg-ok
|
||||||
if /i "%1"=="projgen" set projgen=1&goto arg-ok
|
if /i "%1"=="projgen" set projgen=1&goto arg-ok
|
||||||
|
if /i "%1"=="clang-cl" set clang_cl=1&goto arg-ok
|
||||||
if /i "%1"=="nobuild" set nobuild=1&goto arg-ok
|
if /i "%1"=="nobuild" set nobuild=1&goto arg-ok
|
||||||
if /i "%1"=="nosign" set "sign="&echo Note: vcbuild no longer signs by default. "nosign" is redundant.&goto arg-ok
|
if /i "%1"=="nosign" set "sign="&echo Note: vcbuild no longer signs by default. "nosign" is redundant.&goto arg-ok
|
||||||
if /i "%1"=="sign" set sign=1&goto arg-ok
|
if /i "%1"=="sign" set sign=1&goto arg-ok
|
||||||
@ -190,6 +192,8 @@ if defined nosnapshot set configure_flags=%configure_flags% --without-snap
|
|||||||
if defined nonpm set configure_flags=%configure_flags% --without-npm
|
if defined nonpm set configure_flags=%configure_flags% --without-npm
|
||||||
if defined nocorepack set configure_flags=%configure_flags% --without-corepack
|
if defined nocorepack set configure_flags=%configure_flags% --without-corepack
|
||||||
if defined ltcg set configure_flags=%configure_flags% --with-ltcg
|
if defined ltcg set configure_flags=%configure_flags% --with-ltcg
|
||||||
|
:: If clang-cl build is requested, set it to 17.0, which is the version shipped with VS 2022.
|
||||||
|
if defined clang_cl set configure_flags=%configure_flags% --clang-cl=17.0
|
||||||
if defined release_urlbase set configure_flags=%configure_flags% --release-urlbase=%release_urlbase%
|
if defined release_urlbase set configure_flags=%configure_flags% --release-urlbase=%release_urlbase%
|
||||||
if defined download_arg set configure_flags=%configure_flags% %download_arg%
|
if defined download_arg set configure_flags=%configure_flags% %download_arg%
|
||||||
if defined enable_vtune_arg set configure_flags=%configure_flags% --enable-vtune-profiling
|
if defined enable_vtune_arg set configure_flags=%configure_flags% --enable-vtune-profiling
|
||||||
@ -750,7 +754,7 @@ set exit_code=1
|
|||||||
goto exit
|
goto exit
|
||||||
|
|
||||||
:help
|
:help
|
||||||
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]
|
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]
|
||||||
echo Examples:
|
echo Examples:
|
||||||
echo vcbuild.bat : builds release build
|
echo vcbuild.bat : builds release build
|
||||||
echo vcbuild.bat debug : builds debug build
|
echo vcbuild.bat debug : builds debug build
|
||||||
|
Loading…
Reference in New Issue
Block a user