Skip to content

Commit 310a75b

Browse files
Revert "utils: remove option to control the allocator" (#79112)
1 parent 0e117ec commit 310a75b

File tree

1 file changed

+28
-31
lines changed

1 file changed

+28
-31
lines changed

utils/build.ps1

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ 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+
105110
.EXAMPLE
106111
PS> .\Build.ps1
107112
@@ -138,6 +143,7 @@ param(
138143
[switch] $DebugInfo,
139144
[switch] $EnableCaching,
140145
[string] $Cache = "",
146+
[string] $Allocator = "",
141147
[switch] $Summary,
142148
[switch] $ToBatch
143149
)
@@ -1678,56 +1684,44 @@ function Build-Compilers() {
16781684
}
16791685

16801686
# Reference: https://github.com/microsoft/mimalloc/tree/dev/bin#minject
1681-
function Build-mimalloc() {
1687+
function Build-Mimalloc() {
16821688
[CmdletBinding(PositionalBinding = $false)]
16831689
param
16841690
(
16851691
[Parameter(Position = 0, Mandatory = $true)]
16861692
[hashtable]$Arch
16871693
)
16881694

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

16991701
Isolate-EnvVars {
17001702
Invoke-VsDevShell $Arch
17011703
# Avoid hard-coding the VC tools version number
17021704
$VCRedistDir = (Get-ChildItem "${env:VCToolsRedistDir}\$($HostArch.ShortName)" -Filter "Microsoft.VC*.CRT").FullName
17031705
if ($VCRedistDir) {
1704-
TryAdd-KeyValue $Properties VCRedistDir "$VCRedistDir\"
1706+
$MSBuildArgs += "-p:VCRedistDir=$VCRedistDir\"
17051707
}
17061708
}
17071709

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

17191712
$HostSuffix = if ($Arch -eq $ArchX64) { "" } else { "-arm64" }
17201713
$BuildSuffix = if ($BuildArch -eq $ArchX64) { "" } else { "-arm64" }
1721-
1722-
Copy-Item -Path "$($Arch.BinaryCache)\mimalloc\bin\mimalloc.dll" -Destination "$($Arch.ToolchainInstallRoot)\usr\bin\"
1723-
Copy-Item -Path "$($Arch.BinaryCache)\mimalloc\bin\mimalloc-redirect$HostSuffix.dll" -Destination "$($Arch.ToolchainInstallRoot)\usr\bin"
1714+
$Products = @( "mimalloc.dll" )
1715+
foreach ($Product in $Products) {
1716+
Copy-Item -Path "$SourceCache\mimalloc\out\msvc-$($Arch.ShortName)\Release\$Product" -Destination "$($Arch.ToolchainInstallRoot)\usr\bin"
1717+
}
1718+
Copy-Item -Path "$SourceCache\mimalloc\out\msvc-$($Arch.ShortName)\Release\mimalloc-redirect$HostSuffix.dll" -Destination "$($Arch.ToolchainInstallRoot)\usr\bin"
17241719
# When cross-compiling, bundle the second mimalloc redirect dll as a workaround for
17251720
# https://github.com/microsoft/mimalloc/issues/997
17261721
if ($IsCrossCompiling) {
1727-
Copy-Item -Path "$($Arch.BinaryCache)\mimalloc\bin\mimalloc-redirect$HostSuffix.dll" -Destination "$($Arch.ToolchainInstallRoot)\usr\bin\mimalloc-redirect$BuildSuffix.dll"
1722+
Copy-Item -Path "$SourceCache\mimalloc\out\msvc-$($Arch.ShortName)\Release\mimalloc-redirect$HostSuffix.dll" -Destination "$($Arch.ToolchainInstallRoot)\usr\bin\mimalloc-redirect$BuildSuffix.dll"
17281723
}
17291724

1730-
# TODO: should we split this out into its own function?
17311725
$Tools = @(
17321726
"swift.exe",
17331727
"swiftc.exe",
@@ -1744,9 +1738,9 @@ function Build-mimalloc() {
17441738
foreach ($Tool in $Tools) {
17451739
$Binary = [IO.Path]::Combine("$($Arch.ToolchainInstallRoot)\usr\bin", $Tool)
17461740
# Binary-patch in place
1747-
Start-Process -Wait -WindowStyle Hidden -FilePath "$SourceCache\mimalloc\bin\minject$BuildSuffix" -ArgumentList @("-f", "-i", "-v", "$Binary")
1741+
Invoke-Program "$SourceCache\mimalloc\bin\minject$BuildSuffix" "-f" "-i" "-v" "$Binary"
17481742
# Log the import table
1749-
Start-Process -Wait -WindowStyle Hidden -FilePath "$SourceCache\mimalloc\bin\minject$BuildSuffix" -ArgumentList @("-l", "$Binary")
1743+
Invoke-Program "$SourceCache\mimalloc\bin\minject$BuildSuffix" "-l" "$Binary"
17501744
}
17511745
}
17521746

@@ -2947,13 +2941,16 @@ function Build-Installer($Arch) {
29472941
# TODO(hjyamauchi) Re-enable the swift-inspect and swift-docc builds
29482942
# when cross-compiling https://github.com/apple/swift/issues/71655
29492943
$INCLUDE_SWIFT_DOCC = if ($IsCrossCompiling) { "false" } else { "true" }
2944+
$ENABLE_MIMALLOC = if ($Allocator -eq "mimalloc") { "true" } else { "false" }
2945+
# When cross-compiling, bundle the second mimalloc redirect dll as a workaround for
2946+
# https://github.com/microsoft/mimalloc/issues/997
2947+
$WORKAROUND_MIMALLOC_ISSUE_997 = if ($IsCrossCompiling) { "true" } else { "false" }
29502948

29512949
$Properties = @{
29522950
BundleFlavor = "offline";
29532951
TOOLCHAIN_ROOT = "$($Arch.ToolchainInstallRoot)\";
2954-
# When cross-compiling, bundle the second mimalloc redirect dll as a workaround for
2955-
# https://github.com/microsoft/mimalloc/issues/997
2956-
WORKAROUND_MIMALLOC_ISSUE_997 = if ($IsCrossCompiling) { "true" } else { "false" };
2952+
ENABLE_MIMALLOC = $ENABLE_MIMALLOC;
2953+
WORKAROUND_MIMALLOC_ISSUE_997 = $WORKAROUND_MIMALLOC_ISSUE_997;
29572954
INCLUDE_SWIFT_DOCC = $INCLUDE_SWIFT_DOCC;
29582955
SWIFT_DOCC_BUILD = "$($Arch.BinaryCache)\swift-docc\release";
29592956
SWIFT_DOCC_RENDER_ARTIFACT_ROOT = "${SourceCache}\swift-docc-render-artifact";
@@ -3123,8 +3120,8 @@ if (-not $SkipBuild) {
31233120

31243121
Install-HostToolchain
31253122

3126-
if (-not $SkipBuild) {
3127-
Invoke-BuildStep Build-mimalloc $HostArch
3123+
if (-not $SkipBuild -and $Allocator -eq "mimalloc") {
3124+
Invoke-BuildStep Build-Mimalloc $HostArch
31283125
}
31293126

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

0 commit comments

Comments
 (0)