Skip to content

Commit bcaaaa5

Browse files
Consolidate dependency infos
1 parent 6ca7ed6 commit bcaaaa5

File tree

1 file changed

+94
-58
lines changed

1 file changed

+94
-58
lines changed

utils/build.ps1

Lines changed: 94 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ param(
127127
[string] $PinnedBuild = "",
128128
[string] $PinnedSHA256 = "",
129129
[string] $PinnedVersion = "",
130-
[string] $PythonVersion = "3.9.10",
131130
[string] $AndroidNDKVersion = "r26b",
132131
[string] $WinSDKVersion = "",
133132
[switch] $Android = $false,
@@ -163,22 +162,6 @@ $env:SDKROOT = ""
163162
$BuildArchName = $env:PROCESSOR_ARCHITEW6432
164163
if ($null -eq $BuildArchName) { $BuildArchName = $env:PROCESSOR_ARCHITECTURE }
165164

166-
if ($PinnedBuild -eq "") {
167-
switch ($BuildArchName) {
168-
"AMD64" {
169-
$PinnedBuild = "https://download.swift.org/swift-5.10.1-release/windows10/swift-5.10.1-RELEASE/swift-5.10.1-RELEASE-windows10.exe"
170-
$PinnedSHA256 = "3027762138ACFA1BBE3050FF6613BBE754332E84C9EFA5C23984646009297286"
171-
$PinnedVersion = "5.10.1"
172-
}
173-
"ARM64" {
174-
$PinnedBuild = "https://download.swift.org/development/windows10-arm64/swift-DEVELOPMENT-SNAPSHOT-2024-07-02-a/swift-DEVELOPMENT-SNAPSHOT-2024-07-02-a-windows10-arm64.exe"
175-
$PinnedSHA256 = "037BDBF9D1A1A99D7156584948870A8A958FD27CC4FF5711691CC0A76F2E88F5"
176-
$PinnedVersion = "0.0.0"
177-
}
178-
default { throw "Unsupported processor architecture" }
179-
}
180-
}
181-
182165
# Store the revision zero variant of the Windows SDK version (no-op if unspecified)
183166
$WindowsSDKMajorMinorBuildMatch = [Regex]::Match($WinSDKVersion, "^\d+\.\d+\.\d+")
184167
$WinSDKVersionRevisionZero = if ($WindowsSDKMajorMinorBuildMatch.Success) { $WindowsSDKMajorMinorBuildMatch.Value + ".0" } else { "" }
@@ -188,8 +171,82 @@ $vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.e
188171
$VSInstallRoot = & $vswhere -nologo -latest -products "*" -all -prerelease -property installationPath
189172
$msbuild = "$VSInstallRoot\MSBuild\Current\Bin\$BuildArchName\MSBuild.exe"
190173

191-
# Hoist to global scope as this is used in two sites.
174+
# Update package hashes when changing versions
192175
$WiXVersion = "4.0.5"
176+
$PythonVersion = "3.9.10"
177+
$WinFlexBisonVersion = "2.5.25"
178+
179+
$Components = @{
180+
WiX = @{
181+
URL = "https://www.nuget.org/api/v2/package/wix/$WiXVersion"
182+
Hash = "DF9BDB347183716F82EFE2CECB8C54BB3554AA907A69F47A41741D6FA4D0A754"
183+
}
184+
PythonAMD64 = @{
185+
URL = "https://www.nuget.org/api/v2/package/python/$PythonVersion"
186+
Hash = "ac43b491e9488ac926ed31c5594f0c9409a21ecbaf99dc7a93f8c7b24cf85867"
187+
}
188+
PythonARM64 = @{
189+
URL = "https://www.nuget.org/api/v2/package/pythonarm64/$PythonVersion"
190+
Hash = "429ada77e7f30e4bd8ff22953a1f35f98b2728e84c9b1d006712561785641f69"
191+
}
192+
PinnedSwiftAMD64 = @{
193+
URL = "https://download.swift.org/swift-5.10.1-release/windows10/swift-5.10.1-RELEASE/swift-5.10.1-RELEASE-windows10.exe"
194+
Hash = "3027762138ACFA1BBE3050FF6613BBE754332E84C9EFA5C23984646009297286"
195+
Version = "5.10.1"
196+
}
197+
PinnedSwiftARM64 = @{
198+
URL = "https://download.swift.org/development/windows10-arm64/swift-DEVELOPMENT-SNAPSHOT-2024-07-02-a/swift-DEVELOPMENT-SNAPSHOT-2024-07-02-a-windows10-arm64.exe"
199+
Hash = "037BDBF9D1A1A99D7156584948870A8A958FD27CC4FF5711691CC0A76F2E88F5"
200+
Version = "0.0.0"
201+
}
202+
PinnedSwiftCustom = @{
203+
URL = $PinnedBuild
204+
Hash = $PinnedSHA256
205+
Version = $PinnedVersion
206+
}
207+
NDK = @{
208+
URL = "https://dl.google.com/android/repository/android-ndk-r26b-windows.zip"
209+
Hash = "A478D43D4A45D0D345CDA6BE50D79642B92FB175868D9DC0DFC86181D80F691E"
210+
}
211+
WinFlexBison = @{
212+
URL = "https://github.com/lexxmark/winflexbison/releases/download/v$WinFlexBisonVersion/win_flex_bison-$WinFlexBisonVersion.zip"
213+
Hash = "8D324B62BE33604B2C45AD1DD34AB93D722534448F55A16CA7292DE32B6AC135"
214+
}
215+
GnuWin32Make = @{
216+
URL = "https://downloads.sourceforge.net/project/ezwinports/make-4.4.1-without-guile-w32-bin.zip"
217+
Hash = "fb66a02b530f7466f6222ce53c0b602c5288e601547a034e4156a512dd895ee7"
218+
}
219+
packaging = @{
220+
URL = "https://files.pythonhosted.org/packages/08/aa/cc0199a5f0ad350994d660967a8efb233fe0416e4639146c089643407ce6/packaging-24.1-py3-none-any.whl"
221+
Hash = "5b8f2217dbdbd2f7f384c41c628544e6d52f2d0f53c6d0c3ea61aa5d1d7ff124"
222+
}
223+
distutils = @{
224+
# 'setuptools' provides 'distutils' module for Python 3.12+, required for SWIG support
225+
# https://github.com/swiftlang/llvm-project/issues/9289
226+
URL = "https://files.pythonhosted.org/packages/ff/ae/f19306b5a221f6a436d8f2238d5b80925004093fa3edea59835b514d9057/setuptools-75.1.0-py3-none-any.whl"
227+
Hash = "35ab7fd3bcd95e6b7fd704e4a1539513edad446c097797f2985e0e4b960772f2"
228+
}
229+
psutil = @{
230+
URL = "https://files.pythonhosted.org/packages/11/91/87fa6f060e649b1e1a7b19a4f5869709fbf750b7c8c262ee776ec32f3028/psutil-6.1.0-cp37-abi3-win_amd64.whl"
231+
Hash = "a8fb3752b491d246034fa4d279ff076501588ce8cbcdbb62c32fd7a377d996be"
232+
}
233+
unittest2 = @{
234+
URL = "https://files.pythonhosted.org/packages/72/20/7f0f433060a962200b7272b8c12ba90ef5b903e218174301d0abfd523813/unittest2-1.1.0-py2.py3-none-any.whl"
235+
Hash = "13f77d0875db6d9b435e1d4f41e74ad4cc2eb6e1d5c824996092b3430f088bb8"
236+
}
237+
}
238+
239+
if ($PinnedBuild -eq "") {
240+
$PinnedSwift = "PinnedSwift$BuildArchName"
241+
if ($Components[$PinnedSwift] -eq $null) {
242+
throw "Unsupported processor architecture"
243+
}
244+
} else {
245+
$PinnedSwift = "PinnedSwiftCustom"
246+
if ($Components[$PinnedSwift].Version -eq "") {
247+
throw "PinnedVersion must be set"
248+
}
249+
}
193250

194251
# Avoid $env:ProgramFiles in case this script is running as x86
195252
$UnixToolsBinDir = "$env:SystemDrive\Program Files\Git\usr\bin"
@@ -375,7 +432,7 @@ function Get-HostSwiftSDK() {
375432
}
376433

377434
$NugetRoot = "$BinaryCache\nuget"
378-
$PinnedToolchain = [IO.Path]::GetFileNameWithoutExtension($PinnedBuild)
435+
$PinnedToolchain = [IO.Path]::GetFileNameWithoutExtension($Components[$PinnedSwift].URL)
379436

380437
$LibraryRoot = "$ImageRoot\Library"
381438

@@ -630,22 +687,26 @@ function Fetch-Dependencies {
630687

631688
$WebClient = New-Object Net.WebClient
632689

633-
function DownloadAndVerify($URL, $Destination, $Hash) {
690+
function DownloadAndVerify($Component, $Destination) {
634691
if (Test-Path $Destination) {
635692
return
636693
}
694+
$Comp = $Components[$Component]
695+
if ($Comp -eq $null) {
696+
throw "Unknown component requested"
697+
}
637698

638699
Write-Output "$Destination not found. Downloading ..."
639700
if ($ToBatch) {
640701
Write-Output "md `"$(Split-Path -Path $Destination -Parent)`""
641-
Write-Output "curl.exe -sL $URL -o $Destination"
642-
Write-Output "(certutil -HashFile $Destination SHA256) == $Hash || (exit /b)"
702+
Write-Output "curl.exe -sL $($Comp.URL) -o $Destination"
703+
Write-Output "(certutil -HashFile $Destination SHA256) == $($Comp.Hash) || (exit /b)"
643704
} else {
644705
New-Item -ItemType Directory (Split-Path -Path $Destination -Parent) -ErrorAction Ignore | Out-Null
645-
$WebClient.DownloadFile($URL, $Destination)
706+
$WebClient.DownloadFile($Comp.URL, $Destination)
646707
$SHA256 = Get-FileHash -Path $Destination -Algorithm SHA256
647-
if ($SHA256.Hash -ne $Hash) {
648-
throw "SHA256 mismatch ($($SHA256.Hash) vs $Hash)"
708+
if ($SHA256.Hash -ne $Comp.Hash) {
709+
throw "SHA256 mismatch ($($SHA256.Hash) vs $($Comp.Hash))"
649710
}
650711
}
651712
}
@@ -716,28 +777,19 @@ function Fetch-Dependencies {
716777

717778
if ($SkipBuild -and $SkipPackaging) { return }
718779

719-
$WiXURL = "https://www.nuget.org/api/v2/package/wix/$WiXVersion"
720-
$WiXHash = "DF9BDB347183716F82EFE2CECB8C54BB3554AA907A69F47A41741D6FA4D0A754"
721-
DownloadAndVerify $WixURL "$BinaryCache\WiX-$WiXVersion.zip" $WiXHash
780+
DownloadAndVerify "WiX" "$BinaryCache\WiX-$WiXVersion.zip"
722781
Extract-ZipFile WiX-$WiXVersion.zip $BinaryCache WiX-$WiXVersion
723782

724783
if ($SkipBuild) { return }
725784

726-
DownloadAndVerify $PinnedBuild "$BinaryCache\$PinnedToolchain.exe" $PinnedSHA256
785+
DownloadAndVerify $PinnedSwift "$BinaryCache\$PinnedToolchain.exe"
727786

728787
# TODO(compnerd) stamp/validate that we need to re-extract
729788
New-Item -ItemType Directory -ErrorAction Ignore $BinaryCache\toolchains | Out-Null
730789
Extract-Toolchain "$PinnedToolchain.exe" $BinaryCache $PinnedToolchain
731790

732791
function Download-Python($ArchName) {
733-
$PythonAMD64URL = "https://www.nuget.org/api/v2/package/python/$PythonVersion"
734-
$PythonAMD64Hash = "ac43b491e9488ac926ed31c5594f0c9409a21ecbaf99dc7a93f8c7b24cf85867"
735-
736-
$PythonARM64URL = "https://www.nuget.org/api/v2/package/pythonarm64/$PythonVersion"
737-
$PythonARM64Hash = "429ada77e7f30e4bd8ff22953a1f35f98b2728e84c9b1d006712561785641f69"
738-
739-
DownloadAndVerify (Get-Variable -Name "Python${ArchName}URL").Value $BinaryCache\Python$ArchName-$PythonVersion.zip (Get-Variable -Name "Python${ArchName}Hash").Value
740-
792+
DownloadAndVerify "Python$ArchName" "$BinaryCache\Python$ArchName-$PythonVersion.zip"
741793
if (-not $ToBatch) {
742794
Extract-ZipFile Python$ArchName-$PythonVersion.zip $BinaryCache Python$ArchName-$PythonVersion
743795
}
@@ -755,20 +807,14 @@ function Fetch-Dependencies {
755807
try {
756808
Invoke-Program -OutNull $Python -c 'import packaging' *> $null
757809
} catch {
758-
$WheelURL = "https://files.pythonhosted.org/packages/08/aa/cc0199a5f0ad350994d660967a8efb233fe0416e4639146c089643407ce6/packaging-24.1-py3-none-any.whl"
759-
$WheelHash = "5b8f2217dbdbd2f7f384c41c628544e6d52f2d0f53c6d0c3ea61aa5d1d7ff124"
760-
DownloadAndVerify $WheelURL "$BinaryCache\python\packaging-24.1-py3-none-any.whl" $WheelHash
810+
DownloadAndVerify "packaging" "$BinaryCache\python\packaging-24.1-py3-none-any.whl"
761811
Write-Output "Installing 'packaging-24.1-py3-none-any.whl' ..."
762812
Invoke-Program -OutNull $Python '-I' -m pip install "$BinaryCache\python\packaging-24.1-py3-none-any.whl" --disable-pip-version-check
763813
}
764-
# 'setuptools' provides 'distutils' module for Python 3.12+, required for SWIG support
765-
# https://github.com/swiftlang/llvm-project/issues/9289
766814
try {
767815
Invoke-Program -OutNull $Python -c 'import distutils' *> $null
768816
} catch {
769-
$WheelURL = "https://files.pythonhosted.org/packages/ff/ae/f19306b5a221f6a436d8f2238d5b80925004093fa3edea59835b514d9057/setuptools-75.1.0-py3-none-any.whl"
770-
$WheelHash = "35ab7fd3bcd95e6b7fd704e4a1539513edad446c097797f2985e0e4b960772f2"
771-
DownloadAndVerify $WheelURL "$BinaryCache\python\setuptools-75.1.0-py3-none-any.whl" $WheelHash
817+
DownloadAndVerify "distutils" "$BinaryCache\python\setuptools-75.1.0-py3-none-any.whl"
772818
Write-Output "Installing 'setuptools-75.1.0-py3-none-any.whl' ..."
773819
Invoke-Program -OutNull $Python '-I' -m pip install "$BinaryCache\python\setuptools-75.1.0-py3-none-any.whl" --disable-pip-version-check
774820
}
@@ -786,19 +832,12 @@ function Fetch-Dependencies {
786832
if ($AndroidNDKVersion -ne "r26b") {
787833
throw "Unsupported Android NDK version"
788834
}
789-
$NDKURL = "https://dl.google.com/android/repository/android-ndk-r26b-windows.zip"
790-
$NDKHash = "A478D43D4A45D0D345CDA6BE50D79642B92FB175868D9DC0DFC86181D80F691E"
791-
DownloadAndVerify $NDKURL "$BinaryCache\android-ndk-$AndroidNDKVersion-windows.zip" $NDKHash
792-
835+
DownloadAndVerify "NDK" "$BinaryCache\android-ndk-$AndroidNDKVersion-windows.zip"
793836
Extract-ZipFile -ZipFileName "android-ndk-$AndroidNDKVersion-windows.zip" -BinaryCache $BinaryCache -ExtractPath "android-ndk-$AndroidNDKVersion" -CreateExtractPath $false
794837
}
795838

796839
if ($IncludeDS2) {
797-
$WinFlexBisonVersion = "2.5.25"
798-
$WinFlexBisonURL = "https://github.com/lexxmark/winflexbison/releases/download/v$WinFlexBisonVersion/win_flex_bison-$WinFlexBisonVersion.zip"
799-
$WinFlexBisonHash = "8D324B62BE33604B2C45AD1DD34AB93D722534448F55A16CA7292DE32B6AC135"
800-
DownloadAndVerify $WinFlexBisonURL "$BinaryCache\win_flex_bison-$WinFlexBisonVersion.zip" $WinFlexBisonHash
801-
840+
DownloadAndVerify "WinFlexBison" "$BinaryCache\win_flex_bison-$WinFlexBisonVersion.zip"
802841
Extract-ZipFile -ZipFileName "win_flex_bison-$WinFlexBisonVersion.zip" -BinaryCache $BinaryCache -ExtractPath "win_flex_bison"
803842
}
804843

@@ -856,10 +895,7 @@ function Get-PinnedToolchainRuntime() {
856895
}
857896

858897
function Get-PinnedToolchainVersion() {
859-
if (Test-Path variable:PinnedVersion) {
860-
return $PinnedVersion
861-
}
862-
throw "PinnedVersion must be set"
898+
$Components[$PinnedSwift].Version
863899
}
864900

865901
$CompilersBinaryCache = if ($IsCrossCompiling) {

0 commit comments

Comments
 (0)