Skip to content

Commit a927c02

Browse files
committed
synchronise
1 parent c4a8f18 commit a927c02

File tree

1 file changed

+88
-35
lines changed

1 file changed

+88
-35
lines changed

utils/build.ps1

Lines changed: 88 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
1-
#===--- build.ps1 - Windows Build Script -----------------*- PowerShell -*-===//
2-
#
3-
# This source file is part of the Swift.org open source project
4-
#
5-
# Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
6-
# Licensed under Apache License v2.0 with Runtime Library Exception
7-
#
8-
# See https://swift.org/LICENSE.txt for license information
9-
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10-
#
11-
#===----------------------------------------------------------------------===//
12-
131
# Copyright 2020 Saleem Abdulrasool <[email protected]>
142
# Copyright 2023 Tristan Labelle <[email protected]>
153

@@ -54,6 +42,9 @@ An array of architectures for which the Swift SDK should be built.
5442
The product version to be used when building the installer.
5543
Supports semantic version strings.
5644
45+
.PARAMETER PinnedToolchain
46+
The development toolchain snapshot to build the early components with.
47+
5748
.PARAMETER WinSDKVersion
5849
The version number of the Windows SDK to be used.
5950
Overrides the value resolved by the Visual Studio command prompt.
@@ -95,6 +86,7 @@ param(
9586
[string] $SwiftDebugFormat = "dwarf",
9687
[string[]] $SDKs = @("X64","X86","Arm64"),
9788
[string] $ProductVersion = "0.0.0",
89+
[string] $PinnedToolchain = "swift-DEVELOPMENT-SNAPSHOT-2023-08-12-a",
9890
[string] $WinSDKVersion = "",
9991
[switch] $SkipBuild = $false,
10092
[switch] $SkipRedistInstall = $false,
@@ -413,6 +405,32 @@ function Ensure-WindowsSDK {
413405
}
414406
}
415407

