Skip to content

Commit 3d43e1a

Browse files
authored
Merge pull request swiftlang#80918 from etcwilde/ewilde/use-installed-cmake-ninja
Windows: Use pre-installed CMake and Ninja
2 parents a0fc6e2 + b15303d commit 3d43e1a

File tree

1 file changed

+35
-17
lines changed

1 file changed

+35
-17
lines changed

utils/build.ps1

+35-17
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,31 @@ $vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.e
383383
$VSInstallRoot = & $vswhere -nologo -latest -products "*" -all -prerelease -property installationPath
384384
$msbuild = "$VSInstallRoot\MSBuild\Current\Bin\$BuildArchName\MSBuild.exe"
385385

386+
function Get-CMake {
387+
try {
388+
return (Get-Command "cmake.exe" -ErrorAction Stop).Source
389+
} catch {
390+
if (Test-Path -Path "${VSInstallRoot}\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin" -PathType Container) {
391+
return "${VSInstallRoot}\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe"
392+
}
393+
}
394+
throw "CMake not found on Path nor in the Visual Studio Installation. Please Install CMake to continue."
395+
}
396+
397+
function Get-Ninja {
398+
try {
399+
return (Get-Command "Ninja.exe" -ErrorAction Stop).Source
400+
} catch {
401+
if (Test-Path -Path "${VSInstallRoot}\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja" -PathType Container) {
402+
return "${VSInstallRoot}\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja\ninja.exe"
403+
}
404+
}
405+
throw "Ninja not found on Path nor in the Visual Studio Installation. Please Install Ninja to continue."
406+
}
407+
408+
$cmake = Get-CMake
409+
$ninja = Get-Ninja
410+
386411
$NugetRoot = "$BinaryCache\nuget"
387412
$LibraryRoot = "$ImageRoot\Library"
388413

@@ -1206,14 +1231,6 @@ function Build-CMakeProject {
12061231
}
12071232

12081233
if ($Platform.OS -eq [OS]::Android) {
1209-
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
1210-
$VSInstallPath = & $vswhere -nologo -latest -products * -property installationPath
1211-
if (Test-Path "${VSInstallPath}\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin") {
1212-
$env:Path = "${VSInstallPath}\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;${VSInstallPath}\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja;${env:Path}"
1213-
Add-KeyValueIfNew $Defines CMAKE_MAKE_PROGRAM "${VSInstallPath}\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja\ninja.exe"
1214-
} else {
1215-
throw "Missing CMake and Ninja in the visual studio installation that are needed to build Android"
1216-
}
12171234
$androidNDKPath = Get-AndroidNDKPath
12181235
Add-KeyValueIfNew $Defines CMAKE_C_COMPILER (Join-Path -Path $androidNDKPath -ChildPath "toolchains\llvm\prebuilt\windows-x86_64\bin\clang.exe")
12191236
Add-KeyValueIfNew $Defines CMAKE_CXX_COMPILER (Join-Path -Path $androidNDKPath -ChildPath "toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe")
@@ -1412,6 +1429,8 @@ function Build-CMakeProject {
14121429
Add-KeyValueIfNew $Defines CMAKE_INSTALL_PREFIX $InstallTo
14131430
}
14141431

1432+
Add-KeyValueIfNew $Defines CMAKE_MAKE_PROGRAM "$ninja"
1433+
14151434
# Generate the project
14161435
$cmakeGenerateArgs = @("-B", $Bin, "-S", $Src, "-G", $Generator)
14171436
if ($CacheScript) {
@@ -1451,26 +1470,25 @@ function Build-CMakeProject {
14511470
} elseif ($UsePinnedCompilers.Contains("Swift")) {
14521471
$env:Path = "$(Get-PinnedToolchainRuntime);${env:Path}"
14531472
}
1454-
14551473
if ($ToBatch) {
14561474
Write-Output ""
1457-
Write-Output "echo cmake.exe $cmakeGenerateArgs"
1475+
Write-Output "echo $cmake $cmakeGenerateArgs"
14581476
} else {
1459-
Write-Host "cmake.exe $cmakeGenerateArgs"
1477+
Write-Host "$cmake $cmakeGenerateArgs"
14601478
}
1461-
Invoke-Program cmake.exe @cmakeGenerateArgs
1479+
Invoke-Program $cmake @cmakeGenerateArgs
14621480

14631481
# Build all requested targets
14641482
foreach ($Target in $BuildTargets) {
14651483
if ($Target -eq "default") {
1466-
Invoke-Program cmake.exe --build $Bin
1484+
Invoke-Program $cmake --build $Bin
14671485
} else {
1468-
Invoke-Program cmake.exe --build $Bin --target $Target
1486+
Invoke-Program $cmake --build $Bin --target $Target
14691487
}
14701488
}
14711489

14721490
if ($BuildTargets.Length -eq 0 -and $InstallTo) {
1473-
Invoke-Program cmake.exe --build $Bin --target install
1491+
Invoke-Program $cmake --build $Bin --target install
14741492
}
14751493
}
14761494

@@ -2254,7 +2272,7 @@ function Build-ExperimentalRuntime {
22542272
Invoke-VsDevShell $BuildPlatform
22552273

22562274
Push-Location "${SourceCache}\swift\Runtimes"
2257-
Start-Process -Wait -WindowStyle Hidden -FilePath cmake.exe -ArgumentList @("-P", "Resync.cmake")
2275+
Start-Process -Wait -WindowStyle Hidden -FilePath $cmake -ArgumentList @("-P", "Resync.cmake")
22582276
Pop-Location
22592277
}
22602278

@@ -2665,7 +2683,7 @@ function Test-LLBuild {
26652683
# Build additional llvm executables needed by tests
26662684
Invoke-IsolatingEnvVars {
26672685
Invoke-VsDevShell $BuildPlatform
2668-
Invoke-Program ninja.exe -C (Get-ProjectBinaryCache $BuildPlatform BuildTools) FileCheck not
2686+
Invoke-Program $ninja -C (Get-ProjectBinaryCache $BuildPlatform BuildTools) FileCheck not
26692687
}
26702688

26712689
Invoke-IsolatingEnvVars {

0 commit comments

Comments
 (0)