Skip to content

Commit c831aa5

Browse files
authored
Merge pull request #78994 from hjyamauchi/mimallocarm64
Adjust to mimalloc v3.0.1 and enable mimalloc arm64
2 parents 3772032 + e838cec commit c831aa5

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

utils/build.ps1

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,7 +1685,6 @@ function Build-Compilers() {
16851685
}
16861686

16871687
# Reference: https://github.com/microsoft/mimalloc/tree/dev/bin#minject
1688-
# TODO: Add ARM64
16891688
function Build-Mimalloc() {
16901689
[CmdletBinding(PositionalBinding = $false)]
16911690
param
@@ -1694,15 +1693,11 @@ function Build-Mimalloc() {
16941693
[hashtable]$Arch
16951694
)
16961695

1697-
if ($Arch -ne $ArchX64) {
1698-
throw "mimalloc is currently supported for X64 only"
1699-
}
1700-
17011696
$MSBuildArgs = @("$SourceCache\mimalloc\ide\vs2022\mimalloc.sln")
17021697
$MSBuildArgs += "-noLogo"
17031698
$MSBuildArgs += "-maxCpuCount"
17041699
$MSBuildArgs += "-p:Configuration=Release"
1705-
$MSBuildArgs += "-p:ProductArchitecture=$($Arch.VSName)"
1700+
$MSBuildArgs += "-p:Platform=$($Arch.ShortName)"
17061701

17071702
Isolate-EnvVars {
17081703
Invoke-VsDevShell $Arch
@@ -1715,9 +1710,17 @@ function Build-Mimalloc() {
17151710

17161711
Invoke-Program $msbuild @MSBuildArgs
17171712

1718-
$Products = @( "mimalloc-override.dll", "mimalloc-redirect.dll" )
1713+
$HostSuffix = if ($Arch -eq $ArchX64) { "" } else { "-arm64" }
1714+
$BuildSuffix = if ($BuildArch -eq $ArchX64) { "" } else { "-arm64" }
1715+
$Products = @( "mimalloc.dll" )
17191716
foreach ($Product in $Products) {
1720-
Copy-Item -Path "$SourceCache\mimalloc\out\msvc-$($Arch.ShortName)\Release\$Product" -Destination "$(Arch.ToolchainInstallRoot)\usr\bin"
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"
1720+
# When cross-compiling, bundle the second mimalloc redirect dll as a workaround for
1721+
# https://github.com/microsoft/mimalloc/issues/997
1722+
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"
17211724
}
17221725

17231726
$Tools = @(
@@ -1734,11 +1737,11 @@ function Build-Mimalloc() {
17341737
"ld64.lld.exe"
17351738
)
17361739
foreach ($Tool in $Tools) {
1737-
$Binary = [IO.Path]::Combine($Dest, $Tool)
1740+
$Binary = [IO.Path]::Combine("$($Arch.ToolchainInstallRoot)\usr\bin", $Tool)
17381741
# Binary-patch in place
1739-
Invoke-Program "$SourceCache\mimalloc\bin\minject" @("-f", "-i", "-v", $Binary)
1742+
Invoke-Program "$SourceCache\mimalloc\bin\minject$BuildSuffix" "-f" "-i" "-v" "$Binary"
17401743
# Log the import table
1741-
Invoke-Program "$SourceCache\mimalloc\bin\minject" @("-l", $Binary)
1744+
Invoke-Program "$SourceCache\mimalloc\bin\minject$BuildSuffix" "-l" "$Binary"
17421745
}
17431746
}
17441747

@@ -2924,12 +2927,16 @@ function Build-Installer($Arch) {
29242927
# TODO(hjyamauchi) Re-enable the swift-inspect and swift-docc builds
29252928
# when cross-compiling https://github.com/apple/swift/issues/71655
29262929
$INCLUDE_SWIFT_DOCC = if ($IsCrossCompiling) { "false" } else { "true" }
2927-
$ENABLE_MIMALLOC = if ($Allocator -eq "mimalloc" -and $Arch -eq $ArchX64) { "true" } else { "false" }
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" }
29282934

29292935
$Properties = @{
29302936
BundleFlavor = "offline";
29312937
TOOLCHAIN_ROOT = "$($Arch.ToolchainInstallRoot)\";
29322938
ENABLE_MIMALLOC = $ENABLE_MIMALLOC;
2939+
WORKAROUND_MIMALLOC_ISSUE_997 = $WORKAROUND_MIMALLOC_ISSUE_997;
29332940
INCLUDE_SWIFT_DOCC = $INCLUDE_SWIFT_DOCC;
29342941
SWIFT_DOCC_BUILD = "$($Arch.BinaryCache)\swift-docc\release";
29352942
SWIFT_DOCC_RENDER_ARTIFACT_ROOT = "${SourceCache}\swift-docc-render-artifact";

0 commit comments

Comments
 (0)