Skip to content

Commit 58a7bf7

Browse files
committed
build: add clang-cl build option on Windows
1 parent 73a7a76 commit 58a7bf7

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

common.gypi

+6-2
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,10 @@
152152
'cflags': [ '-fPIC' ],
153153
'ldflags': [ '-fPIC' ]
154154
}],
155+
['clang==1', {
156+
'msbuild_toolset': 'ClangCL',
157+
}],
155158
],
156-
'msbuild_toolset': 'ClangCL',
157159
'msvs_settings': {
158160
'VCCLCompilerTool': {
159161
'BasicRuntimeChecks': 3, # /RTC1
@@ -241,8 +243,10 @@
241243
'cflags': [ '-fPIC', '-I<(android_ndk_path)/sources/android/cpufeatures' ],
242244
'ldflags': [ '-fPIC' ]
243245
}],
246+
['clang==1', {
247+
'msbuild_toolset': 'ClangCL',
248+
}],
244249
],
245-
'msbuild_toolset': 'ClangCL',
246250
'msvs_settings': {
247251
'VCCLCompilerTool': {
248252
'conditions': [

configure.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,13 @@
866866
default=None,
867867
help=argparse.SUPPRESS)
868868

869+
parser.add_argument('--clang-cl',
870+
action='store',
871+
dest='clang_cl',
872+
default=None,
873+
help='Configure for clang-cl on Windows. This flag sets the GYP "clang" ' +
874+
'variable to 1 and "llvm_version" to the specified value.')
875+
869876
(options, args) = parser.parse_known_args()
870877

871878
# Expand ~ in the install prefix now, it gets written to multiple files.
@@ -1042,9 +1049,9 @@ def get_gas_version(cc):
10421049
# quite prepared to go that far yet.
10431050
def check_compiler(o):
10441051
if sys.platform == 'win32':
1045-
o['variables']['clang'] = 1
1046-
# Visual Studio 2022 ships with this version.
1047-
o['variables']['llvm_version'] = '17.0'
1052+
if options.clang_cl:
1053+
o['variables']['clang'] = 1
1054+
o['variables']['llvm_version'] = options.clang_cl
10481055
if not options.openssl_no_asm and options.dest_cpu in ('x86', 'x64'):
10491056
nasm_version = get_nasm_version('nasm')
10501057
o['variables']['nasm_version'] = nasm_version

vcbuild.bat

+5-1
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] [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)