Skip to content

Commit

Permalink
build: add clang-cl build option on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed May 9, 2024
1 parent 73a7a76 commit 58a7bf7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
8 changes: 6 additions & 2 deletions common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@
'cflags': [ '-fPIC' ],
'ldflags': [ '-fPIC' ]
}],
['clang==1', {
'msbuild_toolset': 'ClangCL',
}],
],
'msbuild_toolset': 'ClangCL',
'msvs_settings': {
'VCCLCompilerTool': {
'BasicRuntimeChecks': 3, # /RTC1
Expand Down Expand Up @@ -241,8 +243,10 @@
'cflags': [ '-fPIC', '-I<(android_ndk_path)/sources/android/cpufeatures' ],
'ldflags': [ '-fPIC' ]
}],
['clang==1', {
'msbuild_toolset': 'ClangCL',
}],
],
'msbuild_toolset': 'ClangCL',
'msvs_settings': {
'VCCLCompilerTool': {
'conditions': [
Expand Down
13 changes: 10 additions & 3 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,13 @@
default=None,
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()

# Expand ~ in the install prefix now, it gets written to multiple files.
Expand Down Expand Up @@ -1042,9 +1049,9 @@ def get_gas_version(cc):
# quite prepared to go that far yet.
def check_compiler(o):
if sys.platform == 'win32':
o['variables']['clang'] = 1
# Visual Studio 2022 ships with this version.
o['variables']['llvm_version'] = '17.0'
if options.clang_cl:
o['variables']['clang'] = 1
o['variables']['llvm_version'] = options.clang_cl
if not options.openssl_no_asm and options.dest_cpu in ('x86', 'x64'):
nasm_version = get_nasm_version('nasm')
o['variables']['nasm_version'] = nasm_version
Expand Down
6 changes: 5 additions & 1 deletion vcbuild.bat
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ set ltcg=
set target_env=
set noprojgen=
set projgen=
set clang_cl=
set nobuild=
set sign=
set nosnapshot=
Expand Down Expand Up @@ -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"=="noprojgen" set noprojgen=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"=="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
Expand Down Expand Up @@ -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 nocorepack set configure_flags=%configure_flags% --without-corepack
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 download_arg set configure_flags=%configure_flags% %download_arg%
if defined enable_vtune_arg set configure_flags=%configure_flags% --enable-vtune-profiling
Expand Down Expand Up @@ -750,7 +754,7 @@ set exit_code=1
goto exit

: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] [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 vcbuild.bat : builds release build
echo vcbuild.bat debug : builds debug build
Expand Down

0 comments on commit 58a7bf7

Please sign in to comment.