Skip to content

Commit af46e6c

Browse files
committed
build.ps1: intrduce the ability to build with clang optionally
Add a `-UseHostCompiler` option which allows you to to pass in `-UseHostCompiler=$False` to switch to using the bootstrap compiler to build the toolchain.
1 parent 46677a5 commit af46e6c

File tree

1 file changed

+34
-18
lines changed

1 file changed

+34
-18
lines changed

utils/build.ps1

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ param
170170
# Toolchain Cross-compilation
171171
[ValidateSet("AMD64", "ARM64")]
172172
[string] $HostArchName = $(if ($env:PROCESSOR_ARCHITEW6432) { $env:PROCESSOR_ARCHITEW6432 } else { $env:PROCESSOR_ARCHITECTURE }),
173+
[object] $UseHostToolchain = $true,
173174

174175
# Debug Information
175176
[switch] $DebugInfo,
@@ -248,6 +249,10 @@ if ($Test -contains "*") {
248249
$Test = @("lld", "lldb", "swift", "dispatch", "foundation", "xctest", "swift-format", "sourcekit-lsp")
249250
}
250251

252+
if ($UseHostToolchain -is [string]) {
253+
$UseHostToolchain = [System.Convert]::ToBoolean($UseHostToolchain)
254+
}
255+
251256
## Declare static build and build tool parameters.
252257

