Skip to content

utils: make -BuildTargets optional in build.ps1 #76290

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

Merged
merged 1 commit into from
Sep 9, 2024
Merged
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
105 changes: 50 additions & 55 deletions utils/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ $AndroidARM64 = @{
CMakeName = "aarch64";
LLVMName = "aarch64";
LLVMTarget = "aarch64-unknown-linux-android$AndroidAPILevel";
ShortName = "arm64";
BuildID = 400;
BinaryCache = "$BinaryCache\aarch64";
PlatformInstallRoot = "$BinaryCache\arm64\Android.platform";
Expand All @@ -283,6 +284,7 @@ $AndroidARMv7 = @{
CMakeName = "armv7-a";
LLVMName = "armv7";
LLVMTarget = "armv7-unknown-linux-androideabi$AndroidAPILevel";
ShortName = "armv7";
BuildID = 500;
BinaryCache = "$BinaryCache\armv7";
PlatformInstallRoot = "$BinaryCache\armv7\Android.platform";
Expand All @@ -297,6 +299,7 @@ $AndroidX86 = @{
CMakeName = "i686";
LLVMName = "i686";
LLVMTarget = "i686-unknown-linux-android$AndroidAPILevel";
ShortName = "i686";
BuildID = 600;
BinaryCache = "$BinaryCache\i686";
PlatformInstallRoot = "$BinaryCache\x86\Android.platform";
Expand All @@ -311,6 +314,7 @@ $AndroidX64 = @{
CMakeName = "x86_64";
LLVMName = "x86_64";
LLVMTarget = "x86_64-unknown-linux-android$AndroidAPILevel";
ShortName = "x86_64";
BuildID = 700;
BinaryCache = "$BinaryCache\x86_64";
PlatformInstallRoot = "$BinaryCache\x64\Android.platform";
Expand Down Expand Up @@ -1056,36 +1060,44 @@ function Build-CMakeProject {
}
TryAdd-KeyValue $Defines CMAKE_Swift_COMPILER_TARGET $Arch.LLVMTarget.Replace("$AndroidAPILevel", "")
if ($UseBuiltCompilers.Contains("Swift")) {
if ($SwiftSDK -ne "") {
$SwiftArgs += @("-sdk", $SwiftSDK)
} else {
$RuntimeBinaryCache = Get-TargetProjectBinaryCache $Arch Runtime
$SwiftResourceDir = "${RuntimeBinaryCache}\lib\swift"

switch ($Platform) {
Windows {
$RuntimeBinaryCache = Get-TargetProjectBinaryCache $Arch Runtime
$SwiftResourceDir = "${RuntimeBinaryCache}\lib\swift"

switch ($Platform) {
Windows {
if ($SwiftSDK -ne "") {
$SwiftArgs += @("-sdk", $SwiftSDK)
} else {
$SwiftArgs += @(
"-vfsoverlay", "$RuntimeBinaryCache\stdlib\windows-vfs-overlay.yaml",
"-strict-implicit-module-context",
"-Xcc", "-Xclang", "-Xcc", "-fbuiltin-headers-in-system-modules"
)
$SwiftArgs += @("-resource-dir", "$SwiftResourceDir")
$SwiftArgs += @("-L", "$SwiftResourceDir\$($Platform.ToString().ToLowerInvariant())")
}
Android {
$androidNDKPath = Get-AndroidNDKPath
}
Android {
$androidNDKPath = Get-AndroidNDKPath
if ($SwiftSDK -ne "") {
$SwiftArgs += @("-sdk", $SwiftSDK)
$SwiftArgs += @("-sysroot", "$androidNDKPath\toolchains\llvm\prebuilt\windows-x86_64\sysroot")
} else {
$SwiftArgs += @("-sdk", "$androidNDKPath\toolchains\llvm\prebuilt\windows-x86_64\sysroot")
$SwiftArgs += @(
"-Xclang-linker", "-target",
"-Xclang-linker", $Arch.LLVMTarget,
"-Xclang-linker", "--sysroot",
"-Xclang-linker", "$androidNDKPath\toolchains\llvm\prebuilt\windows-x86_64\sysroot",
"-Xclang-linker", "-resource-dir",
"-Xclang-linker", "$androidNDKPath\toolchains\llvm\prebuilt\windows-x86_64\lib\clang\17"
)
$SwiftArgs += @("-resource-dir", "$SwiftResourceDir")
$SwiftArgs += @("-L", "$SwiftResourceDir\$($Platform.ToString().ToLowerInvariant())")
}
$SwiftArgs += @(
"-Xclang-linker", "-target",
"-Xclang-linker", $Arch.LLVMTarget,
"-Xclang-linker", "--sysroot",
"-Xclang-linker", "$androidNDKPath\toolchains\llvm\prebuilt\windows-x86_64\sysroot",
"-Xclang-linker", "-resource-dir",
"-Xclang-linker", "$androidNDKPath\toolchains\llvm\prebuilt\windows-x86_64\lib\clang\17"
)
}
$SwiftArgs += @("-resource-dir", "$SwiftResourceDir")
$SwiftArgs += @("-L", "$SwiftResourceDir\$($Platform.ToString().ToLowerInvariant())")
}

} else {
$SwiftArgs += @("-sdk", (Get-PinnedToolchainSDK))
}
Expand Down Expand Up @@ -1172,7 +1184,7 @@ function Build-CMakeProject {
}
}

if ("" -ne $InstallTo) {
if ($BuildTargets.Length -eq 0 -and $InstallTo) {
Invoke-Program cmake.exe --build $Bin --target install
}
}
Expand Down Expand Up @@ -1309,7 +1321,6 @@ function Build-CMark($Arch) {
-Bin "$($Arch.BinaryCache)\cmark-gfm-0.29.0.gfm.13" `
-InstallTo "$($Arch.ToolchainInstallRoot)\usr" `
-Arch $Arch `
-BuildTargets default `
-Defines @{
BUILD_SHARED_LIBS = "YES";
BUILD_TESTING = "NO";
Expand Down Expand Up @@ -1477,7 +1488,6 @@ function Build-ZLib([Platform]$Platform, $Arch) {
-Arch $Arch `
-Platform $Platform `
-UseMSVCCompilers C `
-BuildTargets default `
-Defines @{
BUILD_SHARED_LIBS = "NO";
CMAKE_POSITION_INDEPENDENT_CODE = "YES";
Expand All @@ -1497,7 +1507,6 @@ function Build-XML2([Platform]$Platform, $Arch) {
-Arch $Arch `
-Platform $Platform `
-UseMSVCCompilers C,CXX `
-BuildTargets default `
-Defines @{
BUILD_SHARED_LIBS = "NO";
CMAKE_INSTALL_BINDIR = "bin/$Platform/$ArchName";
Expand Down Expand Up @@ -1564,7 +1573,6 @@ function Build-CURL([Platform]$Platform, $Arch) {
-Arch $Arch `
-Platform $Platform `
-UseMSVCCompilers C `
-BuildTargets default `
-Defines ($PlatformDefines + @{
BUILD_SHARED_LIBS = "NO";
BUILD_TESTING = "NO";
Expand Down Expand Up @@ -1687,7 +1695,6 @@ function Build-Runtime([Platform]$Platform, $Arch) {
-Platform $Platform `
-CacheScript $SourceCache\swift\cmake\caches\Runtime-$Platform-$($Arch.LLVMName).cmake `
-UseBuiltCompilers C,CXX,Swift `
-BuildTargets default `
-Defines ($PlatformDefines + @{
CMAKE_Swift_COMPILER_TARGET = $Arch.LLVMTarget.Replace("$AndroidAPILevel", "");
CMAKE_Swift_COMPILER_WORKS = "YES";
Expand Down Expand Up @@ -1728,7 +1735,6 @@ function Build-Dispatch([Platform]$Platform, $Arch, [switch]$Test = $false) {
-Arch $Arch `
-Platform $Platform `
-UseBuiltCompilers C,CXX,Swift `
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it okay not to keep ExperimentalTest when testing? If $Target is really dead, better to remove it from the above statement?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that needs to be preserved to run the tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, we need to keep the -BuildTargets $Targets here?

-BuildTargets $Targets `
-Defines @{
ENABLE_SWIFT = "YES";
}
Expand Down Expand Up @@ -1771,19 +1777,22 @@ function Build-Foundation([Platform]$Platform, $Arch, [switch]$Test = $false) {
$ShortArch = $Arch.LLVMName

Isolate-EnvVars {
$TestingDefines = @{ ENABLE_TESTING = "NO" }
$Targets = @("default")
$InstallPath = "$($Arch.SDKInstallRoot)\usr"
$SDKRoot = if ($Platform -eq "Windows") {
""
} else {
(Get-Variable "${Platform}$($Arch.ShortName)" -ValueOnly).SDKInstallRoot
}

Build-CMakeProject `
-Src $SourceCache\swift-corelibs-foundation `
-Bin $FoundationBinaryCache `
-InstallTo $InstallPath `
-InstallTo "$($Arch.SDKInstallRoot)\usr" `
-Arch $Arch `
-Platform $Platform `
-UseBuiltCompilers ASM,C,CXX,Swift `
-BuildTargets $Targets `
-SwiftSDK:$SDKRoot `
-Defines (@{
ENABLE_TESTING = "NO";
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 All @@ -1805,7 +1814,7 @@ function Build-Foundation([Platform]$Platform, $Arch, [switch]$Test = $false) {
_SwiftFoundationICU_SourceDIR = "$SourceCache\swift-foundation-icu";
_SwiftCollections_SourceDIR = "$SourceCache\swift-collections";
SwiftFoundation_MACRO = "$(Get-BuildProjectBinaryCache FoundationMacros)\bin"
} + $TestingDefines)
})
}
}
}
Expand All @@ -1832,15 +1841,11 @@ function Build-FoundationMacros() {
$SwiftSDK = $BuildArch.SDKInstallRoot
}

$Targets = if ($Build) {
@("default")
} else {
@("default", "install")
}

$InstallDir = $null
$Targets = @("default")
if (-not $Build) {
$InstallDir = "$($Arch.ToolchainInstallRoot)\usr"
$Targets = @()
}

$SwiftSyntaxCMakeModules = if ($Build -and $HostArch -ne $BuildArch) {
Expand All @@ -1857,7 +1862,7 @@ function Build-FoundationMacros() {
-Platform $Platform `
-UseBuiltCompilers Swift `
-SwiftSDK:$SwiftSDK `
-BuildTargets $Targets `
-BuildTargets:$Targets `
-Defines @{
SwiftSyntax_DIR = $SwiftSyntaxCMakeModules;
}
Expand All @@ -1882,7 +1887,7 @@ function Build-XCTest([Platform]$Platform, $Arch, [switch]$Test = $false) {
$env:Path = "$XCTestBinaryCache;$FoundationBinaryCache\bin;$DispatchBinaryCache;$(Get-TargetProjectBinaryCache $Arch Runtime)\bin;$env:Path;$UnixToolsBinDir"
} else {
$TestingDefines = @{ ENABLE_TESTING = "NO" }
$Targets = @("default")
$Targets = @("install")
$InstallPath = "$($Arch.XCTestInstallRoot)\usr"
}

Expand Down Expand Up @@ -1910,7 +1915,6 @@ function Build-Testing([Platform]$Platform, $Arch, [switch]$Test = $false) {
# TODO: Test
return
} else {
$Targets = @("default")
$InstallPath = "$($Arch.SwiftTestingInstallRoot)\usr"
}

Expand All @@ -1921,7 +1925,6 @@ function Build-Testing([Platform]$Platform, $Arch, [switch]$Test = $false) {
-Arch $Arch `
-Platform $Platform `
-UseBuiltCompilers C,CXX,Swift `
-BuildTargets $Targets `
-Defines (@{
BUILD_SHARED_LIBS = "YES";
CMAKE_BUILD_WITH_INSTALL_RPATH = "YES";
Expand Down Expand Up @@ -2020,7 +2023,6 @@ function Build-SQLite($Arch) {
-InstallTo $LibraryRoot\sqlite-3.46.0\usr `
-Arch $Arch `
-UseMSVCCompilers C `
-BuildTargets default `
-Defines @{
BUILD_SHARED_LIBS = "NO";
}
Expand All @@ -2035,7 +2037,6 @@ function Build-System($Arch) {
-Platform Windows `
-UseBuiltCompilers C,Swift `
-SwiftSDK (Get-HostSwiftSDK) `
-BuildTargets default `
-Defines @{
BUILD_SHARED_LIBS = "YES";
}
Expand All @@ -2055,7 +2056,6 @@ function Build-ToolsSupportCore($Arch) {
-Platform Windows `
-UseBuiltCompilers C,Swift `
-SwiftSDK (Get-HostSwiftSDK) `
-BuildTargets default `
-Defines @{
BUILD_SHARED_LIBS = "YES";
SwiftSystem_DIR = (Get-HostProjectCMakeModules System);
Expand All @@ -2081,7 +2081,7 @@ function Build-LLBuild($Arch, [switch]$Test = $false) {
$env:CLANG = ([IO.Path]::Combine((Get-HostProjectBinaryCache Compilers), "bin", "clang.exe"))
$InstallPath = ""
} else {
$Targets = @("default")
$Targets = @()
$TestingDefines = @{}
$InstallPath = "$($Arch.ToolchainInstallRoot)\usr"
}
Expand Down Expand Up @@ -2129,7 +2129,6 @@ function Build-ArgumentParser($Arch) {
-Platform Windows `
-UseBuiltCompilers Swift `
-SwiftSDK (Get-HostSwiftSDK) `
-BuildTargets default `
-Defines @{
BUILD_SHARED_LIBS = "YES";
BUILD_TESTING = "NO";
Expand All @@ -2145,7 +2144,6 @@ function Build-Driver($Arch) {
-Platform Windows `
-UseBuiltCompilers C,CXX,Swift `
-SwiftSDK (Get-HostSwiftSDK) `
-BuildTargets default `
-Defines @{
BUILD_SHARED_LIBS = "YES";
SwiftSystem_DIR = (Get-HostProjectCMakeModules System);
Expand Down Expand Up @@ -2185,7 +2183,6 @@ function Build-Collections($Arch) {
-Platform Windows `
-UseBuiltCompilers C,Swift `
-SwiftSDK (Get-HostSwiftSDK) `
-BuildTargets default `
-Defines @{
BUILD_SHARED_LIBS = "YES";
}
Expand Down Expand Up @@ -2235,7 +2232,6 @@ function Build-PackageManager($Arch) {
-Platform Windows `
-UseBuiltCompilers C,Swift `
-SwiftSDK (Get-HostSwiftSDK) `
-BuildTargets default `
-Defines @{
BUILD_SHARED_LIBS = "YES";
CMAKE_Swift_FLAGS = @("-DCRYPTO_v2");
Expand Down Expand Up @@ -2263,7 +2259,6 @@ function Build-Markdown($Arch) {
-Platform Windows `
-UseBuiltCompilers C,Swift `
-SwiftSDK (Get-HostSwiftSDK) `
-BuildTargets default `
-Defines @{
BUILD_SHARED_LIBS = "NO";
ArgumentParser_DIR = (Get-HostProjectCMakeModules ArgumentParser);
Expand All @@ -2281,7 +2276,6 @@ function Build-Format($Arch) {
-UseMSVCCompilers C `
-UseBuiltCompilers Swift `
-SwiftSDK (Get-HostSwiftSDK) `
-BuildTargets default `
-Defines @{
BUILD_SHARED_LIBS = "YES";
ArgumentParser_DIR = (Get-HostProjectCMakeModules ArgumentParser);
Expand Down Expand Up @@ -2318,7 +2312,6 @@ function Build-SourceKitLSP($Arch) {
-Platform Windows `
-UseBuiltCompilers C,Swift `
-SwiftSDK (Get-HostSwiftSDK) `
-BuildTargets default `
-Defines @{
SwiftSyntax_DIR = (Get-HostProjectCMakeModules Compilers);
SwiftSystem_DIR = (Get-HostProjectCMakeModules System);
Expand Down Expand Up @@ -2361,8 +2354,10 @@ function Build-TestingMacros() {
}

$InstallDir = $null
$Targets = @("default")
if (-not $Build) {
$InstallDir = "$($Arch.ToolchainInstallRoot)\usr"
$Targets = @()
}

$SwiftSyntaxCMakeModules = if ($Build -and $HostArch -ne $BuildArch) {
Expand All @@ -2379,7 +2374,7 @@ function Build-TestingMacros() {
-Platform $Platform `
-UseBuiltCompilers Swift `
-SwiftSDK:$SwiftSDK `
-BuildTargets $Targets `
-BuildTargets:$Targets `
-Defines @{
SwiftSyntax_DIR = $SwiftSyntaxCMakeModules;
}
Expand Down