408+
function Ensure-SwiftToolchain($Arch) {
409+
if (Test-Path "$BinaryCache\toolchains\$PinnedToolchain\PFiles64\Swift\Toolchains\0.0.0+Asserts\usr\bin\swiftc.exe") {
410+
return
411+
}
412+
413+
if (-not (Test-Path $BinaryCache\wix-4.0.1.zip)) {
414+
curl.exe -sL https://www.nuget.org/api/v2/package/wix/4.0.1 -o $BinaryCache\wix-4.0.1.zip
415+
}
416+
New-Item -ItemType Directory -ErrorAction Ignore $BinaryCache\wix-4.0.1 | Out-Null
417+
Expand-Archive -Path $BinaryCache\wix-4.0.1.zip -Destination $BinaryCache\wix-4.0.1 -Force
418+
419+
Write-Output "Swift toolchain not found. Downloading from swift.org..."
420+
$SwiftToolchainURL = "https://swift.org/builds/development/windows10/${PinnedToolchain}/${PinnedToolchain}-windows10.exe"
421+
New-Item -ItemType Directory -ErrorAction Ignore "$BinaryCache\toolchains" | Out-Null
422+
if (-not (Test-Path "$BinaryCache\toolchains\${PinnedToolchain}.exe")) {
423+
(New-Object Net.WebClient).DownloadFile($SwiftToolchainURL, "$BinaryCache\toolchains\${PinnedToolchain}.exe")
424+
}
425+
426+
Write-Output "Installing Swift toolchain..."
427+
Invoke-Program "$BinaryCache\wix-4.0.1\tools\net6.0\any\wix.exe" -- burn extract "$BinaryCache\toolchains\${PinnedToolchain}.exe" -out "$BinaryCache\toolchains\"
428+
Invoke-Program -OutNull msiexec.exe /qn /a "$BinaryCache\toolchains\a0" TARGETDIR="$BinaryCache\toolchains\${PinnedToolchain}\PFiles64\Swift\Runtimes\0.0.0\usr\bin"
429+
Invoke-Program -OutNull msiexec.exe /qn /a "$BinaryCache\toolchains\a1" TARGETDIR="$BinaryCache\toolchains\${PinnedToolchain}"
430+
Invoke-Program -OutNull msiexec.exe /qn /a "$BinaryCache\toolchains\a2" TARGETDIR="$BinaryCache\toolchains\${PinnedToolchain}"
431+
Invoke-Program -OutNull msiexec.exe /qn /a "$BinaryCache\toolchains\a5" TARGETDIR="$BinaryCache\toolchains\${PinnedToolchain}"
432+
}
433+
416434
function TryAdd-KeyValue([hashtable]$Hashtable, [string]$Key, [string]$Value) {
417435
if (-not $Hashtable.Contains($Key)) {
418436
$Hashtable.Add($Key, $Value)
@@ -600,6 +618,9 @@ function Build-CMakeProject {
600618
$cmakeGenerateArgs += @("-D", "$($Define.Key)=$Value")
601619
}
602620

621+
if ($UseBuiltCompilers.Contains("Swift")) {
622+
$env:Path = "$RuntimeInstallRoot\usr\bin;$ToolchainInstallRoot\usr\bin;${env:Path}"
623+
}
603624
Invoke-Program cmake.exe @cmakeGenerateArgs
604625

605626
# Build all requested targets
@@ -717,6 +738,25 @@ function Build-WiXProject() {
717738
Invoke-Program $msbuild @MSBuildArgs
718739
}
719740

741+
function Build-CompilerDependencies($Arch) {
742+
Isolate-EnvVars {
743+
$env:Path = "$BinaryCache\toolchains\$PinnedToolchain\PFiles64\Swift\Runtimes\0.0.0\usr\bin;${env:Path}"
744+
$env:SDKROOT = "$BinaryCache\toolchains\$PinnedToolchain\PFiles64\Swift\Platforms\Windows.platform\Developer\SDKs\Windows.sdk"
745+
746+
Build-CMakeProject `
747+
-Src $SourceCache\swift-syntax `
748+
-Bin $BinaryCache\99 `
749+
-InstallTo "$($Arch.ToolchainInstallRoot)\usr" `
750+
-Arch $Arch `
751+
-BuildTargets default `
752+
-Defines @{
753+
BUILD_SHARED_LIBS = "YES";
754+
CMAKE_Swift_COMPILER = "$BinaryCache\toolchains\$PinnedToolchain\PFiles64\Swift\Toolchains\0.0.0+Asserts\usr\bin\swiftc.exe";
755+
CMAKE_Swift_FLAGS = @("-sdk", "${env:SDKROOT}");
756+
}
757+
}
758+
}
759+
720760
function Build-BuildTools($Arch) {
721761
Build-CMakeProject `
722762
-Src $SourceCache\llvm-project\llvm `
@@ -767,6 +807,8 @@ function Build-Compilers($Arch, [switch]$Test = $false) {
767807
}
768808
}
769809

810+
$env:Path = "$BinaryCache\toolchains\$PinnedToolchain\PFiles64\Swift\Runtimes\0.0.0\usr\bin;${env:Path}"
811+
770812
$LLVM_ENABLE_PDB = switch ($BuildType) {
771813
"Release" { "NO" }
772814
default { "YES" }
@@ -787,6 +829,8 @@ function Build-Compilers($Arch, [switch]$Test = $false) {
787829
# give us a sligtly faster build.
788830
CMAKE_BUILD_TYPE = "Release";
789831
CMAKE_INSTALL_PREFIX = "$($Arch.ToolchainInstallRoot)\usr";
832+
CMAKE_Swift_COMPILER = "$BinaryCache\toolchains\$PinnedToolchain\PFiles64\Swift\Toolchains\0.0.0+Asserts\usr\bin\swiftc.exe";
833+
CMAKE_Swift_FLAGS = @("-sdk", "$BinaryCache\toolchains\$PinnedToolchain\PFiles64\Swift\Platforms\Windows.platform\Developer\SDKs\Windows.sdk");
790834
LLDB_PYTHON_EXE_RELATIVE_PATH = "python.exe";
791835
LLDB_PYTHON_EXT_SUFFIX = ".pyd";
792836
LLDB_PYTHON_RELATIVE_PATH = "lib/site-packages";
@@ -804,9 +848,11 @@ function Build-Compilers($Arch, [switch]$Test = $false) {
804848
SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED = "YES";
805849
SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION = "YES";
806850
SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING = "YES";
851+
SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR = "$BinaryCache\99";
807852
SWIFT_PATH_TO_LIBDISPATCH_SOURCE = "$SourceCache\swift-corelibs-libdispatch";
808853
SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE = "$SourceCache\swift-syntax";
809854
SWIFT_PATH_TO_STRING_PROCESSING_SOURCE = "$SourceCache\swift-experimental-string-processing";
855+
SWIFT_PATH_TO_SWIFT_SDK = "$BinaryCache\toolchains\$PinnedToolchain\PFiles64\Swift\Platforms\Windows.platform\Developer\SDKs\Windows.sdk";
810856
})
811857
}
812858
}
@@ -935,29 +981,33 @@ function Build-ICU($Arch) {
935981
function Build-Runtime($Arch) {
936982
$LLVMBinaryCache = Get-ProjectBinaryCache $Arch 0
937983

938-
Build-CMakeProject `
939-
-Src $SourceCache\swift `
940-
-Bin (Get-ProjectBinaryCache $Arch 1) `
941-
-InstallTo "$($Arch.SDKInstallRoot)\usr" `
942-
-Arch $Arch `
943-
-CacheScript $SourceCache\swift\cmake\caches\Runtime-Windows-$($Arch.LLVMName).cmake `
944-
-UseBuiltCompilers C,CXX `
945-
-BuildTargets default `
946-
-Defines @{
947-
CMAKE_Swift_COMPILER_TARGET = $Arch.LLVMTarget;
948-
LLVM_DIR = "$LLVMBinaryCache\lib\cmake\llvm";
949-
SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY = "YES";
950-
SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP = "YES";
951-
SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING = "YES";
952-
SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED = "YES";
953-
SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION = "YES";
954-
SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING = "YES";
955-
SWIFT_NATIVE_SWIFT_TOOLS_PATH = "$BinaryCache\1\bin";
956-
SWIFT_PATH_TO_LIBDISPATCH_SOURCE = "$SourceCache\swift-corelibs-libdispatch";
957-
SWIFT_PATH_TO_STRING_PROCESSING_SOURCE = "$SourceCache\swift-experimental-string-processing";
958-
SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE = "$SourceCache\swift-syntax";
959-
CMAKE_SHARED_LINKER_FLAGS = @("/INCREMENTAL:NO", "/OPT:REF", "/OPT:ICF");
960-
}
984+
Isolate-EnvVars {
985+
$env:Path = "$BinaryCache\toolchains\$PinnedToolchain\PFiles64\Swift\Runtimes\0.0.0\usr\bin;${env:Path}"
986+
987+
Build-CMakeProject `
988+
-Src $SourceCache\swift `
989+
-Bin (Get-ProjectBinaryCache $Arch 1) `
990+
-InstallTo "$($Arch.SDKInstallRoot)\usr" `
991+
-Arch $Arch `
992+
-CacheScript $SourceCache\swift\cmake\caches\Runtime-Windows-$($Arch.LLVMName).cmake `
993+
-UseBuiltCompilers C,CXX `
994+
-BuildTargets default `
995+
-Defines @{
996+
CMAKE_Swift_COMPILER_TARGET = $Arch.LLVMTarget;
997+
LLVM_DIR = "$LLVMBinaryCache\lib\cmake\llvm";
998+
SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY = "YES";
999+
SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP = "YES";
1000+
SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING = "YES";
1001+
SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED = "YES";
1002+
SWIFT_ENABLE_EXPERIMENTAL_OBSERVATION = "YES";
1003+
SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING = "YES";
1004+
SWIFT_NATIVE_SWIFT_TOOLS_PATH = "$BinaryCache\1\bin";
1005+
SWIFT_PATH_TO_LIBDISPATCH_SOURCE = "$SourceCache\swift-corelibs-libdispatch";
1006+
SWIFT_PATH_TO_STRING_PROCESSING_SOURCE = "$SourceCache\swift-experimental-string-processing";
1007+
SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE = "$SourceCache\swift-syntax";
1008+
CMAKE_SHARED_LINKER_FLAGS = @("/INCREMENTAL:NO", "/OPT:REF", "/OPT:ICF");
1009+
}
1010+
}
9611011

9621012
Invoke-Program $python -c "import plistlib; print(str(plistlib.dumps({ 'DefaultProperties': { 'DEFAULT_USE_RUNTIME': 'MD' } }), encoding='utf-8'))" `
9631013
-OutFile "$($Arch.SDKInstallRoot)\SDKSettings.plist"
@@ -1526,6 +1576,9 @@ if (-not $SkipBuild) {
15261576
}
15271577

15281578
if (-not $SkipBuild) {
1579+
Ensure-SwiftToolchain $HostArch
1580+
Build-CompilerDependencies $HostArch
1581+
15291582
Build-BuildTools $HostArch
15301583
Build-Compilers $HostArch
15311584
}

0 commit comments

Comments
 (0)