Skip to content

Commit 5917dce

Browse files
Add code to build.ps1 to build the installer (not called yet) (#463)
* Add code to build the installer (not called yet) * Add BINDIR redirection for runtime binaries & PR feedback. * MSBuildArgs casing * Added comment about commented code * Remove manual nuget download of WiX Co-authored-by: Saleem Abdulrasool <[email protected]>
1 parent 712b0dc commit 5917dce

File tree

1 file changed

+86
-39
lines changed

1 file changed

+86
-39
lines changed

build.ps1

Lines changed: 86 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ $PlatformInstallRoot = "$InstallRoot\Developer\Platforms\Windows.platform"
1616
$SDKInstallRoot = "$PlatformInstallRoot\Developer\SDKs\Windows.sdk"
1717

1818
$vswhere = "${Env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
19-
$VSInstallRoot = .$vswhere -nologo -latest -products "*" -all -prerelease -property installationPath
19+
$VSInstallRoot = & $vswhere -nologo -latest -products "*" -all -prerelease -property installationPath
20+
$msbuild = "$VSInstallRoot\MSBuild\Current\Bin\$env:PROCESSOR_ARCHITECTURE\MSBuild.exe"
2021

2122
# Architecture definitions
2223
$ArchX64 = @{
@@ -81,6 +82,15 @@ function Get-ProjectBuildDir($Arch, $ID)
8182
return "$BinaryCache\" + ($Arch.BuildID + $ID)
8283
}
8384

85+
function Get-RuntimeInstallDir($Arch, $SubDir = "")
86+
{
87+
$Path = "$InstallRoot\swift-development\$($Arch.ShortName)"
88+
if ("" -ne $SubDir) {
89+
$Path += "\$SubDir"
90+
}
91+
return $Path
92+
}
93+
8494
function Check-LastExitCode
8595
{
8696
if ($LastExitCode -ne 0)
@@ -102,11 +112,11 @@ function Invoke-VsDevShell($Arch)
102112
Check-LastExitCode
103113
}
104114

105-
function TryAdd-Define([hashtable]$Defines, [string]$Name, [string]$Value)
115+
function TryAdd-KeyValue([hashtable]$Hashtable, [string]$Key, [string]$Value)
106116
{
107-
if (-not $Defines.Contains($Name))
117+
if (-not $Hashtable.Contains($Key))
108118
{
109-
$Defines.Add($Name, $Value)
119+
$Hashtable.Add($Key, $Value)
110120
}
111121
}
112122

@@ -152,39 +162,39 @@ function Build-CMakeProject
152162

153163
# Add additional defines (unless already present)
154164
$Defines = $Defines.Clone()
155-
TryAdd-Define $Defines CMAKE_BUILD_TYPE $BuildType
156-
TryAdd-Define $Defines CMAKE_MT "mt"
165+
TryAdd-KeyValue $Defines CMAKE_BUILD_TYPE $BuildType
166+
TryAdd-KeyValue $Defines CMAKE_MT "mt"
157167

158168
$CFlags = "/GS- /Gw /Gy /Oi /Oy /Zi /Zc:inline"
159169
$CXXFlags = "/GS- /Gw /Gy /Oi /Oy /Zi /Zc:inline /Zc:__cplusplus"
160170
if ($UseMSVCCompilers.Contains("C"))
161171
{
162-
TryAdd-Define $Defines CMAKE_C_COMPILER cl
172+
TryAdd-KeyValue $Defines CMAKE_C_COMPILER cl
163173
Append-FlagsDefine $Defines CMAKE_C_FLAGS $CFlags
164174
}
165175
if ($UseMSVCCompilers.Contains("CXX"))
166176
{
167-
TryAdd-Define $Defines CMAKE_CXX_COMPILER cl
177+
TryAdd-KeyValue $Defines CMAKE_CXX_COMPILER cl
168178
Append-FlagsDefine $Defines CMAKE_CXX_FLAGS $CXXFlags
169179
}
170180
if ($UseBuiltCompilers.Contains("ASM")) {
171-
TryAdd-Define $Defines CMAKE_ASM_COMPILER S:/b/1/bin/clang-cl.exe
181+
TryAdd-KeyValue $Defines CMAKE_ASM_COMPILER S:/b/1/bin/clang-cl.exe
172182
Append-FlagsDefine $Defines CMAKE_ASM_FLAGS "--target=$($Arch.LLVMTarget)"
173-
TryAdd-Define $Defines CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL "/MD"
183+
TryAdd-KeyValue $Defines CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL "/MD"
174184
}
175185
if ($UseBuiltCompilers.Contains("C")) {
176-
TryAdd-Define $Defines CMAKE_C_COMPILER S:/b/1/bin/clang-cl.exe
177-
TryAdd-Define $Defines CMAKE_C_COMPILER_TARGET $Arch.LLVMTarget
186+
TryAdd-KeyValue $Defines CMAKE_C_COMPILER S:/b/1/bin/clang-cl.exe
187+
TryAdd-KeyValue $Defines CMAKE_C_COMPILER_TARGET $Arch.LLVMTarget
178188
Append-FlagsDefine $Defines CMAKE_C_FLAGS $CFlags
179189
}
180190
if ($UseBuiltCompilers.Contains("CXX")) {
181-
TryAdd-Define $Defines CMAKE_CXX_COMPILER S:/b/1/bin/clang-cl.exe
182-
TryAdd-Define $Defines CMAKE_CXX_COMPILER_TARGET $Arch.LLVMTarget
191+
TryAdd-KeyValue $Defines CMAKE_CXX_COMPILER S:/b/1/bin/clang-cl.exe
192+
TryAdd-KeyValue $Defines CMAKE_CXX_COMPILER_TARGET $Arch.LLVMTarget
183193
Append-FlagsDefine $Defines CMAKE_CXX_FLAGS $CXXFlags
184194
}
185195
if ($UseBuiltCompilers.Contains("Swift")) {
186-
TryAdd-Define $Defines CMAKE_Swift_COMPILER S:/b/1/bin/swiftc.exe
187-
TryAdd-Define $Defines CMAKE_Swift_COMPILER_TARGET $Arch.LLVMTarget
196+
TryAdd-KeyValue $Defines CMAKE_Swift_COMPILER S:/b/1/bin/swiftc.exe
197+
TryAdd-KeyValue $Defines CMAKE_Swift_COMPILER_TARGET $Arch.LLVMTarget
188198

189199
$RuntimeBuildDir = Get-ProjectBuildDir $Arch 1
190200
$SwiftResourceDir = "${RuntimeBuildDir}\lib\swift"
@@ -202,7 +212,7 @@ function Build-CMakeProject
202212
Append-FlagsDefine $Defines CMAKE_Swift_FLAGS $SwiftcFlags
203213
}
204214
if ("" -ne $InstallTo) {
205-
TryAdd-Define $Defines CMAKE_INSTALL_PREFIX $InstallTo
215+
TryAdd-KeyValue $Defines CMAKE_INSTALL_PREFIX $InstallTo
206216
}
207217

208218
# Generate the project
@@ -240,6 +250,32 @@ function Build-CMakeProject
240250
Write-Host ""
241251
}
242252

