Skip to content

Commit 9b23eaa

Browse files
committed
utils: remove option to control the allocator
The evolution proposal for enabling the memory allocator for the toolchain on Windows has been accepted. Always use mimalloc for the Windows toolchain and reduce the complexity. Clean up and simplify some of the logic for the MSBuild based build of mimalloc. Avoid building in the source tree at a cost of complexity. Reduce the amount of building by selectively building projects instead of the solution.
1 parent c831aa5 commit 9b23eaa

File tree

1 file changed

+31
-28
lines changed

1 file changed

+31
-28
lines changed

utils/build.ps1

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,6 @@ in batch file format instead of executing them.
102102
.PARAMETER HostArchName
103103
The architecture where the toolchain will execute.
104104
105-
.PARAMETER Allocator
106-
The memory allocator used in the toolchain binaries, if it's
107-
`mimalloc`, it uses mimalloc. Otherwise, it uses the default
108-
allocator.
109-
110105
.EXAMPLE
111106
PS> .\Build.ps1
112107
@@ -144,7 +139,6 @@ param(
144139
[switch] $DebugInfo,
145140
[switch] $EnableCaching,
146141
[string] $Cache = "",
147-
[string] $Allocator = "",
148142
[switch] $Summary,
149143
[switch] $ToBatch
150144
)
@@ -1685,44 +1679,56 @@ function Build-Compilers() {
16851679
}
16861680

