Skip to content

Adjust to mimalloc v3.0.1 and enable mimalloc arm64 #78994

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
Jan 30, 2025
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
31 changes: 19 additions & 12 deletions utils/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,6 @@ function Build-Compilers() {
}

# Reference: https://github.com/microsoft/mimalloc/tree/dev/bin#minject
# TODO: Add ARM64
function Build-Mimalloc() {
[CmdletBinding(PositionalBinding = $false)]
param
Expand All @@ -1548,15 +1547,11 @@ function Build-Mimalloc() {
[hashtable]$Arch
)

if ($Arch -ne $ArchX64) {
throw "mimalloc is currently supported for X64 only"
}

$MSBuildArgs = @("$SourceCache\mimalloc\ide\vs2022\mimalloc.sln")
$MSBuildArgs += "-noLogo"
$MSBuildArgs += "-maxCpuCount"
$MSBuildArgs += "-p:Configuration=Release"
$MSBuildArgs += "-p:ProductArchitecture=$($Arch.VSName)"
$MSBuildArgs += "-p:Platform=$($Arch.ShortName)"

Isolate-EnvVars {
Invoke-VsDevShell $Arch
Expand All @@ -1569,9 +1564,17 @@ function Build-Mimalloc() {

Invoke-Program $msbuild @MSBuildArgs

$Products = @( "mimalloc-override.dll", "mimalloc-redirect.dll" )
$HostSuffix = if ($Arch -eq $ArchX64) { "" } else { "-arm64" }
$BuildSuffix = if ($BuildArch -eq $ArchX64) { "" } else { "-arm64" }
$Products = @( "mimalloc.dll" )
foreach ($Product in $Products) {
Copy-Item -Path "$SourceCache\mimalloc\out\msvc-$($Arch.ShortName)\Release\$Product" -Destination "$(Arch.ToolchainInstallRoot)\usr\bin"
Copy-Item -Path "$SourceCache\mimalloc\out\msvc-$($Arch.ShortName)\Release\$Product" -Destination "$($Arch.ToolchainInstallRoot)\usr\bin"
}
Copy-Item -Path "$SourceCache\mimalloc\out\msvc-$($Arch.ShortName)\Release\mimalloc-redirect$HostSuffix.dll" -Destination "$($Arch.ToolchainInstallRoot)\usr\bin"
# When cross-compiling, bundle the second mimalloc redirect dll as a workaround for
# https://github.com/microsoft/mimalloc/issues/997
if ($IsCrossCompiling) {
Copy-Item -Path "$SourceCache\mimalloc\out\msvc-$($Arch.ShortName)\Release\mimalloc-redirect$HostSuffix.dll" -Destination "$($Arch.ToolchainInstallRoot)\usr\bin\mimalloc-redirect$BuildSuffix.dll"
}

$Tools = @(
Expand All @@ -1588,11 +1591,11 @@ function Build-Mimalloc() {
"ld64.lld.exe"
)
foreach ($Tool in $Tools) {
$Binary = [IO.Path]::Combine($Dest, $Tool)
$Binary = [IO.Path]::Combine("$($Arch.ToolchainInstallRoot)\usr\bin", $Tool)
# Binary-patch in place
Invoke-Program "$SourceCache\mimalloc\bin\minject" @("-f", "-i", "-v", $Binary)
Invoke-Program "$SourceCache\mimalloc\bin\minject$BuildSuffix" "-f" "-i" "-v" "$Binary"
# Log the import table
Invoke-Program "$SourceCache\mimalloc\bin\minject" @("-l", $Binary)
Invoke-Program "$SourceCache\mimalloc\bin\minject$BuildSuffix" "-l" "$Binary"
}
}

Expand Down Expand Up @@ -2718,12 +2721,16 @@ function Build-Installer($Arch) {
# TODO(hjyamauchi) Re-enable the swift-inspect and swift-docc builds
# when cross-compiling https://github.com/apple/swift/issues/71655
$INCLUDE_SWIFT_DOCC = if ($IsCrossCompiling) { "false" } else { "true" }
$ENABLE_MIMALLOC = if ($Allocator -eq "mimalloc" -and $Arch -eq $ArchX64) { "true" } else { "false" }
$ENABLE_MIMALLOC = if ($Allocator -eq "mimalloc") { "true" } else { "false" }
# When cross-compiling, bundle the second mimalloc redirect dll as a workaround for
# https://github.com/microsoft/mimalloc/issues/997
$WORKAROUND_MIMALLOC_ISSUE_997 = if ($IsCrossCompiling) { "true" } else { "false" }

$Properties = @{
BundleFlavor = "offline";
TOOLCHAIN_ROOT = "$($Arch.ToolchainInstallRoot)\";
ENABLE_MIMALLOC = $ENABLE_MIMALLOC;
WORKAROUND_MIMALLOC_ISSUE_997 = $WORKAROUND_MIMALLOC_ISSUE_997;
INCLUDE_SWIFT_DOCC = $INCLUDE_SWIFT_DOCC;
SWIFT_DOCC_BUILD = "$($Arch.BinaryCache)\swift-docc\release";
SWIFT_DOCC_RENDER_ARTIFACT_ROOT = "${SourceCache}\swift-docc-render-artifact";
Expand Down