Skip to content

Commit c13122a

Browse files
StefanStojanovicbmeck
authored andcommitted
build: find version of Clang installed on Windows
PR-URL: nodejs#53228 Refs: nodejs#52809 Reviewed-By: Michaël Zasso <[email protected]>
1 parent f906879 commit c13122a

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

BUILDING.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -636,14 +636,22 @@ Optional requirements to build the MSI installer package:
636636
* The .NET SDK component from [Visual Studio 2022](https://visualstudio.microsoft.com/downloads/)
637637
* This component can be installed via the Visual Studio Installer Application
638638

639-
Optional requirements for compiling for Windows 10 on ARM (ARM64):
639+
Optional requirements for compiling for Windows on ARM (ARM64):
640640

641641
* Visual Studio 17.6.0 or newer
642642
* Visual Studio optional components
643643
* Visual C++ compilers and libraries for ARM64
644644
* Visual C++ ATL for ARM64
645645
* Windows 10 SDK 10.0.17763.0 or newer
646646

647+
Optional requirements for compiling with ClangCL:
648+
649+
* Visual Studio optional components
650+
* C++ Clang Compiler for Windows
651+
* MSBuild support for LLVM toolset
652+
653+
NOTE: Currently we only support compiling with Clang that comes from Visual Studio.
654+
647655
##### Option 2: Automated install with Boxstarter
648656

649657
A [Boxstarter](https://boxstarter.org/) script can be used for easy setup of

tools/msvs/vswhere_usability_wrapper.cmd

+5
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ if not exist "%InstallerPath%" goto :no-vswhere
1313
set "Path=%Path%;%InstallerPath%"
1414
where vswhere 2> nul > nul
1515
if errorlevel 1 goto :no-vswhere
16+
:: VC.Tools are needed even when using clang because of the vcvarsall.bat usage
1617
if "%2"=="arm64" (
1718
set VSWHERE_REQ=-requires Microsoft.VisualStudio.Component.VC.Tools.ARM64
1819
) else (
1920
set VSWHERE_REQ=-requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64
2021
)
22+
if "%4"=="1" (
23+
set VSWHERE_REQ=%VSWHERE_REQ% -requires Microsoft.VisualStudio.Component.VC.Llvm.Clang
24+
set VSWHERE_REQ=%VSWHERE_REQ% -requires Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset
25+
)
2126
set VSWHERE_PRP=-property installationPath
2227
set VSWHERE_LMT=-version %1
2328
vswhere -prerelease > nul

vcbuild.bat

+23-4
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,6 @@ if defined nosnapshot set configure_flags=%configure_flags% --without-snap
187187
if defined nonpm set configure_flags=%configure_flags% --without-npm
188188
if defined nocorepack set configure_flags=%configure_flags% --without-corepack
189189
if defined ltcg set configure_flags=%configure_flags% --with-ltcg
190-
:: If clang-cl build is requested, set it to 17.0, which is the version shipped with VS 2022.
191-
if defined clang_cl set configure_flags=%configure_flags% --clang-cl=17.0
192190
if defined release_urlbase set configure_flags=%configure_flags% --release-urlbase=%release_urlbase%
193191
if defined download_arg set configure_flags=%configure_flags% %download_arg%
194192
if defined enable_vtune_arg set configure_flags=%configure_flags% --enable-vtune-profiling
@@ -256,7 +254,7 @@ echo Looking for Visual Studio 2022
256254
@rem cleared first as vswhere_usability_wrapper.cmd doesn't when it fails to
257255
@rem detect the version searched for
258256
if not defined target_env set "VCINSTALLDIR="
259-
call tools\msvs\vswhere_usability_wrapper.cmd "[17.6,18.0)" %target_arch% "prerelease"
257+
call tools\msvs\vswhere_usability_wrapper.cmd "[17.6,18.0)" %target_arch% "prerelease" %clang_cl%
260258
if "_%VCINSTALLDIR%_" == "__" goto msbuild-not-found
261259
@rem check if VS2022 is already setup, and for the requested arch
262260
if "_%VisualStudioVersion%_" == "_17.0_" if "_%VSCMD_ARG_TGT_ARCH%_"=="_%target_arch%_" goto found_vs2022
@@ -276,13 +274,34 @@ set PLATFORM_TOOLSET=v143
276274
goto msbuild-found
277275

278276
:msbuild-not-found
279-
echo Failed to find a suitable Visual Studio installation.
277+
set "clang_echo="
278+
if defined clang_cl set "clang_echo= or Clang compiler/LLVM toolset"
279+
echo Failed to find a suitable Visual Studio installation%clang_echo%.
280280
echo Try to run in a "Developer Command Prompt" or consult
281281
echo https://github.com/nodejs/node/blob/HEAD/BUILDING.md#windows
282282
goto exit
283283

284284
:msbuild-found
285285

286+
@rem check if the clang-cl build is requested
287+
if not defined clang_cl goto clang-skip
288+
@rem x64 is hard coded as it is used for both cross and native compilation.
289+
set "clang_path=%VCINSTALLDIR%\Tools\Llvm\x64\bin\clang.exe"
290+
for /F "tokens=3" %%i in ('"%clang_path%" --version') do (
291+
set clang_version=%%i
292+
goto clang-found
293+
)
294+
295+
:clang-not-found
296+
echo Failed to find Clang compiler in %clang_path%.
297+
goto exit
298+
299+
:clang-found
300+
echo Found Clang version %clang_version%
301+
set configure_flags=%configure_flags% --clang-cl=%clang_version%
302+
303+
:clang-skip
304+
286305
set project_generated=
287306
:project-gen
288307
@rem Skip project generation if requested.

0 commit comments

Comments
 (0)