@@ -80,9 +80,6 @@ For example: -BuildTo ToolsSupportCore
80
80
When set, runs the script in a special mode which outputs a listing of command invocations
81
81
in batch file format instead of executing them.
82
82
83
- . PARAMETER PinnedLayout
84
- If "New", uses the new toolchain install layout. Otherwise, the old layout.
85
-
86
83
. EXAMPLE
87
84
PS> .\Build.ps1
88
85
@@ -110,8 +107,7 @@ param(
110
107
[string ] $BuildTo = " " ,
111
108
[switch ] $DebugInfo ,
112
109
[switch ] $EnableCaching ,
113
- [switch ] $ToBatch ,
114
- [string ] $PinnedLayout = " old"
110
+ [switch ] $ToBatch
115
111
)
116
112
117
113
$ErrorActionPreference = " Stop"
@@ -273,8 +269,13 @@ function Copy-File($Src, $Dst) {
273
269
}
274
270
275
271
function 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
+ }
278
279
}
279
280
280
281
function Invoke-Program () {
@@ -402,121 +403,103 @@ function Invoke-VsDevShell($Arch) {
402
403
}
403
404
}
404
405
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"
424
408
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"
437
413
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
+ }
448
424
}
449
425
}
450
426
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
454
431
455
- if (-not (Test-Path " $BinaryCache \${ PinnedToolchain} .exe" )) {
432
+ if (-not (Test-Path $BinaryCache \$PinnedToolchain.exe )) {
456
433
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
+ }
459
443
}
460
444
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
466
455
}
467
456
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
480
463
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
483
466
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
+ }
495
481
}
496
482
}
497
483
498
484
function Get-PinnedToolchainTool () {
499
- if ($PinnedLayout -eq " New " ) {
485
+ if (Test-Path " $BinaryCache \toolchains\ ${PinnedToolchain} \LocalApp\Programs\Swift\Toolchains\0.0.0+Asserts\usr\bin " ) {
500
486
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"
503
487
}
488
+ return " $BinaryCache \toolchains\${PinnedToolchain} \Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin"
504
489
}
505
490
506
491
function 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 " ) {
508
493
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"
511
494
}
495
+ return " $BinaryCache \toolchains\${PinnedToolchain} \Library\Developer\Platforms\Windows.platform\Developer\SDKs\Windows.sdk"
512
496
}
513
497
514
498
function 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 " ) {
516
500
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"
519
501
}
502
+ return " $BinaryCache \toolchains\${PinnedToolchain} \PFiles64\Swift\runtime-development\usr\bin"
520
503
}
521
504
522
505
function TryAdd-KeyValue ([hashtable ]$Hashtable , [string ]$Key , [string ]$Value ) {
@@ -1757,11 +1740,10 @@ function Stage-BuildArtifacts($Arch) {
1757
1740
# -------------------------------------------------------------------
1758
1741
1759
1742
if (-not $SkipBuild ) {
1760
- Ensure - WindowsSDK
1743
+ Fetch - Dependencies
1761
1744
}
1762
1745
1763
1746
if (-not $SkipBuild ) {
1764
- Ensure- SwiftToolchain $HostArch
1765
1747
Invoke-BuildStep Build-BuildTools $HostArch
1766
1748
Invoke-BuildStep Build-Compilers $HostArch
1767
1749
}
0 commit comments