@@ -80,9 +80,6 @@ For example: -BuildTo ToolsSupportCore
8080When set, runs the script in a special mode which outputs a listing of command invocations
8181in batch file format instead of executing them.
8282
83- . PARAMETER PinnedLayout
84- If "New", uses the new toolchain install layout. Otherwise, the old layout.
85-
8683. EXAMPLE
8784PS> .\Build.ps1
8885
@@ -110,8 +107,7 @@ param(
110107 [string ] $BuildTo = " " ,
111108 [switch ] $DebugInfo ,
112109 [switch ] $EnableCaching ,
113- [switch ] $ToBatch ,
114- [string ] $PinnedLayout = " old"
110+ [switch ] $ToBatch
115111)
116112
117113$ErrorActionPreference = " Stop"
@@ -273,8 +269,13 @@ function Copy-File($Src, $Dst) {
273269}
274270
275271function Copy-Directory ($Src , $Dst ) {
276- New-Item - ItemType Directory - ErrorAction Ignore $Dst | Out-Null
277- Copy-Item - Force - Recurse $Src $Dst
272+ if ($Tobatch ) {
273+ Write-Output " md `" $Dst `" "
274+ Write-Output " copy /Y `" $Src `" `" $Dst `" "
275+ } else {
276+ New-Item - ItemType Directory - ErrorAction Ignore $Dst | Out-Null
277+ Copy-Item - Force - Recurse $Src $Dst
278+ }
278279}
279280
280281function Invoke-Program () {
@@ -402,121 +403,103 @@ function Invoke-VsDevShell($Arch) {
402403 }
403404}
404405
405- function Ensure-WindowsSDK {
406- # Assume we always have a default Windows SDK version available
407- if (-not $WinSDKVersion ) { return }
408-
409- # Check whether VsDevShell can already resolve the requested Windows SDK version
410- try {
411- Isolate- EnvVars { Invoke-VsDevShell $HostArch }
412- return
413- } catch {}
414-
415- Write-Output " Windows SDK $WinSDKVersion not found. Downloading from nuget..."
416-
417- # Assume the requested Windows SDK is not available and we need to download it
418- # Install the base nuget package that contains header files
419- $WinSDKBasePackageName = " Microsoft.Windows.SDK.CPP"
420- Invoke-Program nuget install $WinSDKBasePackageName - Version $WinSDKVersion - OutputDirectory $NugetRoot
421-
422- # Export to script scope so Invoke-VsDevShell can read it
423- $script :CustomWinSDKRoot = " $NugetRoot \$WinSDKBasePackageName .$WinSDKVersion \c"
406+ function Fetch-Dependencies {
407+ $ProgressPreference = " SilentlyContinue"
424408
425- # Install each required arch-specific package and move the files under the base /lib directory
426- $WinSDKArchs = $SDKArchs.Clone ()
427- if (-not ($HostArch -in $WinSDKArchs )) {
428- $WinSDKArchs += $HostArch
429- }
430-
431- foreach ($Arch in $WinSDKArchs ) {
432- $WinSDKArchPackageName = " $WinSDKBasePackageName .$ ( $Arch.ShortName ) "
433- Invoke-Program nuget install $WinSDKArchPackageName - Version $WinSDKVersion - OutputDirectory $NugetRoot
434- Copy-Directory " $NugetRoot \$WinSDKArchPackageName .$WinSDKVersion \c\*" " $CustomWinSDKRoot \lib\$WinSDKVersionRevisionZero "
435- }
436- }
409+ $WebClient = New-Object Net.WebClient
410+ $WiXVersion = " 4.0.3"
411+ $WiXURL = " https://www.nuget.org/api/v2/package/wix/$WiXVersion "
412+ $WiXHash = " 33B3F28556F2499D10E0E0382ED481BD71BCB6178A20E7AF15A6879571B6BD41"
437413
438- function Ensure-SwiftToolchain ( $Arch ) {
439- if ( - not ( Test-Path $BinaryCache \wix - 4.0 . 3. zip)) {
440- Write-Output " WiX not found. Downloading from nuget.org... "
441- Invoke-Program curl.exe - sL https: // www.nuget.org / api / v2 / package / wix / 4.0 . 3 -- output $BinaryCache \wix - 4.0 . 3. zip -- create - dirs
442- }
443-
444- if ( -not $ToBatch ) {
445- $SHA256 = Get-FileHash - Path " $BinaryCache \wix-4.0.3.zip " - Algorithm SHA256
446- if ( $ SHA256.Hash -ne " 33B3F28556F2499D10E0E0382ED481BD71BCB6178A20E7AF15A6879571B6BD41 " ) {
447- throw " WiX SHA256 mismatch ( $ ( $SHA256 .Hash ) vs 33B3F28556F2499D10E0E0382ED481BD71BCB6178A20E7AF15A6879571B6BD41) "
414+ if ( -not ( Test-Path $BinaryCache \WiX - $WiXVersion .zip ) ) {
415+ Write-Output " WiX not found. Downloading from nuget.org ... "
416+ if ( $ToBatch ) {
417+ Write-Output " curl.exe -sL $WiXURL -o $BinaryCache \WiX- $WiXVersion . zip"
418+ } else {
419+ $WebClient .DownloadFile ( $WiXURL , " $BinaryCache \WiX- $WiXVersion .zip " )
420+ $SHA256 = Get-FileHash - Path " $BinaryCache \WiX- $WiXVersion .zip " - Algorithm SHA256
421+ if ( $SHA256 .Hash -ne $WiXHash ) {
422+ throw " WiX SHA256 mismatch ( $ ( $ SHA256.Hash ) vs $WiXHash ) "
423+ }
448424 }
449425 }
450426
451- New-Item - ItemType Directory - ErrorAction Ignore $BinaryCache \wix- 4.0 .3 | Out-Null
452- Write-Output " Extracting WiX..."
453- Expand-Archive - Path $BinaryCache \wix- 4.0 .3. zip - Destination $BinaryCache \wix- 4.0 .3 - Force
427+ # TODO(compnerd) stamp/validate that we need to re-extract
428+ New-Item - ItemType Directory - ErrorAction Ignore $BinaryCache \WiX- $WiXVersion | Out-Null
429+ Write-Output " Extracting WiX ..."
430+ Expand-Archive - Path $BinaryCache \WiX- $WiXVersion.zip - Destination $BinaryCache \WiX- $WiXVersion - Force
454431
455- if (-not (Test-Path " $BinaryCache \${ PinnedToolchain} .exe" )) {
432+ if (-not (Test-Path $BinaryCache \$PinnedToolchain.exe )) {
456433 Write-Output " Swift toolchain not found. Downloading from swift.org..."
457- (New-Object Net.WebClient).DownloadFile($PinnedBuild , " $BinaryCache \${PinnedToolchain} .exe" )
458- # Invoke-Program curl.exe -sL $PinnedBuild --output $BinaryCache\${PinnedToolchain}.exe --create-dirs
434+ if ($ToBatch ) {
435+ Write-Output " curl.exe -sL $PinnedBuild -o $BinaryCache \$PinnedToolchain .exe"
436+ } else {
437+ $WebClient.DownloadFile (" $PinnedBuild " , " $BinaryCache \$PinnedToolchain .exe" )
438+ $SHA256 = Get-FileHash - Path " $BinaryCache \$PinnedToolchain .exe" - Algorithm SHA256
439+ if ($SHA256.Hash -ne $PinnedSHA256 ) {
440+ throw " $PinnedToolchain SHA256 mismatch ($ ( $SHA256.Hash ) vs $PinnedSHA256 )"
441+ }
442+ }
459443 }
460444
461- if (-not $ToBatch ) {
462- $SHA256 = Get-FileHash - Path " $BinaryCache \${PinnedToolchain} .exe" - Algorithm SHA256
463- if ($SHA256.Hash -ne $PinnedSHA256 ) {
464- throw " SHA256 mismatch ($ ( $SHA256.Hash ) vs ${PinnedSHA256} )"
465- }
445+ # TODO(compnerd) stamp/validate that we need to re-extract
446+ Write-Output " Extracting $PinnedToolchain ..."
447+ New-Item - ItemType Directory - ErrorAction Ignore $BinaryCache \toolchains | Out-Null
448+ # The new runtime MSI is built to expand files into the immediate directory. So, setup the installation location.
449+ New-Item - ItemType Directory - ErrorAction Ignore $BinaryCache \toolchains\$PinnedToolchain \LocalApp\Programs\Swift\Runtimes\0.0 .0 \usr\bin | Out-Null
450+ Invoke-Program $BinaryCache \WiX- $WiXVersion \tools\net6.0 \any\wix.exe -- burn extract $BinaryCache \$PinnedToolchain.exe - out $BinaryCache \toolchains\ - outba $BinaryCache \toolchains\
451+ Get-ChildItem " $BinaryCache \toolchains\WixAttachedContainer" | % {
452+ $LogFile = [System.IO.Path ]::ChangeExtension($_.Name , " log" )
453+ $TARGETDIR = if ($_.Name -eq " rti.msi" ) { " $BinaryCache \toolchains\$PinnedToolchain \LocalApp\Programs\Swift\Runtimes\0.0.0\usr\bin" } else { " $BinaryCache \toolchains\$PinnedToolchain " }
454+ Invoke-Program - OutNull msiexec.exe / lvx! $LogFile / qn / a $BinaryCache \toolchains\WixAttachedContainer\$_ ALLUSERS= 0 TARGETDIR= $TARGETDIR
466455 }
467456
468- New-Item - ItemType Directory - ErrorAction Ignore " $BinaryCache \toolchains" | Out-Null
469- Write-Output " Extracting Swift toolchain..."
470- Invoke-Program " $BinaryCache \wix-4.0.3\tools\net6.0\any\wix.exe" -- burn extract " $BinaryCache \${PinnedToolchain} .exe" - out " $BinaryCache \toolchains\"
471- if ($PinnedLayout -eq " New" ) {
472- [string []] $Packages = @ (" UNUSED" ,
473- " rtl.msi" , " bld.msi" , " cli.msi" , " dbg.msi" , " ide.msi" ,
474- " sdk.x86.msi" , " sdk.amd64.msi" , " sdk.arm64.msi" ,
475- " rtl.cab" , " bld.cab" , " cli.cab" , " dbg.cab" , " ide.cab" ,
476- " sdk.x86.cab" , " sdk.amd64.cab" , " sdk.arm64.cab" )
477- for ($I = 1 ; $I -lt $Packages.length ; $I += 1 ) {
478- Move-Item - Force " $BinaryCache \toolchains\a${I} " " $BinaryCache \toolchains\$ ( $Packages [$I ]) "
479- }
457+ if ($WinSDKVersion ) {
458+ try {
459+ # Check whether VsDevShell can already resolve the requested Windows SDK Version
460+ Isolate- EnvVars { Invoke-VsDevShell $HostArch }
461+ } catch {
462+ $Package = Microsoft.Windows.SDK.CPP
480463
481- # The runtime msi is built to expand files into the immediate directory. So, setup the installation location.
482- New-Item - ItemType Directory - ErrorAction Ignore " $BinaryCache \toolchains\ ${PinnedToolchain} \LocalApp\Programs\Swift\Runtimes\0.0.0\usr\bin " | Out-Null
464+ Write-Output " Windows SDK $WinSDKVersion not found. Downloading from nuget.org ... "
465+ Invoke-Program nuget install $Package - Version $WinSDKVersion - OutputDirectory $NugetRoot
483466
484- Invoke-Program - OutNull msiexec.exe / lvx! bld.log / qn / a " $BinaryCache \toolchains\bld.msi" ALLUSERS= 1 TARGETDIR= " $BinaryCache \toolchains\${PinnedToolchain} "
485- Invoke-Program - OutNull msiexec.exe / lvx! cli.log / qn / a " $BinaryCache \toolchains\cli.msi" ALLUSERS= 1 TARGETDIR= " $BinaryCache \toolchains\${PinnedToolchain} "
486- Invoke-Program - OutNull msiexec.exe / lvx! sdk.x86.log / qn / a " $BinaryCache \toolchains\sdk.x86.msi" ALLUSERS= 1 TARGETDIR= " $BinaryCache \toolchains\${PinnedToolchain} "
487- Invoke-Program - OutNull msiexec.exe / lvx! sdk.amd64.log / qn / a " $BinaryCache \toolchains\sdk.amd64.msi" ALLUSERS= 1 TARGETDIR= " $BinaryCache \toolchains\${PinnedToolchain} "
488- Invoke-Program - OutNull msiexec.exe / lvx! sdk.arm64.log / qn / a " $BinaryCache \toolchains\sdk.arm64.msi" ALLUSERS= 1 TARGETDIR= " $BinaryCache \toolchains\${PinnedToolchain} "
489- Invoke-Program - OutNull msiexec.exe / lvx! rtl.log / qn / a " $BinaryCache \toolchains\rtl.msi" ALLUSERS= 1 TARGETDIR= " $BinaryCache \toolchains\${PinnedToolchain} \LocalApp\Programs\Swift\Runtimes\0.0.0\usr\bin"
490- } else {
491- Invoke-Program - OutNull msiexec.exe / lvx! a0.log / qn / a " $BinaryCache \toolchains\a0" ALLUSERS= 1 TARGETDIR= " $BinaryCache \toolchains\${PinnedToolchain} "
492- Invoke-Program - OutNull msiexec.exe / lvx! a1.log / qn / a " $BinaryCache \toolchains\a1" ALLUSERS= 1 TARGETDIR= " $BinaryCache \toolchains\${PinnedToolchain} "
493- Invoke-Program - OutNull msiexec.exe / lvx! a2.log / qn / a " $BinaryCache \toolchains\a2" ALLUSERS= 1 TARGETDIR= " $BinaryCache \toolchains\${PinnedToolchain} "
494- Invoke-Program - OutNull msiexec.exe / lvx! a3.log / qn / a " $BinaryCache \toolchains\a3" ALLUSERS= 1 TARGETDIR= " $BinaryCache \toolchains\${PinnedToolchain} "
467+ # Set to script scope so Invoke-VsDevShell can read it.
468+ $script :CustomWinSDKRoot = " $NugetRoot \$Package .$WinSDKVersion \c"
469+
470+ # Install each required architecture package and move files under the base /lib directory.
471+ $WinSDKArchs = $SDKArchs.Clone ()
472+ if (-not ($HostArch -in $WinSDKArchs )) {
473+ $WinSDKArch += $HostArch
474+ }
475+
476+ foreach ($Arch in $WinSDKArchs ) {
477+ Invoke-Program nuget install $Package .$ ($Arch.ShortName ) - Version $WinSDKVersion - OutputDirectory $NugetRoot
478+ Copy-Directory " $NugetRoot \$Package .$ ( $Arch.ShortName ) .$WinSDKVersion \c\*" " $CustomWinSDKRoot \lib\$WinSDKVersionRevisionZero "
479+ }
480+ }
495481 }
496482}
497483
498484function Get-PinnedToolchainTool () {
499- if ($PinnedLayout -eq " New " ) {
485+ if (Test-Path " $BinaryCache \toolchains\ ${PinnedToolchain} \LocalApp\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin " ) {
500486 return " $BinaryCache \toolchains\${PinnedToolchain} \LocalApp\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin"
501- } else {
502- return " $BinaryCache \toolchains\${PinnedToolchain} \Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin"
503487 }
488+ return " $BinaryCache \toolchains\${PinnedToolchain} \Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin"
504489}
505490
506491function Get-PinnedToolchainSDK () {
507- if ($PinnedLayout -eq " New " ) {
492+ if (Test-Path " $BinaryCache \toolchains\ ${PinnedToolchain} \LocalApp\Programs\Swift\Platforms\0.0.0\Windows.platform\Developer\SDKs\Windows.sdk " ) {
508493 return " $BinaryCache \toolchains\${PinnedToolchain} \LocalApp\Programs\Swift\Platforms\0.0.0\Windows.platform\Developer\SDKs\Windows.sdk"
509- } else {
510- return " $BinaryCache \toolchains\${PinnedToolchain} \Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk"
511494 }
495+ return " $BinaryCache \toolchains\${PinnedToolchain} \Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk"
512496}
513497
514498function Get-PinnedToolchainRuntime () {
515- if ($PinnedLayout -eq " New " ) {
499+ if (Test-Path " $BinaryCache \toolchains\ ${PinnedToolchain} \LocalApp\Programs\Swift\Runtimes\0.0.0\usr\bin\swiftCore.dll " ) {
516500 return " $BinaryCache \toolchains\${PinnedToolchain} \LocalApp\Programs\Swift\Runtimes\0.0.0\usr\bin"
517- } else {
518- return " $BinaryCache \toolchains\${PinnedToolchain} \PFiles64\Swift\runtime-development\usr\bin"
519501 }
502+ return " $BinaryCache \toolchains\${PinnedToolchain} \PFiles64\Swift\runtime-development\usr\bin"
520503}
521504
522505function TryAdd-KeyValue ([hashtable ]$Hashtable , [string ]$Key , [string ]$Value ) {
@@ -1757,11 +1740,10 @@ function Stage-BuildArtifacts($Arch) {
17571740# -------------------------------------------------------------------
17581741
17591742if (-not $SkipBuild ) {
1760- Ensure - WindowsSDK
1743+ Fetch - Dependencies
17611744}
17621745
17631746if (-not $SkipBuild ) {
1764- Ensure- SwiftToolchain $HostArch
17651747 Invoke-BuildStep Build-BuildTools $HostArch
17661748 Invoke-BuildStep Build-Compilers $HostArch
17671749}
0 commit comments