16871681
# Reference: https://github.com/microsoft/mimalloc/tree/dev/bin#minject
1688-
function Build-Mimalloc() {
1682+
function Build-mimalloc() {
16891683
[CmdletBinding(PositionalBinding = $false)]
16901684
param
16911685
(
16921686
[Parameter(Position = 0, Mandatory = $true)]
16931687
[hashtable]$Arch
16941688
)
16951689

1696-
$MSBuildArgs = @("$SourceCache\mimalloc\ide\vs2022\mimalloc.sln")
1690+
# TODO: migrate to the CMake build
1691+
$MSBuildArgs = @()
16971692
$MSBuildArgs += "-noLogo"
16981693
$MSBuildArgs += "-maxCpuCount"
1699-
$MSBuildArgs += "-p:Configuration=Release"
1700-
$MSBuildArgs += "-p:Platform=$($Arch.ShortName)"
1694+
1695+
$Properties = @{}
1696+
TryAdd-KeyValue $Properties Configuration Release
1697+
TryAdd-KeyValue $Properties OutDir "$($Arch.BinaryCache)\mimalloc\bin\"
1698+
TryAdd-KeyValue $Properties Platform "$($Arch.ShortName)"
17011699

17021700
Isolate-EnvVars {
17031701
Invoke-VsDevShell $Arch
17041702
# Avoid hard-coding the VC tools version number
17051703
$VCRedistDir = (Get-ChildItem "${env:VCToolsRedistDir}\$($HostArch.ShortName)" -Filter "Microsoft.VC*.CRT").FullName
17061704
if ($VCRedistDir) {
1707-
$MSBuildArgs += "-p:VCRedistDir=$VCRedistDir\"
1705+
TryAdd-KeyValue $Properties VCRedistDir "$VCRedistDir\"
17081706
}
17091707
}
17101708

1711-
Invoke-Program $msbuild @MSBuildArgs
1709+
foreach ($Property in $Properties.GetEnumerator()) {
1710+
if ($Property.Value.Contains(" ")) {
1711+
$MSBuildArgs += "-p:$($Property.Key)=$($Property.Value.Replace('\', '\\'))"
1712+
} else {
1713+
$MSBuildArgs += "-p:$($Property.Key)=$($Property.Value)"
1714+
}
1715+
}
1716+
1717+
Invoke-Program $msbuild "$SourceCache\mimalloc\ide\vs2022\mimalloc-lib.vcxproj" @MSBuildArgs "-p:IntDir=$($Arch.BinaryCache)\mimalloc\mimalloc\"
1718+
Invoke-Program $msbuild "$SourceCache\mimalloc\ide\vs2022\mimalloc-override-dll.vcxproj" @MSBuildArgs "-p:IntDir=$($Arch.BinaryCache)\mimalloc\mimalloc-override-dll\"
17121719

17131720
$HostSuffix = if ($Arch -eq $ArchX64) { "" } else { "-arm64" }
17141721
$BuildSuffix = if ($BuildArch -eq $ArchX64) { "" } else { "-arm64" }
1715-
$Products = @( "mimalloc.dll" )
1716-
foreach ($Product in $Products) {
1717-
Copy-Item -Path "$SourceCache\mimalloc\out\msvc-$($Arch.ShortName)\Release\$Product" -Destination "$($Arch.ToolchainInstallRoot)\usr\bin"
1718-
}
1719-
Copy-Item -Path "$SourceCache\mimalloc\out\msvc-$($Arch.ShortName)\Release\mimalloc-redirect$HostSuffix.dll" -Destination "$($Arch.ToolchainInstallRoot)\usr\bin"
1722+
1723+
Copy-Item -Path "$($Arch.BinaryCache)\mimalloc\bin\mimalloc.dll" -Destination "$($Arch.ToolchainInstallRoot)\usr\bin\"
1724+
Copy-Item -Path "$($Arch.BinaryCache)\mimalloc\bin\mimalloc-redirect$HostSuffix.dll" -Destination "$($Arch.ToolchainInstallRoot)\usr\bin"
17201725
# When cross-compiling, bundle the second mimalloc redirect dll as a workaround for
17211726
# https://github.com/microsoft/mimalloc/issues/997
17221727
if ($IsCrossCompiling) {
1723-
Copy-Item -Path "$SourceCache\mimalloc\out\msvc-$($Arch.ShortName)\Release\mimalloc-redirect$HostSuffix.dll" -Destination "$($Arch.ToolchainInstallRoot)\usr\bin\mimalloc-redirect$BuildSuffix.dll"
1728+
Copy-Item -Path "$($Arch.BinaryCache)\mimalloc\bin\mimalloc-redirect$HostSuffix.dll" -Destination "$($Arch.ToolchainInstallRoot)\usr\bin\mimalloc-redirect$BuildSuffix.dll"
17241729
}
17251730

1731+
# TODO: should we split this out into its own function?
17261732
$Tools = @(
17271733
"swift.exe",
17281734
"swiftc.exe",
@@ -1739,9 +1745,9 @@ function Build-Mimalloc() {
17391745
foreach ($Tool in $Tools) {
17401746
$Binary = [IO.Path]::Combine("$($Arch.ToolchainInstallRoot)\usr\bin", $Tool)
17411747
# Binary-patch in place
1742-
Invoke-Program "$SourceCache\mimalloc\bin\minject$BuildSuffix" "-f" "-i" "-v" "$Binary"
1748+
Start-Process -Wait -WindowStyle Hidden -FilePath "$SourceCache\mimalloc\bin\minject$BuildSuffix" -ArgumentList @("-f", "-i", "-v", "$Binary")
17431749
# Log the import table
1744-
Invoke-Program "$SourceCache\mimalloc\bin\minject$BuildSuffix" "-l" "$Binary"
1750+
Start-Process -Wait -WindowStyle Hidden -FilePath "$SourceCache\mimalloc\bin\minject$BuildSuffix" -ArgumentList @("-l", "$Binary")
17451751
}
17461752
}
17471753

@@ -2927,16 +2933,13 @@ function Build-Installer($Arch) {
29272933
# TODO(hjyamauchi) Re-enable the swift-inspect and swift-docc builds
29282934
# when cross-compiling https://github.com/apple/swift/issues/71655
29292935
$INCLUDE_SWIFT_DOCC = if ($IsCrossCompiling) { "false" } else { "true" }
2930-
$ENABLE_MIMALLOC = if ($Allocator -eq "mimalloc") { "true" } else { "false" }
2931-
# When cross-compiling, bundle the second mimalloc redirect dll as a workaround for
2932-
# https://github.com/microsoft/mimalloc/issues/997
2933-
$WORKAROUND_MIMALLOC_ISSUE_997 = if ($IsCrossCompiling) { "true" } else { "false" }
29342936

29352937
$Properties = @{
29362938
BundleFlavor = "offline";
29372939
TOOLCHAIN_ROOT = "$($Arch.ToolchainInstallRoot)\";
2938-
ENABLE_MIMALLOC = $ENABLE_MIMALLOC;
2939-
WORKAROUND_MIMALLOC_ISSUE_997 = $WORKAROUND_MIMALLOC_ISSUE_997;
2940+
# When cross-compiling, bundle the second mimalloc redirect dll as a workaround for
2941+
# https://github.com/microsoft/mimalloc/issues/997
2942+
WORKAROUND_MIMALLOC_ISSUE_997 = if ($IsCrossCompiling) { "true" } else { "false" };
29402943
INCLUDE_SWIFT_DOCC = $INCLUDE_SWIFT_DOCC;
29412944
SWIFT_DOCC_BUILD = "$($Arch.BinaryCache)\swift-docc\release";
29422945
SWIFT_DOCC_RENDER_ARTIFACT_ROOT = "${SourceCache}\swift-docc-render-artifact";
@@ -3104,8 +3107,8 @@ if (-not $SkipBuild) {
31043107

31053108
Install-HostToolchain
31063109

3107-
if (-not $SkipBuild -and $Allocator -eq "mimalloc") {
3108-
Invoke-BuildStep Build-Mimalloc $HostArch
3110+
if (-not $SkipBuild) {
3111+
Invoke-BuildStep Build-mimalloc $HostArch
31093112
}
31103113

31113114
if (-not $SkipBuild -and -not $IsCrossCompiling) {

0 commit comments

Comments
 (0)