Skip to content

Commit

Permalink
build: find version of Clang installed on Windows
Browse files Browse the repository at this point in the history
PR-URL: #53228
Refs: #52809
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information
StefanStojanovic authored and pull[bot] committed Aug 27, 2024
1 parent eeb420d commit dbfcc48
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
10 changes: 9 additions & 1 deletion BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -636,14 +636,22 @@ Optional requirements to build the MSI installer package:
* The .NET SDK component from [Visual Studio 2022](https://visualstudio.microsoft.com/downloads/)
* This component can be installed via the Visual Studio Installer Application

Optional requirements for compiling for Windows 10 on ARM (ARM64):
Optional requirements for compiling for Windows on ARM (ARM64):

* Visual Studio 17.6.0 or newer
* Visual Studio optional components
* Visual C++ compilers and libraries for ARM64
* Visual C++ ATL for ARM64
* Windows 10 SDK 10.0.17763.0 or newer

Optional requirements for compiling with ClangCL:

* Visual Studio optional components
* C++ Clang Compiler for Windows
* MSBuild support for LLVM toolset

NOTE: Currently we only support compiling with Clang that comes from Visual Studio.

##### Option 2: Automated install with Boxstarter

A [Boxstarter](https://boxstarter.org/) script can be used for easy setup of
Expand Down
5 changes: 5 additions & 0 deletions tools/msvs/vswhere_usability_wrapper.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ if not exist "%InstallerPath%" goto :no-vswhere
set "Path=%Path%;%InstallerPath%"
where vswhere 2> nul > nul
if errorlevel 1 goto :no-vswhere
:: VC.Tools are needed even when using clang because of the vcvarsall.bat usage
if "%2"=="arm64" (
set VSWHERE_REQ=-requires Microsoft.VisualStudio.Component.VC.Tools.ARM64
) else (
set VSWHERE_REQ=-requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64
)
if "%4"=="1" (
set VSWHERE_REQ=%VSWHERE_REQ% -requires Microsoft.VisualStudio.Component.VC.Llvm.Clang
set VSWHERE_REQ=%VSWHERE_REQ% -requires Microsoft.VisualStudio.Component.VC.Llvm.ClangToolset
)
set VSWHERE_PRP=-property installationPath
set VSWHERE_LMT=-version %1
vswhere -prerelease > nul
Expand Down
27 changes: 23 additions & 4 deletions vcbuild.bat
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,6 @@ 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 @@ -256,7 +254,7 @@ echo Looking for Visual Studio 2022
@rem cleared first as vswhere_usability_wrapper.cmd doesn't when it fails to
@rem detect the version searched for
if not defined target_env set "VCINSTALLDIR="
call tools\msvs\vswhere_usability_wrapper.cmd "[17.6,18.0)" %target_arch% "prerelease"
call tools\msvs\vswhere_usability_wrapper.cmd "[17.6,18.0)" %target_arch% "prerelease" %clang_cl%
if "_%VCINSTALLDIR%_" == "__" goto msbuild-not-found
@rem check if VS2022 is already setup, and for the requested arch
if "_%VisualStudioVersion%_" == "_17.0_" if "_%VSCMD_ARG_TGT_ARCH%_"=="_%target_arch%_" goto found_vs2022
Expand All @@ -276,13 +274,34 @@ set PLATFORM_TOOLSET=v143
goto msbuild-found

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

:msbuild-found

@rem check if the clang-cl build is requested
if not defined clang_cl goto clang-skip
@rem x64 is hard coded as it is used for both cross and native compilation.
set "clang_path=%VCINSTALLDIR%\Tools\Llvm\x64\bin\clang.exe"
for /F "tokens=3" %%i in ('"%clang_path%" --version') do (
set clang_version=%%i
goto clang-found
)

:clang-not-found
echo Failed to find Clang compiler in %clang_path%.
goto exit

:clang-found
echo Found Clang version %clang_version%
set configure_flags=%configure_flags% --clang-cl=%clang_version%

:clang-skip

set project_generated=
:project-gen
@rem Skip project generation if requested.
Expand Down

0 comments on commit dbfcc48

Please sign in to comment.