253+
function Build-WiXProject()
254+
{
255+
[CmdletBinding(PositionalBinding = $false)]
256+
param(
257+
[Parameter(Position = 0)]
258+
[string]$FileName,
259+
[hashtable]$Properties = @{}
260+
)
261+
262+
$Name = $FileName.Split('.')[0]
263+
264+
$Properties = $Properties.Clone()
265+
TryAdd-KeyValue $Properties RunWixToolsOutOfProc true
266+
TryAdd-KeyValue $Properties OutputPath $BinaryCache\msi\
267+
TryAdd-KeyValue $Properties IntermediateOutputPath BinaryCache\$Name\
268+
269+
$MSBuildArgs = @("$SourceCache\swift-installer-scripts\platforms\Windows\$FileName")
270+
$MSBuildArgs += "-noLogo"
271+
foreach ($Property in $Properties.GetEnumerator()) {
272+
$MSBuildArgs += "-p:$($Property.Key)=$($Property.Value)"
273+
}
274+
275+
& $msbuild @MSBuildArgs
276+
Check-LastExitCode
277+
}
278+
243279
function Build-Compilers($Arch)
244280
{
245281
Build-CMakeProject `
@@ -415,6 +451,7 @@ function Build-Runtime($Arch)
415451
-UseBuiltCompilers C,CXX `
416452
-BuildDefaultTarget `
417453
-Defines @{
454+
CMAKE_INSTALL_BINDIR = Get-RuntimeInstallDir $Arch "usr\bin";
418455
LLVM_DIR = "$LLVMBuildDir\lib\cmake\llvm";
419456
SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY = "YES";
420457
SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING = "YES";
@@ -426,13 +463,6 @@ function Build-Runtime($Arch)
426463
SWIFT_PATH_TO_STRING_PROCESSING_SOURCE = "$SourceCache\swift-experimental-string-processing";
427464
SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE = "$SourceCache\swift-syntax";
428465
}
429-
430-
# Restructure runtime
431-
New-Item -ErrorAction Ignore -Type Directory `
432-
-Path $InstallRoot\swift-development\usr\bin\$($Arch.ShortName)
433-
Move-Item -Force `
434-
$SDKInstallRoot\usr\bin\*.dll `
435-
$InstallRoot\swift-development\usr\bin\$($Arch.ShortName)\
436466
}
437467

