Skip to content

Commit 99a7a98

Browse files
authored
Merge pull request swiftlang#71915 from compnerd/platform
utils: start wiring up platform in the build
2 parents 0b5de06 + fe7d5c2 commit 99a7a98

File tree

1 file changed

+71
-37
lines changed

1 file changed

+71
-37
lines changed

utils/build.ps1

Lines changed: 71 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -570,12 +570,18 @@ function Test-CMakeAtLeast([int]$Major, [int]$Minor, [int]$Patch = 0) {
570570
return [int]$Matches.3 -ge $Patch
571571
}
572572

573+
enum Platform {
574+
Windows
575+
Android
576+
}
577+
573578
function Build-CMakeProject {
574579
[CmdletBinding(PositionalBinding = $false)]
575580
param(
576581
[string] $Src,
577582
[string] $Bin,
578583
[string] $InstallTo = "",
584+
[Platform] $Platform = "Windows",
579585
[hashtable] $Arch,
580586
[string] $Generator = "Ninja",
581587
[string] $CacheScript = "",
@@ -600,7 +606,9 @@ function Build-CMakeProject {
600606
# Enter the developer command shell early so we can resolve cmake.exe
601607
# for version checks.
602608
Isolate-EnvVars {
603-
Invoke-VsDevShell $Arch
609+
if ($Platform -eq "Windows") {
610+
Invoke-VsDevShell $Arch
611+
}
604612

605613
$CompilersBinaryCache = Get-HostProjectBinaryCache Compilers
606614
$DriverBinaryCache = Get-HostProjectBinaryCache Driver
@@ -624,7 +632,16 @@ function Build-CMakeProject {
624632
TryAdd-KeyValue $Defines CMAKE_BUILD_TYPE Release
625633
TryAdd-KeyValue $Defines CMAKE_MT "mt"
626634

627-
$CFlags = @("/GS-", "/Gw", "/Gy", "/Oi", "/Oy", "/Zc:inline")
635+
$CFlags = @()
636+
if ($Platform -eq "Windows") {
637+
$CFlags = @("/GS-", "/Gw", "/Gy", "/Oi", "/Oy", "/Zc:inline")
638+
}
639+
640+
$CXXFlags = @()
641+
if ($Platform -eq "Windows") {
642+
$CXXFlags += $CFlags.Clone() + @("/Zc:__cplusplus")
643+
}
644+
628645
if ($UseMSVCCompilers.Contains("C") -Or $UseMSVCCompilers.Contains("CXX") -Or
629646
$UseBuiltCompilers.Contains("C") -Or $UseBuiltCompilers.Contains("CXX") -Or
630647
$UsePinnedCompilers.Contains("C") -Or $UsePinnedCompilers.Contains("CXX")) {
@@ -636,7 +653,6 @@ function Build-CMakeProject {
636653
Append-FlagsDefine $Defines CMAKE_EXE_LINKER_FLAGS "/debug"
637654
}
638655
}
639-
$CXXFlags = $CFlags.Clone() + "/Zc:__cplusplus"
640656

641657
if ($UseMSVCCompilers.Contains("C")) {
642658
TryAdd-KeyValue $Defines CMAKE_C_COMPILER cl
@@ -809,8 +825,8 @@ function Build-CMakeProject {
809825
if ($Summary) {
810826
$TimingData.Add([PSCustomObject]@{
811827
Arch = $Arch.LLVMName
828+
Platform = $Platform
812829
Checkout = $Src.Replace($SourceCache, '')
813-
BuildID = Split-Path -Path $Bin -Leaf
814830
"Elapsed Time" = $Stopwatch.Elapsed.ToString()
815831
})
816832
}
@@ -875,7 +891,7 @@ function Build-SPMProject {
875891
$TimingData.Add([PSCustomObject]@{
876892
Arch = $Arch.LLVMName
877893
Checkout = $Src.Replace($SourceCache, '')
878-
BuildID = Split-Path -Path $Bin -Leaf
894+
Platform = "Windows"
879895
"Elapsed Time" = $Stopwatch.Elapsed.ToString()
880896
})
881897
}
@@ -1060,16 +1076,14 @@ function Build-Compilers() {
10601076
}
10611077
}
10621078

1063-
enum Platform {
1064-
Windows
1065-
}
1066-
10671079
function Build-LLVM([Platform]$Platform, $Arch) {
10681080
Build-CMakeProject `
10691081
-Src $SourceCache\llvm-project\llvm `
10701082
-Bin (Get-TargetProjectBinaryCache $Arch LLVM) `
10711083
-Arch $Arch `
1084+
-Platform $Platform `
10721085
-Defines @{
1086+
CMAKE_SYSTEM_NAME = if ($Platform -eq "Windows") { "Windows" } else { "Android" };
10731087
LLVM_HOST_TRIPLE = $Arch.LLVMTarget;
10741088
}
10751089
}
@@ -1079,14 +1093,16 @@ function Build-ZLib([Platform]$Platform, $Arch) {
10791093

10801094
Build-CMakeProject `
10811095
-Src $SourceCache\zlib `
1082-
-Bin "$($Arch.BinaryCache)\zlib-1.3" `
1096+
-Bin "$($Arch.BinaryCache)\$Platform\zlib-1.3" `
10831097
-InstallTo $LibraryRoot\zlib-1.3\usr `
10841098
-Arch $Arch `
1099+
-Platform $Platform `
10851100
-BuildTargets default `
10861101
-Defines @{
10871102
BUILD_SHARED_LIBS = "NO";
1088-
INSTALL_BIN_DIR = "$LibraryRoot\zlib-1.3\usr\bin\$ArchName";
1089-
INSTALL_LIB_DIR = "$LibraryRoot\zlib-1.3\usr\lib\$ArchName";
1103+
CMAKE_SYSTEM_NAME = if ($Platform -eq "Windows") { "Windows" } else { "Android" };
1104+
INSTALL_BIN_DIR = "$LibraryRoot\zlib-1.3\usr\bin\$Platform\$ArchName";
1105+
INSTALL_LIB_DIR = "$LibraryRoot\zlib-1.3\usr\lib\$Platform\$ArchName";
10901106
}
10911107
}
10921108

@@ -1095,14 +1111,16 @@ function Build-XML2([Platform]$Platform, $Arch) {
10951111

10961112
Build-CMakeProject `
10971113
-Src $SourceCache\libxml2 `
1098-
-Bin "$($Arch.BinaryCache)\libxml2-2.11.5" `
1114+
-Bin "$($Arch.BinaryCache)\$Platform\libxml2-2.11.5" `
10991115
-InstallTo "$LibraryRoot\libxml2-2.11.5\usr" `
11001116
-Arch $Arch `
1117+
-Platform $Platform `
11011118
-BuildTargets default `
11021119
-Defines @{
11031120
BUILD_SHARED_LIBS = "NO";
1104-
CMAKE_INSTALL_BINDIR = "bin/$ArchName";
1105-
CMAKE_INSTALL_LIBDIR = "lib/$ArchName";
1121+
CMAKE_INSTALL_BINDIR = "bin/$Platform/$ArchName";
1122+
CMAKE_INSTALL_LIBDIR = "lib/$Platform/$ArchName";
1123+
CMAKE_SYSTEM_NAME = if ($Platform -eq "Windows") { "Windows" } else { "Android" };
11061124
LIBXML2_WITH_ICONV = "NO";
11071125
LIBXML2_WITH_ICU = "NO";
11081126
LIBXML2_WITH_LZMA = "NO";
@@ -1116,16 +1134,25 @@ function Build-XML2([Platform]$Platform, $Arch) {
11161134
function Build-CURL([Platform]$Platform, $Arch) {
11171135
$ArchName = $Arch.LLVMName
11181136

1137+
$PlatformDefines = @{}
1138+
if ($Platform -eq "Android") {
1139+
$PlatformDefines += @{
1140+
HAVE_FSEEKO = "0";
1141+
}
1142+
}
1143+
11191144
Build-CMakeProject `
11201145
-Src $SourceCache\curl `
1121-
-Bin "$($Arch.BinaryCache)\curl-8.4.0" `
1146+
-Bin "$($Arch.BinaryCache)\$Platform\curl-8.4.0" `
11221147
-InstallTo "$LibraryRoot\curl-8.4.0\usr" `
11231148
-Arch $Arch `
1149+
-Platform $Platform `
11241150
-BuildTargets default `
1125-
-Defines @{
1151+
-Defines ($PlatformDefines + @{
11261152
BUILD_SHARED_LIBS = "NO";
11271153
BUILD_TESTING = "NO";
1128-
CMAKE_INSTALL_LIBDIR = "lib/$ArchName";
1154+
CMAKE_INSTALL_LIBDIR = "lib/$Platform/$ArchName";
1155+
CMAKE_SYSTEM_NAME = if ($Platform -eq "Windows") { "Windows" } else { "Android" };
11291156
BUILD_CURL_EXE = "NO";
11301157
CURL_CA_BUNDLE = "none";
11311158
CURL_CA_FALLBACK = "NO";
@@ -1178,9 +1205,9 @@ function Build-CURL([Platform]$Platform, $Arch) {
11781205
CURL_USE_LIBSSH2 = "NO";
11791206
CURL_USE_MBEDTLS = "NO";
11801207
CURL_USE_OPENSSL = "NO";
1181-
CURL_USE_SCHANNEL = "YES";
1208+
CURL_USE_SCHANNEL = if ($Platform -eq "Windows") { "YES" } else { "NO" };
11821209
CURL_USE_WOLFSSL = "NO";
1183-
CURL_WINDOWS_SSPI = "YES";
1210+
CURL_WINDOWS_SSPI = if ($Platform -eq "Windows") { "YES" } else { "NO" };
11841211
CURL_ZLIB = "YES";
11851212
CURL_ZSTD = "NO";
11861213
ENABLE_ARES = "NO";
@@ -1198,12 +1225,12 @@ function Build-CURL([Platform]$Platform, $Arch) {
11981225
USE_NGHTTP2 = "NO";
11991226
USE_NGTCP2 = "NO";
12001227
USE_QUICHE = "NO";
1201-
USE_WIN32_IDN = "YES";
1202-
USE_WIN32_LARGE_FILES = "YES";
1228+
USE_WIN32_IDN = if ($Platform -eq "Windows") { "YES" } else { "NO" };
1229+
USE_WIN32_LARGE_FILES = if ($Platform -eq "Windows") { "YES" } else { "NO" };
12031230
USE_WIN32_LDAP = "NO";
12041231
ZLIB_ROOT = "$LibraryRoot\zlib-1.3\usr";
1205-
ZLIB_LIBRARY = "$LibraryRoot\zlib-1.3\usr\lib\$ArchName\zlibstatic.lib";
1206-
}
1232+
ZLIB_LIBRARY = "$LibraryRoot\zlib-1.3\usr\lib\$Platform\$ArchName\zlibstatic.lib";
1233+
})
12071234
}
12081235

12091236
function Build-ICU([Platform]$Platform, $Arch) {
@@ -1216,26 +1243,28 @@ function Build-ICU([Platform]$Platform, $Arch) {
12161243
}
12171244
}
12181245

1219-
if ($Arch -eq $ArchARM64 -and $HostArch -ne $ArchARM64) {
1246+
if ($Platform -ne "Windows" -or ($Arch -eq $ArchARM64 -and $HostArch -ne $ArchARM64)) {
12201247
# Use previously built x64 tools
12211248
$BuildToolsDefines = @{
12221249
BUILD_TOOLS = "NO";
1223-
ICU_TOOLS_DIR = "$($ArchX64.BinaryCache)\icu-69.1"
1250+
ICU_TOOLS_DIR = "$($ArchX64.BinaryCache)\windows\icu-69.1"
12241251
}
12251252
} else {
12261253
$BuildToolsDefines = @{BUILD_TOOLS = "YES"}
12271254
}
12281255

12291256
Build-CMakeProject `
12301257
-Src $SourceCache\icu\icu4c `
1231-
-Bin "$($Arch.BinaryCache)\icu-69.1" `
1258+
-Bin "$($Arch.BinaryCache)\$Platform\icu-69.1" `
12321259
-InstallTo "$LibraryRoot\icu-69.1\usr" `
12331260
-Arch $Arch `
1261+
-Platform $Platform `
12341262
-BuildTargets default `
12351263
-Defines ($BuildToolsDefines + @{
12361264
BUILD_SHARED_LIBS = "NO";
1237-
CMAKE_INSTALL_BINDIR = "bin/$ArchName";
1238-
CMAKE_INSTALL_LIBDIR = "lib/$ArchName";
1265+
CMAKE_SYSTEM_NAME = if ($Platform -eq "Windows") { "Windows" } else { "Android" };
1266+
CMAKE_INSTALL_BINDIR = "bin/$Platform/$ArchName";
1267+
CMAKE_INSTALL_LIBDIR = "lib/$Platform/$ArchName";
12391268
})
12401269
}
12411270

@@ -1248,12 +1277,14 @@ function Build-Runtime([Platform]$Platform, $Arch) {
12481277
-Bin (Get-TargetProjectBinaryCache $Arch Runtime) `
12491278
-InstallTo "$($Arch.SDKInstallRoot)\usr" `
12501279
-Arch $Arch `
1280+
-Platform $Platform `
12511281
-CacheScript $SourceCache\swift\cmake\caches\Runtime-Windows-$($Arch.LLVMName).cmake `
12521282
-UseBuiltCompilers C,CXX,Swift `
12531283
-BuildTargets default `
12541284
-Defines @{
12551285
CMAKE_Swift_COMPILER_TARGET = $Arch.LLVMTarget;
12561286
CMAKE_Swift_COMPILER_WORKS = "YES";
1287+
CMAKE_SYSTEM_NAME = if ($Platform -eq "Windows") { "Windows" } else { "Android" };
12571288
LLVM_DIR = "$(Get-TargetProjectBinaryCache $Arch LLVM)\lib\cmake\llvm";
12581289
SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY = "YES";
12591290
SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP = "YES";
@@ -1281,6 +1312,7 @@ function Build-Dispatch([Platform]$Platform, $Arch, [switch]$Test = $false) {
12811312
-Bin (Get-TargetProjectBinaryCache $Arch Dispatch) `
12821313
-InstallTo "$($Arch.SDKInstallRoot)\usr" `
12831314
-Arch $Arch `
1315+
-Platform $Platform `
12841316
-UseBuiltCompilers C,CXX,Swift `
12851317
-BuildTargets $Targets `
12861318
-Defines @{
@@ -1315,6 +1347,7 @@ function Build-Foundation([Platform]$Platform, $Arch, [switch]$Test = $false) {
13151347
-Bin $FoundationBinaryCache `
13161348
-InstallTo "$($Arch.SDKInstallRoot)\usr" `
13171349
-Arch $Arch `
1350+
-Platform $Platform `
13181351
-UseBuiltCompilers ASM,C,Swift `
13191352
-BuildTargets $Targets `
13201353
-Defines (@{
@@ -1324,15 +1357,15 @@ function Build-Foundation([Platform]$Platform, $Arch, [switch]$Test = $false) {
13241357
# and fails with an ICU data object file icudt69l_dat.obj. This
13251358
# matters to X86 only.
13261359
CMAKE_Swift_FLAGS = if ($Arch -eq $ArchX86) { @("-Xlinker", "/SAFESEH:NO") } else { "" };
1327-
CURL_DIR = "$LibraryRoot\curl-8.4.0\usr\lib\$ShortArch\cmake\CURL";
1328-
ICU_DATA_LIBRARY_RELEASE = "$LibraryRoot\icu-69.1\usr\lib\$ShortArch\sicudt69.lib";
1329-
ICU_I18N_LIBRARY_RELEASE = "$LibraryRoot\icu-69.1\usr\lib\$ShortArch\sicuin69.lib";
1360+
CURL_DIR = "$LibraryRoot\curl-8.4.0\usr\lib\$Platform\$ShortArch\cmake\CURL";
1361+
ICU_DATA_LIBRARY_RELEASE = "$LibraryRoot\icu-69.1\usr\lib\$Platform\$ShortArch\sicudt69.lib";
1362+
ICU_I18N_LIBRARY_RELEASE = "$LibraryRoot\icu-69.1\usr\lib\$Platform\$ShortArch\sicuin69.lib";
13301363
ICU_ROOT = "$LibraryRoot\icu-69.1\usr";
1331-
ICU_UC_LIBRARY_RELEASE = "$LibraryRoot\icu-69.1\usr\lib\$ShortArch\sicuuc69.lib";
1332-
LIBXML2_LIBRARY = "$LibraryRoot\libxml2-2.11.5\usr\lib\$ShortArch\libxml2s.lib";
1364+
ICU_UC_LIBRARY_RELEASE = "$LibraryRoot\icu-69.1\usr\lib\$Platform\$ShortArch\sicuuc69.lib";
1365+
LIBXML2_LIBRARY = "$LibraryRoot\libxml2-2.11.5\usr\lib\$Platform\$ShortArch\libxml2s.lib";
13331366
LIBXML2_INCLUDE_DIR = "$LibraryRoot\libxml2-2.11.5\usr\include\libxml2";
13341367
LIBXML2_DEFINITIONS = "/DLIBXML_STATIC";
1335-
ZLIB_LIBRARY = "$LibraryRoot\zlib-1.3\usr\lib\$ShortArch\zlibstatic.lib";
1368+
ZLIB_LIBRARY = "$LibraryRoot\zlib-1.3\usr\lib\$Platform\$ShortArch\zlibstatic.lib";
13361369
ZLIB_INCLUDE_DIR = "$LibraryRoot\zlib-1.3\usr\include";
13371370
dispatch_DIR = "$DispatchBinaryCache\cmake\modules";
13381371
} + $TestingDefines)
@@ -1365,6 +1398,7 @@ function Build-XCTest([Platform]$Platform, $Arch, [switch]$Test = $false) {
13651398
-Bin $XCTestBinaryCache `
13661399
-InstallTo "$($Arch.XCTestInstallRoot)\usr" `
13671400
-Arch $Arch `
1401+
-Platform $Platform `
13681402
-UseBuiltCompilers Swift `
13691403
-BuildTargets $Targets `
13701404
-Defines (@{
@@ -1902,7 +1936,7 @@ if (-not $SkipBuild) {
19021936
if ($Clean) {
19031937
2..16 | % { Remove-Item -Force -Recurse "$BinaryCache\$_" -ErrorAction Ignore }
19041938
foreach ($Arch in $WindowsSDKArchs) {
1905-
0..3 | % { Remove-Item -Force -Recurse "$BinaryCache\$($Arch.BuildiD + $_)" -ErrorAction Ignore }
1939+
0..3 | % { Remove-Item -Force -Recurse "$BinaryCache\$($Arch.BuildID + $_)" -ErrorAction Ignore }
19061940
}
19071941
}
19081942

@@ -2021,6 +2055,6 @@ if ($Test -contains "swiftpm") { Test-PackageManager $HostArch }
20212055
exit 1
20222056
} finally {
20232057
if ($Summary) {
2024-
$TimingData | Select Arch,Checkout,BuildID,"Elapsed Time" | Sort -Descending -Property "Elapsed Time" | Format-Table -AutoSize
2058+
$TimingData | Select Platform,Arch,Checkout,"Elapsed Time" | Sort -Descending -Property "Elapsed Time" | Format-Table -AutoSize
20252059
}
20262060
}

0 commit comments

Comments
 (0)