@@ -102,6 +102,11 @@ in batch file format instead of executing them.
102
102
. PARAMETER HostArchName
103
103
The architecture where the toolchain will execute.
104
104
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
+
105
110
. EXAMPLE
106
111
PS> .\Build.ps1
107
112
@@ -138,6 +143,7 @@ param(
138
143
[switch ] $DebugInfo ,
139
144
[switch ] $EnableCaching ,
140
145
[string ] $Cache = " " ,
146
+ [string ] $Allocator = " " ,
141
147
[switch ] $Summary ,
142
148
[switch ] $ToBatch
143
149
)
@@ -1678,56 +1684,44 @@ function Build-Compilers() {
1678
1684
}
1679
1685
1680
1686
# Reference: https://github.com/microsoft/mimalloc/tree/dev/bin#minject
1681
- function Build-mimalloc () {
1687
+ function Build-Mimalloc () {
1682
1688
[CmdletBinding (PositionalBinding = $false )]
1683
1689
param
1684
1690
(
1685
1691
[Parameter (Position = 0 , Mandatory = $true )]
1686
1692
[hashtable ]$Arch
1687
1693
)
1688
1694
1689
- # TODO: migrate to the CMake build
1690
- $MSBuildArgs = @ ()
1695
+ $MSBuildArgs = @ (" $SourceCache \mimalloc\ide\vs2022\mimalloc.sln" )
1691
1696
$MSBuildArgs += " -noLogo"
1692
1697
$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 ) "
1698
1700
1699
1701
Isolate- EnvVars {
1700
1702
Invoke-VsDevShell $Arch
1701
1703
# Avoid hard-coding the VC tools version number
1702
1704
$VCRedistDir = (Get-ChildItem " ${env: VCToolsRedistDir} \$ ( $HostArch.ShortName ) " - Filter " Microsoft.VC*.CRT" ).FullName
1703
1705
if ($VCRedistDir ) {
1704
- TryAdd - KeyValue $Properties VCRedistDir " $VCRedistDir \"
1706
+ $MSBuildArgs += " -p:VCRedistDir= $VCRedistDir \"
1705
1707
}
1706
1708
}
1707
1709
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
1718
1711
1719
1712
$HostSuffix = if ($Arch -eq $ArchX64 ) { " " } else { " -arm64" }
1720
1713
$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"
1724
1719
# When cross-compiling, bundle the second mimalloc redirect dll as a workaround for
1725
1720
# https://github.com/microsoft/mimalloc/issues/997
1726
1721
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"
1728
1723
}
1729
1724
1730
- # TODO: should we split this out into its own function?
1731
1725
$Tools = @ (
1732
1726
" swift.exe" ,
1733
1727
" swiftc.exe" ,
@@ -1744,9 +1738,9 @@ function Build-mimalloc() {
1744
1738
foreach ($Tool in $Tools ) {
1745
1739
$Binary = [IO.Path ]::Combine(" $ ( $Arch.ToolchainInstallRoot ) \usr\bin" , $Tool )
1746
1740
# 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 "
1748
1742
# 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 "
1750
1744
}
1751
1745
}
1752
1746
@@ -2947,13 +2941,16 @@ function Build-Installer($Arch) {
2947
2941
# TODO(hjyamauchi) Re-enable the swift-inspect and swift-docc builds
2948
2942
# when cross-compiling https://github.com/apple/swift/issues/71655
2949
2943
$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" }
2950
2948
2951
2949
$Properties = @ {
2952
2950
BundleFlavor = " offline" ;
2953
2951
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 ;
2957
2954
INCLUDE_SWIFT_DOCC = $INCLUDE_SWIFT_DOCC ;
2958
2955
SWIFT_DOCC_BUILD = " $ ( $Arch.BinaryCache ) \swift-docc\release" ;
2959
2956
SWIFT_DOCC_RENDER_ARTIFACT_ROOT = " ${SourceCache} \swift-docc-render-artifact" ;
@@ -3123,8 +3120,8 @@ if (-not $SkipBuild) {
3123
3120
3124
3121
Install-HostToolchain
3125
3122
3126
- if (-not $SkipBuild ) {
3127
- Invoke-BuildStep Build-mimalloc $HostArch
3123
+ if (-not $SkipBuild -and $Allocator -eq " mimalloc " ) {
3124
+ Invoke-BuildStep Build-Mimalloc $HostArch
3128
3125
}
3129
3126
3130
3127
if (-not $SkipBuild -and -not $IsCrossCompiling ) {
0 commit comments