438468
function Build-Dispatch($Arch)
@@ -445,19 +475,13 @@ function Build-Dispatch($Arch)
445475
-UseBuiltCompilers C,CXX,Swift `
446476
-BuildDefaultTarget `
447477
-Defines @{
478+
CMAKE_INSTALL_BINDIR = Get-RuntimeInstallDir $Arch "usr\bin";
448479
CMAKE_SYSTEM_NAME = "Windows";
449480
CMAKE_SYSTEM_PROCESSOR = $Arch.CMakeName;
450481
ENABLE_SWIFT = "YES";
451482
BUILD_TESTING = "NO";
452483
}
453484

454-
# Restructure Runtime
455-
New-Item -ErrorAction Ignore -Type Directory `
456-
-Path $InstallRoot\swift-development\usr\bin\$($Arch.ShortName)
457-
Move-Item -Force `
458-
$SDKInstallRoot\usr\bin\*.dll `
459-
$InstallRoot\swift-development\usr\bin\$($Arch.ShortName)\
460-
461485
# Restructure BlocksRuntime, dispatch headers
462486
foreach ($module in ("Block", "dispatch", "os"))
463487
{
@@ -500,6 +524,7 @@ function Build-Foundation($Arch)
500524
-UseBuiltCompilers ASM,C,Swift `
501525
-BuildDefaultTarget `
502526
-Defines @{
527+
CMAKE_INSTALL_BINDIR = Get-RuntimeInstallDir $Arch "usr\bin";
503528
CMAKE_SYSTEM_NAME = "Windows";
504529
CMAKE_SYSTEM_PROCESSOR = $Arch.CMakeName;
505530
CURL_DIR = "$InstallRoot\curl-7.77.0\usr\lib\$ShortArch\cmake\CURL";
@@ -516,14 +541,6 @@ function Build-Foundation($Arch)
516541
ENABLE_TESTING = "NO";
517542
}
518543

519-
# Restructure Runtime
520-
Move-Item -Force `
521-
$SDKInstallRoot\usr\bin\*.dll `
522-
$InstallRoot\swift-development\usr\bin\$ShortArch\
523-
Move-Item -Force `
524-
$SDKInstallRoot\usr\bin\*.exe `
525-
$InstallRoot\swift-development\usr\bin\$ShortArch\
526-
527544
# Remove CoreFoundation Headers
528545
foreach ($module in ("CoreFoundation", "CFXMLInterface", "CFURLSessionInterface"))
529546
{
@@ -912,6 +929,36 @@ function Build-SourceKitLSP($Arch)
912929
}
913930
}
914931

932+
function Build-Installer()
933+
{
934+
# Currently fails due to _InternalSwiftScan paths
935+
# Build-WiXProject toolchain.wixproj -Properties @{
936+
# DEVTOOLS_ROOT = "$ToolchainInstallRoot\";
937+
# TOOLCHAIN_ROOT = "$ToolchainInstallRoot\";
938+
# }
939+
940+
# TODO: The XCTest depends on the architecture
941+
# Build-WiXProject sdk.wixproj -Properties @{
942+
# PLATFORM_ROOT = "$PlatformInstallRoot\";
943+
# SDK_ROOT = "$SDKInstallRoot\";
944+
# SWIFT_SOURCE_DIR = "$SourceCache\swift\";
945+
# }
946+
947+
Build-WiXProject runtime.wixproj -Properties @{
948+
SDK_ROOT = (Get-RuntimeInstallDir $ArchX64) + "\";
949+
}
950+
951+
Build-WiXProject devtools.wixproj -Properties @{
952+
DEVTOOLS_ROOT = "$ToolchainInstallRoot\";
953+
}
954+
955+
# TODO: The above wixprojs need to build
956+
# Build-WiXProject installer.wixproj -Properties @{
957+
# OutputPath = "$BinaryCache\";
958+
# MSI_LOCATION = "$BinaryCache\msi\";
959+
# }
960+
}
961+
915962
#-------------------------------------------------------------------
916963

917964
Build-Compilers $HostArch

0 commit comments

Comments
 (0)