Skip to content

Early driver win #77789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 141 additions & 41 deletions utils/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ $ArchX64 = @{
ToolchainInstallRoot = "$BinaryCache\x64\toolchains\$ProductVersion+Asserts";
}

$WindowsX64 = $ArchX64

$ArchX86 = @{
VSName = "x86";
ShortName = "x86";
Expand All @@ -253,6 +255,8 @@ $ArchX86 = @{
SwiftTestingInstallRoot = "$BinaryCache\x86\Windows.platform\Developer\Library\Testing-development";
}

$WindowsX86 = $ArchX86

$ArchARM64 = @{
VSName = "arm64";
ShortName = "arm64";
Expand All @@ -269,6 +273,8 @@ $ArchARM64 = @{
SwiftTestingInstallRoot = "$BinaryCache\arm64\Windows.platform\Developer\Library\Testing-development";
}

$WindowsARM64 = $ArchARM64

$AndroidARM64 = @{
AndroidArchABI = "arm64-v8a";
BinaryDir = "bin64a";
Expand Down Expand Up @@ -433,7 +439,7 @@ function Get-TargetProjectBinaryCache($Arch, [TargetComponent]$Project) {
}

enum HostComponent {
Compilers = 5
Compilers = 9
FoundationMacros = 10
TestingMacros
System
Expand Down Expand Up @@ -466,6 +472,7 @@ function Get-HostProjectCMakeModules([HostComponent]$Project) {

enum BuildComponent {
BuildTools
Driver
Compilers
FoundationMacros
TestingMacros
Expand Down Expand Up @@ -1068,6 +1075,53 @@ function Build-CMakeProject {
} else {
TryAdd-KeyValue $Defines CMAKE_Swift_COMPILER (Join-Path -Path (Get-PinnedToolchainTool) -ChildPath "swiftc.exe")
}

$DebugSwiftC = $Defines["CMAKE_Swift_COMPILER"]
Write-Host "DEBUG DEBUG DEBUG CMAKE_Swift_COMPILER: $DebugSwiftC"
$SwiftCDepDlls = dumpbin /Dependents $DebugSwiftC
Write-Host "DEBUG DEBUG DEBUG SwiftCDepDlls: $SwiftCDepDlls"
$SwiftCImports = dumpbin /Imports $DebugSwiftC
Write-Host "DEBUG DEBUG DEBUG SwiftCImports: $SwiftCImports"

$BinFolder = Split-Path $DebugSwiftC
Write-Host "DEBUG DEBUG DEBUG BinFolder: $BinFolder"
$DumpChildren = Get-ChildItem $BinFolder
Write-Host "DEBUG DEBUG DEBUG DumpChildren: $DumpChildren"

$SwiftDriver = Join-Path -Path $BinFolder -ChildPath "swift-driver.exe"
Write-Host "DEBUG DEBUG DEBUG SwiftDriver: $SwiftDriver"
$SwiftDriverDepDlls = dumpbin /Dependents $SwiftDriver
Write-Host "DEBUG DEBUG DEBUG SwiftDriverDepDlls: $SwiftDriverDepDlls"
$SwiftDriverImports = dumpbin /Imports $SwiftDriver
Write-Host "DEBUG DEBUG DEBUG SwiftDriverImports: $SwiftDriverImports"

$Dlls = @(
"swiftCore.dll"
"swift_Concurrency.dll"
"swiftWinSDK.dll"
"swiftCRT.dll"
"Foundation.dll"
"swiftDispatch.dll"
"BlocksRuntime.dll"
)

foreach ($Dll in $Dlls) {
$DllPath = Join-Path -Path $BinFolder -ChildPath $Dll
if (-Not (Test-Path $DllPath)) {
# Search through PATH to find the DLL
$DllPath = Get-Command $Dll -ErrorAction SilentlyContinue
if ($DllPath) {
$DllPath = $DllPath.Path
} else {
Write-Host "DEBUG DEBUG DEBUG Could not find ${Dll} in PATH"
continue
}
}
Write-Host "DEBUG DEBUG DEBUG Found ${Dll}: $DllPath"
$DllExports = dumpbin /exports $DllPath
Write-Host "DEBUG DEBUG DEBUG DllExports for ${Dll}: $DllExports"
}

if (-not ($Platform -eq "Windows")) {
TryAdd-KeyValue $Defines CMAKE_Swift_COMPILER_WORKS = "YES"
}
Expand Down Expand Up @@ -1182,10 +1236,12 @@ function Build-CMakeProject {
}

if ($UseBuiltCompilers.Contains("Swift")) {
$env:Path = "$($BuildArch.SDKInstallRoot)\usr\bin;$(Get-CMarkBinaryCache $Arch)\src;$($BuildArch.ToolchainInstallRoot)\usr\bin;${env:Path}"
$env:Path = "$($BuildArch.SDKInstallRoot)\usr\bin;$(Get-CMarkBinaryCache $BuildArch)\src;$($BuildArch.ToolchainInstallRoot)\usr\bin;${env:Path};$(Get-PinnedToolchainRuntime)"
} elseif ($UsePinnedCompilers.Contains("Swift")) {
$env:Path = "$(Get-PinnedToolchainRuntime);${env:Path}"
}
Write-Host "Path: ${env:Path}"
Write-Host (Get-Command cmake).Source @cmakeGenerateArgs
Invoke-Program cmake.exe @cmakeGenerateArgs

# Build all requested targets
Expand Down Expand Up @@ -1492,6 +1548,7 @@ function Build-Compilers() {
Python3_ROOT_DIR = "$BinaryCache\Python$($Arch.CMakeName)-$PythonVersion\tools";
SWIFT_BUILD_SWIFT_SYNTAX = "YES";
SWIFT_CLANG_LOCATION = (Get-PinnedToolchainTool);
SWIFT_EARLY_SWIFT_DRIVER_BUILD = "$(Get-BuildProjectBinaryCache Driver)\$($BuildArch.LLVMTarget)\release";
SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY = "YES";
SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP = "YES";
SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING = "YES";
Expand Down Expand Up @@ -1834,6 +1891,7 @@ function Build-Dispatch([Platform]$Platform, $Arch, [switch]$Test = $false) {
-Arch $Arch `
-Platform $Platform `
-UseBuiltCompilers C,CXX,Swift `
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
-Defines @{
ENABLE_SWIFT = "YES";
}
Expand Down Expand Up @@ -1876,28 +1934,17 @@ function Build-Foundation([Platform]$Platform, $Arch, [switch]$Test = $false) {
$ShortArch = $Arch.LLVMName

Isolate-EnvVars {
$SDKRoot = if ($Platform -eq "Windows") {
""
} else {
(Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot
}

$SDKRoot = if ($Platform -eq "Windows") {
""
} else {
(Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot
}

Build-CMakeProject `
-Src $SourceCache\swift-corelibs-foundation `
-Bin $FoundationBinaryCache `
-InstallTo "$($Arch.SDKInstallRoot)\usr" `
-Arch $Arch `
-Platform $Platform `
-UseBuiltCompilers ASM,C,CXX,Swift `
-SwiftSDK:$SDKRoot `
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
-Defines (@{
ENABLE_TESTING = "NO";
CMAKE_Swift_COMPILER_USE_OLD_DRIVER = "YES";
FOUNDATION_BUILD_TOOLS = if ($Platform -eq "Windows") { "YES" } else { "NO" };
CURL_DIR = "$LibraryRoot\curl-8.9.1\usr\lib\$Platform\$ShortArch\cmake\CURL";
LIBXML2_LIBRARY = if ($Platform -eq "Windows") {
Expand Down Expand Up @@ -1941,7 +1988,7 @@ function Build-FoundationMacros() {
Get-HostProjectBinaryCache FoundationMacros
}

$SwiftSDK = $null
$SwiftSDK = $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot)
if ($Build) {
$SwiftSDK = $BuildArch.SDKInstallRoot
}
Expand All @@ -1966,7 +2013,7 @@ function Build-FoundationMacros() {
-Arch $Arch `
-Platform $Platform `
-UseBuiltCompilers Swift `
-SwiftSDK:$SwiftSDK `
-SwiftSDK $SwiftSDK `
-BuildTargets:$Targets `
-Defines @{
SwiftSyntax_DIR = $SwiftSyntaxCMakeModules;
Expand Down Expand Up @@ -2003,6 +2050,7 @@ function Build-XCTest([Platform]$Platform, $Arch, [switch]$Test = $false) {
-Arch $Arch `
-Platform $Platform `
-UseBuiltCompilers Swift `
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
-BuildTargets $Targets `
-Defines (@{
CMAKE_BUILD_WITH_INSTALL_RPATH = "YES";
Expand Down Expand Up @@ -2032,6 +2080,7 @@ function Build-Testing([Platform]$Platform, $Arch, [switch]$Test = $false) {
-Arch $Arch `
-Platform $Platform `
-UseBuiltCompilers C,CXX,Swift `
-SwiftSDK $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot) `
-Defines (@{
BUILD_SHARED_LIBS = "YES";
CMAKE_BUILD_WITH_INSTALL_RPATH = "YES";
Expand Down Expand Up @@ -2257,29 +2306,79 @@ function Build-ArgumentParser($Arch) {
}
}

function Build-Driver($Arch) {
Build-CMakeProject `
-Src $SourceCache\swift-driver `
-Bin (Get-HostProjectBinaryCache Driver) `
-InstallTo "$($Arch.ToolchainInstallRoot)\usr" `
-Arch $Arch `
-Platform Windows `
-UseBuiltCompilers C,CXX,Swift `
-SwiftSDK (Get-HostSwiftSDK) `
-Defines @{
BUILD_SHARED_LIBS = "YES";
SwiftSystem_DIR = (Get-HostProjectCMakeModules System);
TSC_DIR = (Get-HostProjectCMakeModules ToolsSupportCore);
LLBuild_DIR = (Get-HostProjectCMakeModules LLBuild);
Yams_DIR = (Get-HostProjectCMakeModules Yams);
ArgumentParser_DIR = (Get-HostProjectCMakeModules ArgumentParser);
SQLite3_INCLUDE_DIR = "$LibraryRoot\sqlite-3.46.0\usr\include";
SQLite3_LIBRARY = "$LibraryRoot\sqlite-3.46.0\usr\lib\SQLite3.lib";
SWIFT_DRIVER_BUILD_TOOLS = "YES";
LLVM_DIR = "$(Get-HostProjectBinaryCache Compilers)\lib\cmake\llvm";
Clang_DIR = "$(Get-HostProjectBinaryCache Compilers)\lib\cmake\clang";
Swift_DIR = "$(Get-HostProjectBinaryCache Compilers)\tools\swift\lib\cmake\swift";
function Build-Driver() {
[CmdletBinding(PositionalBinding = $false)]
param
(
[Parameter(Position = 0, Mandatory = $true)]
[hashtable]$Arch,
[switch] $Build = $false
)

if ($Build) {
$Stopwatch = [Diagnostics.Stopwatch]::StartNew()

Isolate-EnvVars {
$env:SWIFTCI_USE_LOCAL_DEPS=1
$env:SDKROOT = (Get-PinnedToolchainSDK)
$env:Path = "$(Get-PinnedToolchainRuntime);$(Get-PinnedToolchainTool);${env:Path}"

$src = "$SourceCache\swift-driver"
$dst = (Get-BuildProjectBinaryCache Driver)

if ($ToBatch) {
Write-Output ""
Write-Output "echo Building '$src' to '$dst' for arch '$($Arch.LLVMName)'..."
} else {
Write-Host -ForegroundColor Cyan "[$([DateTime]::Now.ToString("yyyy-MM-dd HH:mm:ss"))] Building '$src' to '$dst' for arch '$($Arch.LLVMName)'..."
}

Invoke-Program `
"$(Get-PinnedToolchainTool)\swift.exe" build `
-c release `
--scratch-path $dst `
--package-path $src `
-Xcc -Xclang -Xcc -fno-split-cold-code `
-Xlinker "$(Get-PinnedToolchainSDK)\usr\lib\swift\windows\$($BuildArch.LLVMName)\swiftCore.lib"

if (-not $ToBatch) {
Write-Host -ForegroundColor Cyan "[$([DateTime]::Now.ToString("yyyy-MM-dd HH:mm:ss"))] Finished building '$src' to '$dst' for arch '$($Arch.LLVMName)' in $($Stopwatch.Elapsed)"
Write-Host ""
}

if ($Summary) {
$TimingData.Add([PSCustomObject]@{
Arch = $BuildArch.LLVMName
Checkout = $src.Replace($SourceCache, '')
Platform = "Windows"
"Elapsed Time" = $Stopwatch.Elapsed.ToString()
})
}
}
} else {
Build-CMakeProject `
-Src $SourceCache\swift-driver `
-Bin (Get-HostProjectBinaryCache Driver) `
-InstallTo "$($Arch.ToolchainInstallRoot)\usr" `
-Arch $Arch `
-Platform Windows `
-UseBuiltCompilers C,CXX,Swift `
-SwiftSDK (Get-HostSwiftSDK) `
-Defines @{
BUILD_SHARED_LIBS = "YES";
SwiftSystem_DIR = (Get-HostProjectCMakeModules System);
TSC_DIR = (Get-HostProjectCMakeModules ToolsSupportCore);
LLBuild_DIR = (Get-HostProjectCMakeModules LLBuild);
Yams_DIR = (Get-HostProjectCMakeModules Yams);
ArgumentParser_DIR = (Get-HostProjectCMakeModules ArgumentParser);
SQLite3_INCLUDE_DIR = "$LibraryRoot\sqlite-3.46.0\usr\include";
SQLite3_LIBRARY = "$LibraryRoot\sqlite-3.46.0\usr\lib\SQLite3.lib";
SWIFT_DRIVER_BUILD_TOOLS = "YES";
LLVM_DIR = "$(Get-HostProjectBinaryCache Compilers)\lib\cmake\llvm";
Clang_DIR = "$(Get-HostProjectBinaryCache Compilers)\lib\cmake\clang";
Swift_DIR = "$(Get-HostProjectBinaryCache Compilers)\tools\swift\lib\cmake\swift";
}
}
}

function Build-Crypto($Arch) {
Expand Down Expand Up @@ -2577,7 +2676,7 @@ function Build-TestingMacros() {
Get-HostProjectBinaryCache TestingMacros
}

$SwiftSDK = $null
$SwiftSDK = $((Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot)
if ($Build) {
$SwiftSDK = $BuildArch.SDKInstallRoot
}
Expand Down Expand Up @@ -2608,7 +2707,7 @@ function Build-TestingMacros() {
-Arch $Arch `
-Platform $Platform `
-UseBuiltCompilers Swift `
-SwiftSDK:$SwiftSDK `
-SwiftSDK $SwiftSDK `
-BuildTargets:$Targets `
-Defines @{
SwiftSyntax_DIR = $SwiftSyntaxCMakeModules;
Expand Down Expand Up @@ -2747,6 +2846,7 @@ Fetch-Dependencies
if (-not $SkipBuild) {
Invoke-BuildStep Build-CMark $BuildArch
Invoke-BuildStep Build-BuildTools $BuildArch
Invoke-BuildStep Build-Driver -Build $BuildArch
if ($IsCrossCompiling) {
Invoke-BuildStep Build-Compilers -Build $BuildArch
}
Expand Down