253258
$DefaultPinned = @{
@@ -1345,11 +1350,11 @@ function Build-CMakeProject {
13451350
[hashtable] $Platform,
13461351
[string] $Generator = "Ninja",
13471352
[string] $CacheScript = "",
1348-
[ValidateSet("ASM_MASM", "C", "CXX")]
1353+
[ValidateSet("", "ASM_MASM", "C", "CXX")]
13491354
[string[]] $UseMSVCCompilers = @(),
1350-
[ValidateSet("ASM", "C", "CXX", "Swift")]
1355+
[ValidateSet("", "ASM", "C", "CXX", "Swift")]
13511356
[string[]] $UseBuiltCompilers = @(),
1352-
[ValidateSet("ASM", "C", "CXX", "Swift")]
1357+
[ValidateSet("", "ASM", "C", "CXX", "Swift")]
13531358
[string[]] $UsePinnedCompilers = @(),
13541359
[switch] $AddAndroidCMakeEnv = $false,
13551360
[switch] $UseGNUDriver = $false,
@@ -1913,7 +1918,8 @@ function Build-CMark([Hashtable] $Platform) {
19131918
-Bin (Get-CMarkBinaryCache $Platform) `
19141919
-InstallTo "$(Get-InstallDir $Platform)\Toolchains\$ProductVersion+Asserts\usr" `
19151920
-Platform $Platform `
1916-
-UseMSVCCompilers C,CXX `
1921+
-UseMSVCCompilers $(if ($UseHostToolchain) { @("C", "CXX") } else { @("") }) `
1922+
-UsePinnedCompilers $(if ($UseHostToolchain) { @("") } else { @("C", "CXX") }) `
19171923
-Defines @{
19181924
BUILD_SHARED_LIBS = "YES";
19191925
BUILD_TESTING = "NO";
@@ -1926,7 +1932,8 @@ function Build-BuildTools([Hashtable] $Platform) {
19261932
-Src $SourceCache\llvm-project\llvm `
19271933
-Bin (Get-ProjectBinaryCache $Platform BuildTools) `
19281934
-Platform $Platform `
1929-
-UseMSVCCompilers ASM_MASM,C,CXX `
1935+
-UseMSVCCompilers $(if ($UseHostToolchain) { @("ASM_MASM", "C", "CXX") } else { @("") }) `
1936+
-UsePinnedCompilers $(if ($UseHostToolchain) { @("") } else { @("ASM", "C", "CXX") }) `
19301937
-BuildTargets llvm-tblgen,clang-tblgen,clang-pseudo-gen,clang-tidy-confusable-chars-gen,lldb-tblgen,llvm-config,swift-def-to-strings-converter,swift-serialize-diagnostics,swift-compatibility-symbols `
19311938
-Defines @{
19321939
CMAKE_CROSSCOMPILING = "NO";
@@ -2088,8 +2095,8 @@ function Build-Compilers([Hashtable] $Platform, [string] $Variant) {
20882095
-Bin (Get-ProjectBinaryCache $Platform Compilers) `
20892096
-InstallTo "$(Get-InstallDir $Platform)\Toolchains\$ProductVersion+$Variant\usr" `
20902097
-Platform $Platform `
2091-
-UseMSVCCompilers C,CXX `
2092-
-UsePinnedCompilers Swift `
2098+
-UseMSVCCompilers $(if ($UseHostToolchain) { @("C", "CXX") } else { @("") }) `
2099+
-UsePinnedCompilers $(if ($UseHostToolchain) { @("Swift") } else { @("C", "CXX", "Swift") }) `
20932100
-SwiftSDK (Get-PinnedToolchainSDK) `
20942101
-BuildTargets @("install-distribution") `
20952102
-CacheScript $SourceCache\swift\cmake\caches\Windows-$($Platform.Architecture.LLVMName).cmake `
@@ -2156,8 +2163,8 @@ function Test-Compilers([Hashtable] $Platform, [string] $Variant, [switch] $Test
21562163
-Bin $(Get-ProjectBinaryCache $Platform Compilers) `
21572164
-InstallTo "$($Platform.ToolchainInstallRoot)\usr" `
21582165
-Platform $Platform `
2159-
-UseMSVCCompilers C,CXX `
2160-
-UsePinnedCompilers Swift `
2166+
-UseMSVCCompilers $(if ($UseHostToolchain) { @("C", "CXX") } else { @("") }) `
2167+
-UsePinnedCompilers $(if ($UseHostToolchain) { @("Swift") } else { @("C", "CXX", "Swift") }) `
21612168
-SwiftSDK (Get-PinnedToolchainSDK) `
21622169
-BuildTargets $Targets `
21632170
-CacheScript $SourceCache\swift\cmake\caches\Windows-$($Platform.Architecture.LLVMName).cmake `
@@ -2310,7 +2317,8 @@ function Build-ZLib([Hashtable] $Platform) {
23102317
-Bin "$BinaryCache\$($Platform.Triple)\zlib" `
23112318
-InstallTo "$BinaryCache\$($Platform.Triple)\usr" `
23122319
-Platform $Platform `
2313-
-UseMSVCCompilers C `
2320+
-UseMSVCCompilers $(if ($UseHostToolchain) { @("C") } else { @("") }) `
2321+
-UsePinnedCompilers $(if ($UseHostToolchain) { @("") } else { @("C") }) `
23142322
-Defines @{
23152323
BUILD_SHARED_LIBS = "NO";
23162324
CMAKE_POSITION_INDEPENDENT_CODE = "YES";
@@ -2323,7 +2331,8 @@ function Build-XML2([Hashtable] $Platform) {
23232331
-Bin "$BinaryCache\$($Platform.Triple)\libxml2-2.11.5" `
23242332
-InstallTo "$BinaryCache\$($Platform.Triple)\usr" `
23252333
-Platform $Platform `
2326-
-UseMSVCCompilers C,CXX `
2334+
-UseMSVCCompilers $(if ($UseHostToolchain) { @("C", "CXX") } else { @("") }) `
2335+
-UsePinnedCompilers $(if ($UseHostToolchain) { @("") } else { @("C", "CXX") }) `
23272336
-Defines @{
23282337
BUILD_SHARED_LIBS = "NO";
23292338
CMAKE_POSITION_INDEPENDENT_CODE = "YES";
@@ -2343,7 +2352,8 @@ function Build-RegsGen2([Hashtable] $Platform) {
23432352
-Bin (Get-ProjectBinaryCache $Platform RegsGen2) `
23442353
-Platform $Platform `
23452354
-BuildTargets default `
2346-
-UseMSVCCompilers C,CXX `
2355+
-UseMSVCCompilers $(if ($UseHostToolchain) { @("C", "CXX") } else { @("") }) `
2356+
-UsePinnedCompilers $(if ($UseHostToolchain) { @("") } else { @("C", "CXX") }) `
23472357
-Defines @{
23482358
BISON_EXECUTABLE = "$(Get-BisonExecutable)";
23492359
FLEX_EXECUTABLE = "$(Get-FlexExecutable)";
@@ -2377,7 +2387,8 @@ function Build-CURL([Hashtable] $Platform) {
23772387
-Bin "$BinaryCache\$($Platform.Triple)\curl" `
23782388
-InstallTo "$BinaryCache\$($Platform.Triple)\usr" `
23792389
-Platform $Platform `
2380-
-UseMSVCCompilers C `
2390+
-UseMSVCCompilers $(if ($UseHostToolchain) { @("C") } else { @("") }) `
2391+
-UsePinnedCompilers $(if ($UseHostToolchain) { @("") } else { @("C") }) `
23812392
-Defines ($PlatformDefines + @{
23822393
BUILD_SHARED_LIBS = "NO";
23832394
BUILD_TESTING = "NO";
@@ -3100,7 +3111,8 @@ function Build-SQLite([Hashtable] $Platform) {
31003111
-Src $SourceCache\swift-toolchain-sqlite `
31013112
-Bin (Get-ProjectBinaryCache $Platform SQLite) `
31023113
-Platform $Platform `
3103-
-UseMSVCCompilers C `
3114+
-UseMSVCCompilers $(if ($UseHostToolchain) { @("C") } else { @("") }) `
3115+
-UsePinnedCompilers $(if ($UseHostToolchain) { @("") } else { @("C") }) `
31043116
-BuildTargets default `
31053117
-Defines @{
31063118
BUILD_SHARED_LIBS = "NO";
@@ -3182,7 +3194,8 @@ function Build-LLBuild([Hashtable] $Platform) {
31823194
-Bin (Get-ProjectBinaryCache $Platform LLBuild) `
31833195
-InstallTo "$($Platform.ToolchainInstallRoot)\usr" `
31843196
-Platform $Platform `
3185-
-UseMSVCCompilers CXX `
3197+
-UseMSVCCompilers $(if ($UseHostToolchain) { @("CXX") } else { @("") }) `
3198+
-UsePinnedCompilers $(if ($UseHostToolchain) { @("") } else { @("CXX") }) `
31863199
-UseBuiltCompilers Swift `
31873200
-SwiftSDK (Get-SwiftSDK $Platform.OS) `
31883201
-Defines @{
@@ -3209,7 +3222,8 @@ function Test-LLBuild {
32093222
-Src $SourceCache\llbuild `
32103223
-Bin (Get-ProjectBinaryCache $BuildPlatform LLBuild) `
32113224
-Platform $Platform `
3212-
-UseMSVCCompilers CXX `
3225+
-UseMSVCCompilers $(if ($UseHostToolchain) { @("CXX") } else { @("") }) `
3226+
-UsePinnedCompilers $(if ($UseHostToolchain) { @("") } else { @("CXX") }) `
32133227
-UseBuiltCompilers Swift `
32143228
-SwiftSDK (Get-SwiftSDK $BuildPlatform.OS) `
32153229
-BuildTargets default,test-llbuild `
@@ -3377,7 +3391,8 @@ function Build-Format([Hashtable] $Platform) {
33773391
-Bin (Get-ProjectBinaryCache $Platform Format) `
33783392
-InstallTo "$($Platform.ToolchainInstallRoot)\usr" `
33793393
-Platform $Platform `
3380-
-UseMSVCCompilers C `
3394+
-UseMSVCCompilers $(if ($UseHostToolchain) { @("C") } else { @("") }) `
3395+
-UsePinnedCompilers $(if ($UseHostToolchain) { @("") } else { @("C") }) `
33813396
-UseBuiltCompilers Swift `
33823397
-SwiftSDK (Get-SwiftSDK $Platform.OS) `
33833398
-Defines @{
@@ -3432,7 +3447,8 @@ function Build-LMDB([Hashtable] $Platform) {
34323447
-Src $SourceCache\swift-lmdb `
34333448
-Bin (Get-ProjectBinaryCache $Platform LMDB) `
34343449
-Platform $Platform `
3435-
-UseMSVCCompilers C `
3450+
-UseMSVCCompilers $(if ($UseHostToolchain) { @("C") } else { @("") }) `
3451+
-UsePinnedCompilers $(if ($UseHostToolchain) { @("") } else { @("C") }) `
34363452
-BuildTargets default
34373453
}
34383454

0 commit comments

Comments
 (0)