@@ -1539,7 +1539,6 @@ function Build-Compilers() {
1539
1539
}
1540
1540
1541
1541
# Reference: https://github.com/microsoft/mimalloc/tree/dev/bin#minject
1542
- # TODO: Add ARM64
1543
1542
function Build-Mimalloc () {
1544
1543
[CmdletBinding (PositionalBinding = $false )]
1545
1544
param
@@ -1548,15 +1547,11 @@ function Build-Mimalloc() {
1548
1547
[hashtable ]$Arch
1549
1548
)
1550
1549
1551
- if ($Arch -ne $ArchX64 ) {
1552
- throw " mimalloc is currently supported for X64 only"
1553
- }
1554
-
1555
1550
$MSBuildArgs = @ (" $SourceCache \mimalloc\ide\vs2022\mimalloc.sln" )
1556
1551
$MSBuildArgs += " -noLogo"
1557
1552
$MSBuildArgs += " -maxCpuCount"
1558
1553
$MSBuildArgs += " -p:Configuration=Release"
1559
- $MSBuildArgs += " -p:ProductArchitecture =$ ( $Arch.VSName ) "
1554
+ $MSBuildArgs += " -p:Platform =$ ( $Arch.ShortName ) "
1560
1555
1561
1556
Isolate- EnvVars {
1562
1557
Invoke-VsDevShell $Arch
@@ -1569,9 +1564,17 @@ function Build-Mimalloc() {
1569
1564
1570
1565
Invoke-Program $msbuild @MSBuildArgs
1571
1566
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" )
1573
1570
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"
1575
1578
}
1576
1579
1577
1580
$Tools = @ (
@@ -1588,11 +1591,11 @@ function Build-Mimalloc() {
1588
1591
" ld64.lld.exe"
1589
1592
)
1590
1593
foreach ($Tool in $Tools ) {
1591
- $Binary = [IO.Path ]::Combine($Dest , $Tool )
1594
+ $Binary = [IO.Path ]::Combine(" $ ( $Arch .ToolchainInstallRoot ) \usr\bin " , $Tool )
1592
1595
# 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 "
1594
1597
# Log the import table
1595
- Invoke-Program " $SourceCache \mimalloc\bin\minject" @ ( " -l" , $Binary )
1598
+ Invoke-Program " $SourceCache \mimalloc\bin\minject$BuildSuffix " " -l" " $Binary "
1596
1599
}
1597
1600
}
1598
1601
@@ -2718,12 +2721,16 @@ function Build-Installer($Arch) {
2718
2721
# TODO(hjyamauchi) Re-enable the swift-inspect and swift-docc builds
2719
2722
# when cross-compiling https://github.com/apple/swift/issues/71655
2720
2723
$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" }
2722
2728
2723
2729
$Properties = @ {
2724
2730
BundleFlavor = " offline" ;
2725
2731
TOOLCHAIN_ROOT = " $ ( $Arch.ToolchainInstallRoot ) \" ;
2726
2732
ENABLE_MIMALLOC = $ENABLE_MIMALLOC ;
2733
+ WORKAROUND_MIMALLOC_ISSUE_997 = $WORKAROUND_MIMALLOC_ISSUE_997 ;
2727
2734
INCLUDE_SWIFT_DOCC = $INCLUDE_SWIFT_DOCC ;
2728
2735
SWIFT_DOCC_BUILD = " $ ( $Arch.BinaryCache ) \swift-docc\release" ;
2729
2736
SWIFT_DOCC_RENDER_ARTIFACT_ROOT = " ${SourceCache} \swift-docc-render-artifact" ;
0 commit comments