From 2d6f05b3b3dd0826f05099c1cd3579c9896f9ac4 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 15 May 2025 14:55:08 -0700 Subject: [PATCH 01/10] Remove Variant option and add support for IncludeNoAsserts instead --- utils/build.ps1 | 58 +++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/utils/build.ps1 b/utils/build.ps1 index 0592a4b362e4b..78880ae42b2e5 100644 --- a/utils/build.ps1 +++ b/utils/build.ps1 @@ -100,8 +100,8 @@ in batch file format instead of executing them. .PARAMETER HostArchName The architecture where the toolchain will execute. -.PARAMETER Variant -The toolchain variant to build. Defaults to `Asserts`. +.PARAMETER IncludeNoAsserts +If set, the no-assert toolchain variant is also build and included in the output. .PARAMETER FoundationTestConfiguration Whether to run swift-foundation and swift-corelibs-foundation tests in a debug or release configuration. @@ -148,8 +148,7 @@ param [string] $Stage = "", [ValidateSet("AMD64", "ARM64")] [string] $HostArchName = $(if ($env:PROCESSOR_ARCHITEW6432) { $env:PROCESSOR_ARCHITEW6432 } else { $env:PROCESSOR_ARCHITECTURE }), - [ValidateSet("Asserts", "NoAsserts")] - [string] $Variant = "Asserts", + [switch] $IncludeNoAsserts = $false, [switch] $Clean, [switch] $DebugInfo, [ValidatePattern('^\d+(\.\d+)*$')] @@ -623,8 +622,10 @@ function Get-InstallDir([Hashtable] $Platform) { # For dev productivity, install the host toolchain directly using CMake. # This allows iterating on the toolchain using ninja builds. -$HostPlatform.ToolchainInstallRoot = "$(Get-InstallDir $HostPlatform)\Toolchains\$ProductVersion+$Variant" -$BuildPlatform.ToolchainInstallRoot = "$(Get-InstallDir $BuildPlatform)\Toolchains\$ProductVersion+$Variant" +$HostPlatform.ToolchainInstallRoot = "$(Get-InstallDir $HostPlatform)\Toolchains\$ProductVersion+$PinnedToolchainVariant" +$HostPlatform.NoAssertsToolchainInstallRoot = "$(Get-InstallDir $HostPlatform)\Toolchains\$ProductVersion+NoAsserts" +$BuildPlatform.ToolchainInstallRoot = "$(Get-InstallDir $BuildPlatform)\Toolchains\$ProductVersion+$PinnedToolchainVariant" +$BuildPlatform.NoAssertsToolchainInstallRoot = "$(Get-InstallDir $BuildPlatform)\Toolchains\$ProductVersion+NoAsserts" # Build functions function Invoke-BuildStep { @@ -1694,7 +1695,7 @@ function Build-CMark([Hashtable] $Platform) { Build-CMakeProject ` -Src $SourceCache\cmark ` -Bin (Get-CMarkBinaryCache $Platform) ` - -InstallTo "$(Get-InstallDir $Platform)\Toolchains\$ProductVersion+$Variant\usr" ` + -InstallTo "$(Get-InstallDir $Platform)\Toolchains\$ProductVersion+$PinnedToolchainVariant\usr" ` -Platform $Platform ` -Defines @{ BUILD_SHARED_LIBS = "YES"; @@ -1737,7 +1738,7 @@ function Build-BuildTools([Hashtable] $Platform) { SWIFT_INCLUDE_APINOTES = "NO"; SWIFT_INCLUDE_DOCS = "NO"; SWIFT_INCLUDE_TESTS = "NO"; - "cmark-gfm_DIR" = "$(Get-InstallDir $Platform)\Toolchains\$ProductVersion+$Variant\usr\lib\cmake"; + "cmark-gfm_DIR" = "$(Get-InstallDir $Platform)\Toolchains\$ProductVersion+$PinnedToolchainVariant\usr\lib\cmake"; } } @@ -1773,7 +1774,7 @@ function Load-LitTestOverrides($Filename) { } } -function Get-CompilersDefines([Hashtable] $Platform, [switch] $Test) { +function Get-CompilersDefines([Hashtable] $Platformm, [string] $Variant, [switch] $Test) { $BuildTools = [IO.Path]::Combine((Get-ProjectBinaryCache $BuildPlatform BuildTools), "bin") $PythonRoot = [IO.Path]::Combine((Get-PythonPath $Platform), "tools") $PythonLibName = "python{0}{1}" -f ([System.Version]$PythonVersion).Major, ([System.Version]$PythonVersion).Minor @@ -1848,7 +1849,7 @@ function Get-CompilersDefines([Hashtable] $Platform, [switch] $Test) { } } -function Build-Compilers([Hashtable] $Platform) { +function Build-Compilers([Hashtable] $Platform, [string] $Variant) { New-Item -ItemType SymbolicLink -Path "$BinaryCache\$($HostPlatform.Triple)\compilers" -Target "$BinaryCache\5" -ErrorAction Ignore Build-CMakeProject ` -Src $SourceCache\llvm-project\llvm ` @@ -1859,7 +1860,7 @@ function Build-Compilers([Hashtable] $Platform) { -UsePinnedCompilers Swift ` -BuildTargets @("install-distribution") ` -CacheScript $SourceCache\swift\cmake\caches\Windows-$($Platform.Architecture.LLVMName).cmake ` - -Defines (Get-CompilersDefines $Platform) + -Defines (Get-CompilersDefines $Platform $Variant) $Settings = @{ FallbackLibrarySearchPaths = @("usr/bin") @@ -1869,10 +1870,10 @@ function Build-Compilers([Hashtable] $Platform) { Write-PList -Settings $Settings -Path "$($Platform.ToolchainInstallRoot)\ToolchainInfo.plist" } -function Test-Compilers([Hashtable] $Platform, [switch] $TestClang, [switch] $TestLLD, [switch] $TestLLDB, [switch] $TestLLVM, [switch] $TestSwift) { +function Test-Compilers([Hashtable] $Platform, [string] $Variant, [switch] $TestClang, [switch] $TestLLD, [switch] $TestLLDB, [switch] $TestLLVM, [switch] $TestSwift) { Invoke-IsolatingEnvVars { $env:Path = "$(Get-CMarkBinaryCache $Platform)\src;$(Get-ProjectBinaryCache $BuildPlatform Compilers)\tools\swift\libdispatch-windows-$($Platform.Architecture.LLVMName)-prefix\bin;$(Get-ProjectBinaryCache $BuildPlatform Compilers)\bin;$env:Path;$VSInstallRoot\DIA SDK\bin\$($HostPlatform.Architecture.VSName);$UnixToolsBinDir" - $TestingDefines = Get-CompilersDefines $Platform -Test + $TestingDefines = Get-CompilersDefines $Platform $Variant -Test if ($TestLLVM) { $Targets += @("check-llvm") } if ($TestClang) { $Targets += @("check-clang") } if ($TestLLD) { $Targets += @("check-lld") } @@ -1984,19 +1985,26 @@ function Build-mimalloc() { "ld.lld.exe", "ld64.lld.exe" ) - foreach ($Tool in $Tools) { - $Binary = [IO.Path]::Combine($Platform.ToolchainInstallRoot, "usr", "bin", $Tool) + $Binaries = $Tools | ForEach-Object {[IO.Path]::Combine($Platform.ToolchainInstallRoot, "usr", "bin", $_)} + if ($IncludeNoAsserts) { + $NoAssertBinaries = $Tools ` + | ForEach-Object {[IO.Path]::Combine($Platform.NoAssertsToolchainInstallRoot, "usr", "bin", $_)} ` + | Where-Object { Test-Path $_ -PathType Leaf } + $Binaries = $Binaries + $NoAssertBinaries + } + foreach ($Binary in $Binaries) { + $Name = [IO.Path]::GetFileName($Binary) # Binary-patch in place Invoke-Program "$SourceCache\mimalloc\bin\minject$BuildSuffix" "-f" "-i" "$Binary" # Log the import table - $LogFile = "$BinaryCache\$($Platform.Triple)\mimalloc\minject-log-$Tool.txt" - $ErrorFile = "$BinaryCache\$($Platform.Triple)\mimalloc\minject-log-$Tool-error.txt" + $LogFile = "$BinaryCache\$($Platform.Triple)\mimalloc\minject-log-$Name.txt" + $ErrorFile = "$BinaryCache\$($Platform.Triple)\mimalloc\minject-log-$Name-error.txt" Invoke-Program "$SourceCache\mimalloc\bin\minject$BuildSuffix" "-l" "$Binary" -OutFile $LogFile -ErrorFile $ErrorFile # Verify patching $Found = Select-String -Path $LogFile -Pattern "mimalloc" if (-not $Found) { Get-Content $ErrorFile - throw "Failed to patch mimalloc for $Tool" + throw "Failed to patch mimalloc for $Name" } } } @@ -3232,8 +3240,8 @@ function Test-PackageManager() { -Src $SrcDir ` -Bin "$BinaryCache\$($HostPlatform.Triple)\PackageManagerTests" ` -Platform $HostPlatform ` - -Xcc "-I$(Get-InstallDir $Platform)\Toolchains\$ProductVersion+$Variant\usr\include" ` - -Xlinker "-L$(Get-InstallDir $Platform)\Toolchains\$ProductVersion+$Variant\usr\lib" + -Xcc "-I$(Get-InstallDir $Platform)\Toolchains\$ProductVersion+$PinnedToolchainVariant\usr\include" ` + -Xlinker "-L$(Get-InstallDir $Platform)\Toolchains\$ProductVersion+$PinnedToolchainVariant\usr\lib" } function Build-Installer([Hashtable] $Platform) { @@ -3245,6 +3253,7 @@ function Build-Installer([Hashtable] $Platform) { BundleFlavor = "offline"; ImageRoot = "$(Get-InstallDir $Platform)\"; INCLUDE_SWIFT_DOCC = $INCLUDE_SWIFT_DOCC; + INCLUDE_NOASSERTS = $IncludeNoAsserts SWIFT_DOCC_BUILD = "$(Get-ProjectBinaryCache $HostPlatform DocC)\release"; SWIFT_DOCC_RENDER_ARTIFACT_ROOT = "${SourceCache}\swift-docc-render-artifact"; } @@ -3314,7 +3323,7 @@ if (-not $SkipBuild) { Invoke-BuildStep Build-BuildTools $BuildPlatform if ($IsCrossCompiling) { Invoke-BuildStep Build-XML2 $BuildPlatform - Invoke-BuildStep Build-Compilers $BuildPlatform + Invoke-BuildStep Build-Compilers $BuildPlatform -Variant $PinnedToolchainVariant } if ($IncludeDS2) { Invoke-BuildStep Build-RegsGen2 $BuildPlatform @@ -3322,7 +3331,10 @@ if (-not $SkipBuild) { Invoke-BuildStep Build-CMark $HostPlatform Invoke-BuildStep Build-XML2 $HostPlatform - Invoke-BuildStep Build-Compilers $HostPlatform + Invoke-BuildStep Build-Compilers $HostPlatform -Variant "Asserts" + if ($IncludeNoAsserts) { + Invoke-BuildStep Build-Compilers $HostPlatform -Variant "NoAsserts" + } Invoke-BuildStep Build-SDK $BuildPlatform -IncludeMacros @@ -3419,7 +3431,7 @@ if (-not $IsCrossCompiling) { "-TestLLVM" = $Test -contains "llvm"; "-TestSwift" = $Test -contains "swift"; } - Invoke-BuildStep Test-Compilers $HostPlatform $Tests + Invoke-BuildStep Test-Compilers $HostPlatform $PinnedToolchainVariant $Tests } # FIXME(jeffdav): Invoke-BuildStep needs a platform dictionary, even though the Test- From 1624bf63106c3c2004a8ad511c4f0d14d2bbec13 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 15 May 2025 14:57:50 -0700 Subject: [PATCH 02/10] Add support for named arguments in Invoke-BuildStep --- utils/build.ps1 | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/utils/build.ps1 b/utils/build.ps1 index 78880ae42b2e5..bfcdebd1151b0 100644 --- a/utils/build.ps1 +++ b/utils/build.ps1 @@ -637,7 +637,7 @@ function Invoke-BuildStep { [Parameter(Position=1, Mandatory)] [Hashtable] $Platform, [Parameter(ValueFromRemainingArguments)] - $RemainingArgs + [Object[]] $RemainingArgs ) if ($Summary) { @@ -645,13 +645,31 @@ function Invoke-BuildStep { } $SplatArgs = @{} - foreach ($Arg in $RemainingArgs) { - if ($Arg -is [Hashtable]) { - $SplatArgs += $Arg - } elseif ($Arg -is [string]) { - $SplatArgs[$Arg.TrimStart('-')] = $true - } else { - throw "$Arg is unknown type: $($Arg.GetType())" + if ($RemainingArgs) { + $i = 0 + while ($i -lt $RemainingArgs.Count) { + $Arg = $RemainingArgs[$i] + if ($Arg -is [Hashtable]) { + $SplatArgs += $Arg + $i++ + } elseif ($Arg -is [string] -and $Arg.StartsWith('-')) { + $paramName = $Arg.TrimStart('-') + + # Check if the next argument is a value for this parameter + if ($i -lt $RemainingArgs.Count - 1 -and ($RemainingArgs[$i + 1] -isnot [string] -or !$RemainingArgs[$i + 1].StartsWith('-'))) { + # This is a named parameter with a value + $SplatArgs[$paramName] = $RemainingArgs[$i + 1] + $i += 2 + } else { + # This is a switch parameter (flag) + $SplatArgs[$paramName] = $true + $i++ + } + } else { + # Handle positional parameter + throw "Positional parameter '$Arg' found. The Invoke-BuildStep function only supports named parameters after the required Name and Platform parameters." + $i++ + } } } @@ -662,6 +680,7 @@ function Invoke-BuildStep { } } + enum Project { BuildTools RegsGen2 From 709f591064ef57cf10a3bd63cb262ff0c32337b0 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 16 May 2025 09:25:34 -0700 Subject: [PATCH 03/10] Check for property type before using string functions --- utils/build.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/build.ps1 b/utils/build.ps1 index bfcdebd1151b0..ffaf7a1792ef2 100644 --- a/utils/build.ps1 +++ b/utils/build.ps1 @@ -1693,7 +1693,7 @@ function Build-WiXProject() { $MSBuildArgs = @( "-noLogo", "-maxCpuCount", "-restore", "$SourceCache\swift-installer-scripts\platforms\Windows\$FileName" ) foreach ($Property in $Properties.GetEnumerator()) { - if ($Property.Value.Contains(" ")) { + if ($Property.Value -is [string] -and $Property.Value.Contains(" ")) { $MSBuildArgs += "-p:$($Property.Key)=$($Property.Value.Replace('\', '\\'))" } else { $MSBuildArgs += "-p:$($Property.Key)=$($Property.Value)" @@ -3272,7 +3272,7 @@ function Build-Installer([Hashtable] $Platform) { BundleFlavor = "offline"; ImageRoot = "$(Get-InstallDir $Platform)\"; INCLUDE_SWIFT_DOCC = $INCLUDE_SWIFT_DOCC; - INCLUDE_NOASSERTS = $IncludeNoAsserts + INCLUDE_NOASSERTS = $IncludeNoAsserts; SWIFT_DOCC_BUILD = "$(Get-ProjectBinaryCache $HostPlatform DocC)\release"; SWIFT_DOCC_RENDER_ARTIFACT_ROOT = "${SourceCache}\swift-docc-render-artifact"; } From 74151fcbd0598352564f31235a1e0e38ab50f04c Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 20 May 2025 16:00:03 -0700 Subject: [PATCH 04/10] Address code review feedback --- utils/build.ps1 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/utils/build.ps1 b/utils/build.ps1 index ffaf7a1792ef2..d2aec25e3f50b 100644 --- a/utils/build.ps1 +++ b/utils/build.ps1 @@ -653,16 +653,17 @@ function Invoke-BuildStep { $SplatArgs += $Arg $i++ } elseif ($Arg -is [string] -and $Arg.StartsWith('-')) { - $paramName = $Arg.TrimStart('-') + $ParamName = $Arg.TrimStart('-') # Check if the next argument is a value for this parameter - if ($i -lt $RemainingArgs.Count - 1 -and ($RemainingArgs[$i + 1] -isnot [string] -or !$RemainingArgs[$i + 1].StartsWith('-'))) { + $HasNextArg = ($i -lt $RemainingArgs.Count - 1) + if ($HasNextArg -and $RemainingArgs[$i + 1] -is [string] -and !$RemainingArgs[$i + 1].StartsWith('-')) { # This is a named parameter with a value - $SplatArgs[$paramName] = $RemainingArgs[$i + 1] + $SplatArgs[$ParamName] = $RemainingArgs[$i + 1] $i += 2 } else { # This is a switch parameter (flag) - $SplatArgs[$paramName] = $true + $SplatArgs[$ParamName] = $true $i++ } } else { @@ -3272,7 +3273,6 @@ function Build-Installer([Hashtable] $Platform) { BundleFlavor = "offline"; ImageRoot = "$(Get-InstallDir $Platform)\"; INCLUDE_SWIFT_DOCC = $INCLUDE_SWIFT_DOCC; - INCLUDE_NOASSERTS = $IncludeNoAsserts; SWIFT_DOCC_BUILD = "$(Get-ProjectBinaryCache $HostPlatform DocC)\release"; SWIFT_DOCC_RENDER_ARTIFACT_ROOT = "${SourceCache}\swift-docc-render-artifact"; } @@ -3289,6 +3289,7 @@ function Build-Installer([Hashtable] $Platform) { $Properties["Platforms"] = "`"windows$(if ($Android) { ";android" })`""; $Properties["AndroidArchitectures"] = "`"$(($AndroidSDKPlatforms | ForEach-Object { $_.Architecture.LLVMName }) -Join ";")`"" $Properties["WindowsArchitectures"] = "`"$(($WindowsSDKPlatforms | ForEach-Object { $_.Architecture.LLVMName }) -Join ";")`"" + $Properties["ToolchainVariants"] = "`"asserts$(if ($IncludeNoAsserts) { ";noasserts" })`""; foreach ($SDKPlatform in $WindowsSDKPlatforms) { $Properties["WindowsRuntime$($SDKPlatform.Architecture.ShortName.ToUpperInvariant())"] = [IO.Path]::Combine((Get-InstallDir $SDKPlatform), "Runtimes", "$ProductVersion"); } From 96b4038d9efe3c4b5848261ab113d66718c4ffb1 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 29 May 2025 15:00:04 -0700 Subject: [PATCH 05/10] Address review feedback --- utils/build.ps1 | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/utils/build.ps1 b/utils/build.ps1 index d2aec25e3f50b..ff52c9ad7d6a5 100644 --- a/utils/build.ps1 +++ b/utils/build.ps1 @@ -646,30 +646,26 @@ function Invoke-BuildStep { $SplatArgs = @{} if ($RemainingArgs) { - $i = 0 - while ($i -lt $RemainingArgs.Count) { - $Arg = $RemainingArgs[$i] + $Enumerator = $RemainingArgs.GetEnumerator() + while ($Enumerator.MoveNext()) { + $Arg = $Enumerator.Current if ($Arg -is [Hashtable]) { $SplatArgs += $Arg - $i++ } elseif ($Arg -is [string] -and $Arg.StartsWith('-')) { $ParamName = $Arg.TrimStart('-') - - # Check if the next argument is a value for this parameter - $HasNextArg = ($i -lt $RemainingArgs.Count - 1) - if ($HasNextArg -and $RemainingArgs[$i + 1] -is [string] -and !$RemainingArgs[$i + 1].StartsWith('-')) { - # This is a named parameter with a value - $SplatArgs[$ParamName] = $RemainingArgs[$i + 1] - $i += 2 - } else { - # This is a switch parameter (flag) - $SplatArgs[$ParamName] = $true - $i++ + $HasNextArg = $RemainingArgs.IndexOf($Arg) -lt ($RemainingArgs.Count - 1) + if ($HasNextArg) { + $NextArg = $RemainingArgs[$RemainingArgs.IndexOf($Arg) + 1] + if ($NextArg -is [string] -and !$NextArg.StartsWith('-')) { + $SplatArgs[$ParamName] = $NextArg + $Enumerator.MoveNext() # Skip NextArg + continue + } } + # Must be a flag. + $SplatArgs[$ParamName] = $true } else { - # Handle positional parameter throw "Positional parameter '$Arg' found. The Invoke-BuildStep function only supports named parameters after the required Name and Platform parameters." - $i++ } } } @@ -681,7 +677,6 @@ function Invoke-BuildStep { } } - enum Project { BuildTools RegsGen2 From b8be792ee3f040f9d75abbce5fd738a486d3a3f2 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 30 May 2025 09:43:29 -0700 Subject: [PATCH 06/10] Remove PinnedToolchainVarinat variable --- utils/build.ps1 | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/utils/build.ps1 b/utils/build.ps1 index ff52c9ad7d6a5..86f0e9a29500e 100644 --- a/utils/build.ps1 +++ b/utils/build.ps1 @@ -54,10 +54,6 @@ The toolchain snapshot to build the early components with. .PARAMETER PinnedSHA256 The SHA256 for the pinned toolchain. -.PARAMETER PinnedToolchainVariant -The toolchain variant to use while building the toolchain. Defaults to -`Asserts`. - .PARAMETER AndroidNDKVersion The version number of the Android NDK to be used. @@ -132,8 +128,6 @@ param [ValidatePattern("^([A-Fa-f0-9]{64}|)$")] [string] $PinnedSHA256 = "", [string] $PinnedVersion = "", - [ValidateSet("Asserts", "NoAsserts")] - [string] $PinnedToolchainVariant = "Asserts", [ValidatePattern('^\d+(\.\d+)*$')] [string] $PythonVersion = "3.9.10", [ValidatePattern("^r(?:[1-9]|[1-9][0-9])(?:[a-z])?$")] @@ -622,9 +616,9 @@ function Get-InstallDir([Hashtable] $Platform) { # For dev productivity, install the host toolchain directly using CMake. # This allows iterating on the toolchain using ninja builds. -$HostPlatform.ToolchainInstallRoot = "$(Get-InstallDir $HostPlatform)\Toolchains\$ProductVersion+$PinnedToolchainVariant" +$HostPlatform.ToolchainInstallRoot = "$(Get-InstallDir $HostPlatform)\Toolchains\$ProductVersion+Asserts" $HostPlatform.NoAssertsToolchainInstallRoot = "$(Get-InstallDir $HostPlatform)\Toolchains\$ProductVersion+NoAsserts" -$BuildPlatform.ToolchainInstallRoot = "$(Get-InstallDir $BuildPlatform)\Toolchains\$ProductVersion+$PinnedToolchainVariant" +$BuildPlatform.ToolchainInstallRoot = "$(Get-InstallDir $BuildPlatform)\Toolchains\$ProductVersion+Asserts" $BuildPlatform.NoAssertsToolchainInstallRoot = "$(Get-InstallDir $BuildPlatform)\Toolchains\$ProductVersion+NoAsserts" # Build functions @@ -1195,7 +1189,7 @@ function Get-PinnedToolchainToolsDir() { } } - $VariantToolchainPath = [IO.Path]::Combine($ToolchainsRoot, "$(Get-PinnedToolchainVersion)+$PinnedToolchainVariant", "usr", "bin") + $VariantToolchainPath = [IO.Path]::Combine($ToolchainsRoot, "$(Get-PinnedToolchainVersion)+Asserts", "usr", "bin") if (Test-Path $VariantToolchainPath) { return $VariantToolchainPath @@ -1203,7 +1197,7 @@ function Get-PinnedToolchainToolsDir() { return [IO.Path]::Combine("$BinaryCache\", "toolchains", $PinnedToolchain, "Library", "Developer", "Toolchains", - "unknown-$PinnedToolchainVariant-development.xctoolchain", "usr", "bin") + "unknown-Asserts-development.xctoolchain", "usr", "bin") } function Get-PinnedToolchainSDK() { @@ -1710,7 +1704,7 @@ function Build-CMark([Hashtable] $Platform) { Build-CMakeProject ` -Src $SourceCache\cmark ` -Bin (Get-CMarkBinaryCache $Platform) ` - -InstallTo "$(Get-InstallDir $Platform)\Toolchains\$ProductVersion+$PinnedToolchainVariant\usr" ` + -InstallTo "$(Get-InstallDir $Platform)\Toolchains\$ProductVersion+Asserts\usr" ` -Platform $Platform ` -Defines @{ BUILD_SHARED_LIBS = "YES"; @@ -1753,7 +1747,7 @@ function Build-BuildTools([Hashtable] $Platform) { SWIFT_INCLUDE_APINOTES = "NO"; SWIFT_INCLUDE_DOCS = "NO"; SWIFT_INCLUDE_TESTS = "NO"; - "cmark-gfm_DIR" = "$(Get-InstallDir $Platform)\Toolchains\$ProductVersion+$PinnedToolchainVariant\usr\lib\cmake"; + "cmark-gfm_DIR" = "$(Get-InstallDir $Platform)\Toolchains\$ProductVersion+Asserts\usr\lib\cmake"; } } @@ -3255,8 +3249,8 @@ function Test-PackageManager() { -Src $SrcDir ` -Bin "$BinaryCache\$($HostPlatform.Triple)\PackageManagerTests" ` -Platform $HostPlatform ` - -Xcc "-I$(Get-InstallDir $Platform)\Toolchains\$ProductVersion+$PinnedToolchainVariant\usr\include" ` - -Xlinker "-L$(Get-InstallDir $Platform)\Toolchains\$ProductVersion+$PinnedToolchainVariant\usr\lib" + -Xcc "-I$(Get-InstallDir $Platform)\Toolchains\$ProductVersion+Asserts\usr\include" ` + -Xlinker "-L$(Get-InstallDir $Platform)\Toolchains\$ProductVersion+Asserts\usr\lib" } function Build-Installer([Hashtable] $Platform) { @@ -3338,7 +3332,7 @@ if (-not $SkipBuild) { Invoke-BuildStep Build-BuildTools $BuildPlatform if ($IsCrossCompiling) { Invoke-BuildStep Build-XML2 $BuildPlatform - Invoke-BuildStep Build-Compilers $BuildPlatform -Variant $PinnedToolchainVariant + Invoke-BuildStep Build-Compilers $BuildPlatform -Variant "Asserts" } if ($IncludeDS2) { Invoke-BuildStep Build-RegsGen2 $BuildPlatform @@ -3446,7 +3440,7 @@ if (-not $IsCrossCompiling) { "-TestLLVM" = $Test -contains "llvm"; "-TestSwift" = $Test -contains "swift"; } - Invoke-BuildStep Test-Compilers $HostPlatform $PinnedToolchainVariant $Tests + Invoke-BuildStep Test-Compilers $HostPlatform "Asserts" $Tests } # FIXME(jeffdav): Invoke-BuildStep needs a platform dictionary, even though the Test- From 3aff198f083e9beaa76917245854e6d4b5a60d61 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 30 May 2025 15:19:19 -0700 Subject: [PATCH 07/10] Remove trailing whitespace --- utils/build.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/build.ps1 b/utils/build.ps1 index 86f0e9a29500e..ab4520a104b62 100644 --- a/utils/build.ps1 +++ b/utils/build.ps1 @@ -3440,7 +3440,7 @@ if (-not $IsCrossCompiling) { "-TestLLVM" = $Test -contains "llvm"; "-TestSwift" = $Test -contains "swift"; } - Invoke-BuildStep Test-Compilers $HostPlatform "Asserts" $Tests + Invoke-BuildStep Test-Compilers $HostPlatform "Asserts" $Tests } # FIXME(jeffdav): Invoke-BuildStep needs a platform dictionary, even though the Test- From 14b2682fdd060c16f35f2f6f3fd0cf78abb47cb7 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Fri, 30 May 2025 16:25:38 -0700 Subject: [PATCH 08/10] Copy Asserts output to the NoAsserts toolchain layout --- utils/build.ps1 | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/utils/build.ps1 b/utils/build.ps1 index ab4520a104b62..f76589dfed957 100644 --- a/utils/build.ps1 +++ b/utils/build.ps1 @@ -1996,9 +1996,7 @@ function Build-mimalloc() { ) $Binaries = $Tools | ForEach-Object {[IO.Path]::Combine($Platform.ToolchainInstallRoot, "usr", "bin", $_)} if ($IncludeNoAsserts) { - $NoAssertBinaries = $Tools ` - | ForEach-Object {[IO.Path]::Combine($Platform.NoAssertsToolchainInstallRoot, "usr", "bin", $_)} ` - | Where-Object { Test-Path $_ -PathType Leaf } + $NoAssertBinaries = $Tools | ForEach-Object {[IO.Path]::Combine($Platform.NoAssertsToolchainInstallRoot, "usr", "bin", $_)} $Binaries = $Binaries + $NoAssertBinaries } foreach ($Binary in $Binaries) { @@ -3302,6 +3300,37 @@ function Copy-BuildArtifactsToStage([Hashtable] $Platform) { Invoke-Program "$($WiX.Path)\wix.exe" -- burn detach "$BinaryCache\$($Platform.Triple)\installer\Release\$($Platform.Architecture.VSName)\installer.exe" -engine "$Stage\installer-engine.exe" -intermediateFolder "$BinaryCache\$($Platform.Triple)\installer\$($Platform.Architecture.VSName)\" } +function Build-NoAssertsToolchain() { + if ($ToBatch) { + Write-Output "" + Write-Output "Building NoAsserts Toolchain ..." + } else { + Write-Host -ForegroundColor Cyan "[$([DateTime]::Now.ToString("yyyy-MM-dd HH:mm:ss"))] Building NoAsserts Toolchain ..." + } + $Stopwatch = [Diagnostics.Stopwatch]::StartNew() + + Invoke-BuildStep Build-Compilers $HostPlatform -Variant "NoAsserts" + + # Only compilers have NoAsserts enabled. Copy the rest of the Toolcahin binaries from the Asserts output + # Use robocopy for efficient copying + # /E : Copies subdirectories, including empty ones. + # /XC: Excludes existing files with the same timestamp but different file sizes. + # /XN: Excludes existing files that are newer than the copy in the source directory. + # /XO: Excludes existing files that are older than the copy in the source directory. + # /NFL: Do not list coppied files in output + # /NDL: Do not list directories in output + # /NJH: Do not write a job header + # /NC: Do not write file classes + # /NS: Do not write file sizes + # /NP: Do not show progress indicator + &robocopy $HostPlatform.ToolchainInstallRoot $HostPlatform.NoAssertsToolchainInstallRoot /E /XC /XN /XO /NS /NC /NFL /NDL /NJH + + if (-not $ToBatch) { + Write-Host -ForegroundColor Cyan "[$([DateTime]::Now.ToString("yyyy-MM-dd HH:mm:ss"))] Building Instalting NoAsserts Toolchain in $($Stopwatch.Elapsed)" + Write-Host "" + } +} + #------------------------------------------------------------------- try { @@ -3341,9 +3370,6 @@ if (-not $SkipBuild) { Invoke-BuildStep Build-CMark $HostPlatform Invoke-BuildStep Build-XML2 $HostPlatform Invoke-BuildStep Build-Compilers $HostPlatform -Variant "Asserts" - if ($IncludeNoAsserts) { - Invoke-BuildStep Build-Compilers $HostPlatform -Variant "NoAsserts" - } Invoke-BuildStep Build-SDK $BuildPlatform -IncludeMacros @@ -3414,6 +3440,10 @@ if (-not $SkipBuild) { Install-HostToolchain +if ($IncludeNoAsserts) { + Build-NoAssertsToolchain +} + if (-not $SkipBuild) { Invoke-BuildStep Build-mimalloc $HostPlatform } From a16f47c2c16762030e6f61d3df7024f77edccc26 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Mon, 2 Jun 2025 09:02:26 -0700 Subject: [PATCH 09/10] Add parameter name --- utils/build.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/build.ps1 b/utils/build.ps1 index f76589dfed957..e81765cc6b4b2 100644 --- a/utils/build.ps1 +++ b/utils/build.ps1 @@ -3470,7 +3470,7 @@ if (-not $IsCrossCompiling) { "-TestLLVM" = $Test -contains "llvm"; "-TestSwift" = $Test -contains "swift"; } - Invoke-BuildStep Test-Compilers $HostPlatform "Asserts" $Tests + Invoke-BuildStep Test-Compilers $HostPlatform -Variant "Asserts" $Tests } # FIXME(jeffdav): Invoke-BuildStep needs a platform dictionary, even though the Test- From 2f1009731861b344dc3d9adc4c8e565e83805214 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy <8000722+mhegazy@users.noreply.github.com> Date: Thu, 5 Jun 2025 10:27:00 -0700 Subject: [PATCH 10/10] Update utils/build.ps1 Co-authored-by: Saleem Abdulrasool --- utils/build.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/build.ps1 b/utils/build.ps1 index e81765cc6b4b2..f6cefa21eeb08 100644 --- a/utils/build.ps1 +++ b/utils/build.ps1 @@ -1783,7 +1783,7 @@ function Load-LitTestOverrides($Filename) { } } -function Get-CompilersDefines([Hashtable] $Platformm, [string] $Variant, [switch] $Test) { +function Get-CompilersDefines([Hashtable] $Platform, [string] $Variant, [switch] $Test) { $BuildTools = [IO.Path]::Combine((Get-ProjectBinaryCache $BuildPlatform BuildTools), "bin") $PythonRoot = [IO.Path]::Combine((Get-PythonPath $Platform), "tools") $PythonLibName = "python{0}{1}" -f ([System.Version]$PythonVersion).Major, ([System.Version]$PythonVersion).Minor