@@ -1539,7 +1539,6 @@ function Build-Compilers() {
15391539}
15401540
15411541# Reference: https://github.com/microsoft/mimalloc/tree/dev/bin#minject
1542- # TODO: Add ARM64
15431542function Build-Mimalloc () {
15441543 [CmdletBinding (PositionalBinding = $false )]
15451544 param
@@ -1548,15 +1547,11 @@ function Build-Mimalloc() {
15481547 [hashtable ]$Arch
15491548 )
15501549
1551- if ($Arch -ne $ArchX64 ) {
1552- throw " mimalloc is currently supported for X64 only"
1553- }
1554-
15551550 $MSBuildArgs = @ (" $SourceCache \mimalloc\ide\vs2022\mimalloc.sln" )
15561551 $MSBuildArgs += " -noLogo"
15571552 $MSBuildArgs += " -maxCpuCount"
15581553 $MSBuildArgs += " -p:Configuration=Release"
1559- $MSBuildArgs += " -p:ProductArchitecture =$ ( $Arch.VSName ) "
1554+ $MSBuildArgs += " -p:Platform =$ ( $Arch.ShortName ) "
15601555
15611556 Isolate- EnvVars {
15621557 Invoke-VsDevShell $Arch
@@ -1569,9 +1564,17 @@ function Build-Mimalloc() {
15691564
15701565 Invoke-Program $msbuild @MSBuildArgs
15711566
1572- $Products = @ ( " mimalloc-override.dll" , " mimalloc-redirect.dll" )
1567+ $HostSuffix = if ($Arch -eq $ArchX64 ) { " " } else { " -arm64" }
1568+ $BuildSuffix = if ($BuildArch -eq $ArchX64 ) { " " } else { " -arm64" }
1569+ $Products = @ ( " mimalloc.dll" )
15731570 foreach ($Product in $Products ) {
1574- Copy-Item - Path " $SourceCache \mimalloc\out\msvc-$ ( $Arch.ShortName ) \Release\$Product " - Destination " $ ( Arch.ToolchainInstallRoot) \usr\bin"
1571+ Copy-Item - Path " $SourceCache \mimalloc\out\msvc-$ ( $Arch.ShortName ) \Release\$Product " - Destination " $ ( $Arch.ToolchainInstallRoot ) \usr\bin"
1572+ }
1573+ Copy-Item - Path " $SourceCache \mimalloc\out\msvc-$ ( $Arch.ShortName ) \Release\mimalloc-redirect$HostSuffix .dll" - Destination " $ ( $Arch.ToolchainInstallRoot ) \usr\bin"
1574+ # When cross-compiling, bundle the second mimalloc redirect dll as a workaround for
1575+ # https://github.com/microsoft/mimalloc/issues/997
1576+ if ($IsCrossCompiling ) {
1577+ Copy-Item - Path " $SourceCache \mimalloc\out\msvc-$ ( $Arch.ShortName ) \Release\mimalloc-redirect$HostSuffix .dll" - Destination " $ ( $Arch.ToolchainInstallRoot ) \usr\bin\mimalloc-redirect$BuildSuffix .dll"
15751578 }
15761579
15771580 $Tools = @ (
@@ -1588,11 +1591,11 @@ function Build-Mimalloc() {
15881591 " ld64.lld.exe"
15891592 )
15901593 foreach ($Tool in $Tools ) {
1591- $Binary = [IO.Path ]::Combine($Dest , $Tool )
1594+ $Binary = [IO.Path ]::Combine(" $ ( $Arch .ToolchainInstallRoot ) \usr\bin " , $Tool )
15921595 # Binary-patch in place
1593- Invoke-Program " $SourceCache \mimalloc\bin\minject" @ ( " -f" , " -i" , " -v" , $Binary )
1596+ Invoke-Program " $SourceCache \mimalloc\bin\minject$BuildSuffix " " -f" " -i" " -v" " $Binary "
15941597 # Log the import table
1595- Invoke-Program " $SourceCache \mimalloc\bin\minject" @ ( " -l" , $Binary )
1598+ Invoke-Program " $SourceCache \mimalloc\bin\minject$BuildSuffix " " -l" " $Binary "
15961599 }
15971600}
15981601
@@ -2718,12 +2721,16 @@ function Build-Installer($Arch) {
27182721 # TODO(hjyamauchi) Re-enable the swift-inspect and swift-docc builds
27192722 # when cross-compiling https://github.com/apple/swift/issues/71655
27202723 $INCLUDE_SWIFT_DOCC = if ($IsCrossCompiling ) { " false" } else { " true" }
2721- $ENABLE_MIMALLOC = if ($Allocator -eq " mimalloc" -and $Arch -eq $ArchX64 ) { " true" } else { " false" }
2724+ $ENABLE_MIMALLOC = if ($Allocator -eq " mimalloc" ) { " true" } else { " false" }
2725+ # When cross-compiling, bundle the second mimalloc redirect dll as a workaround for
2726+ # https://github.com/microsoft/mimalloc/issues/997
2727+ $WORKAROUND_MIMALLOC_ISSUE_997 = if ($IsCrossCompiling ) { " true" } else { " false" }
27222728
27232729 $Properties = @ {
27242730 BundleFlavor = " offline" ;
27252731 TOOLCHAIN_ROOT = " $ ( $Arch.ToolchainInstallRoot ) \" ;
27262732 ENABLE_MIMALLOC = $ENABLE_MIMALLOC ;
2733+ WORKAROUND_MIMALLOC_ISSUE_997 = $WORKAROUND_MIMALLOC_ISSUE_997 ;
27272734 INCLUDE_SWIFT_DOCC = $INCLUDE_SWIFT_DOCC ;
27282735 SWIFT_DOCC_BUILD = " $ ( $Arch.BinaryCache ) \swift-docc\release" ;
27292736 SWIFT_DOCC_RENDER_ARTIFACT_ROOT = " ${SourceCache} \swift-docc-render-artifact" ;
0 commit comments