@@ -102,11 +102,6 @@ in batch file format instead of executing them.
102102. PARAMETER HostArchName
103103The architecture where the toolchain will execute.
104104
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-
110105. EXAMPLE
111106PS> .\Build.ps1
112107
@@ -143,7 +138,6 @@ param(
143138 [switch ] $DebugInfo ,
144139 [switch ] $EnableCaching ,
145140 [string ] $Cache = " " ,
146- [string ] $Allocator = " " ,
147141 [switch ] $Summary ,
148142 [switch ] $ToBatch
149143)
@@ -1684,44 +1678,56 @@ function Build-Compilers() {
16841678}
16851679
16861680# Reference: https://github.com/microsoft/mimalloc/tree/dev/bin#minject
1687- function Build-Mimalloc () {
1681+ function Build-mimalloc () {
16881682 [CmdletBinding (PositionalBinding = $false )]
16891683 param
16901684 (
16911685 [Parameter (Position = 0 , Mandatory = $true )]
16921686 [hashtable ]$Arch
16931687 )
16941688
1695- $MSBuildArgs = @ (" $SourceCache \mimalloc\ide\vs2022\mimalloc.sln" )
1689+ # TODO: migrate to the CMake build
1690+ $MSBuildArgs = @ ()
16961691 $MSBuildArgs += " -noLogo"
16971692 $MSBuildArgs += " -maxCpuCount"
1698- $MSBuildArgs += " -p:Configuration=Release"
1699- $MSBuildArgs += " -p:Platform=$ ( $Arch.ShortName ) "
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 ) "
17001698
17011699 Isolate- EnvVars {
17021700 Invoke-VsDevShell $Arch
17031701 # Avoid hard-coding the VC tools version number
17041702 $VCRedistDir = (Get-ChildItem " ${env: VCToolsRedistDir} \$ ( $HostArch.ShortName ) " - Filter " Microsoft.VC*.CRT" ).FullName
17051703 if ($VCRedistDir ) {
1706- $MSBuildArgs += " -p:VCRedistDir= $VCRedistDir \"
1704+ TryAdd - KeyValue $Properties VCRedistDir " $VCRedistDir \"
17071705 }
17081706 }
17091707
1710- Invoke-Program $msbuild @MSBuildArgs
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\"
17111718
17121719 $HostSuffix = if ($Arch -eq $ArchX64 ) { " " } else { " -arm64" }
17131720 $BuildSuffix = if ($BuildArch -eq $ArchX64 ) { " " } else { " -arm64" }
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"
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"
17191724 # When cross-compiling, bundle the second mimalloc redirect dll as a workaround for
17201725 # https://github.com/microsoft/mimalloc/issues/997
17211726 if ($IsCrossCompiling ) {
1722- Copy-Item - Path " $SourceCache \mimalloc\out\msvc- $ ( $Arch.ShortName ) \Release \mimalloc-redirect$HostSuffix .dll" - Destination " $ ( $Arch.ToolchainInstallRoot ) \usr\bin\mimalloc-redirect$BuildSuffix .dll"
1727+ Copy-Item - Path " $ ( $Arch.BinaryCache ) \mimalloc\bin \mimalloc-redirect$HostSuffix .dll" - Destination " $ ( $Arch.ToolchainInstallRoot ) \usr\bin\mimalloc-redirect$BuildSuffix .dll"
17231728 }
17241729
1730+ # TODO: should we split this out into its own function?
17251731 $Tools = @ (
17261732 " swift.exe" ,
17271733 " swiftc.exe" ,
@@ -1738,9 +1744,9 @@ function Build-Mimalloc() {
17381744 foreach ($Tool in $Tools ) {
17391745 $Binary = [IO.Path ]::Combine(" $ ( $Arch.ToolchainInstallRoot ) \usr\bin" , $Tool )
17401746 # Binary-patch in place
1741- Invoke-Program " $SourceCache \mimalloc\bin\minject$BuildSuffix " " -f" " -i" " -v" " $Binary "
1747+ Start-Process - Wait - WindowStyle Hidden - FilePath " $SourceCache \mimalloc\bin\minject$BuildSuffix " - ArgumentList @ ( " -f" , " -i" , " -v" , " $Binary " )
17421748 # Log the import table
1743- Invoke-Program " $SourceCache \mimalloc\bin\minject$BuildSuffix " " -l" " $Binary "
1749+ Start-Process - Wait - WindowStyle Hidden - FilePath " $SourceCache \mimalloc\bin\minject$BuildSuffix " - ArgumentList @ ( " -l" , " $Binary " )
17441750 }
17451751}
17461752
@@ -2926,16 +2932,13 @@ function Build-Installer($Arch) {
29262932 # TODO(hjyamauchi) Re-enable the swift-inspect and swift-docc builds
29272933 # when cross-compiling https://github.com/apple/swift/issues/71655
29282934 $INCLUDE_SWIFT_DOCC = if ($IsCrossCompiling ) { " false" } else { " true" }
2929- $ENABLE_MIMALLOC = if ($Allocator -eq " mimalloc" ) { " true" } else { " false" }
2930- # When cross-compiling, bundle the second mimalloc redirect dll as a workaround for
2931- # https://github.com/microsoft/mimalloc/issues/997
2932- $WORKAROUND_MIMALLOC_ISSUE_997 = if ($IsCrossCompiling ) { " true" } else { " false" }
29332935
29342936 $Properties = @ {
29352937 BundleFlavor = " offline" ;
29362938 TOOLCHAIN_ROOT = " $ ( $Arch.ToolchainInstallRoot ) \" ;
2937- ENABLE_MIMALLOC = $ENABLE_MIMALLOC ;
2938- WORKAROUND_MIMALLOC_ISSUE_997 = $WORKAROUND_MIMALLOC_ISSUE_997 ;
2939+ # When cross-compiling, bundle the second mimalloc redirect dll as a workaround for
2940+ # https://github.com/microsoft/mimalloc/issues/997
2941+ WORKAROUND_MIMALLOC_ISSUE_997 = if ($IsCrossCompiling ) { " true" } else { " false" };
29392942 INCLUDE_SWIFT_DOCC = $INCLUDE_SWIFT_DOCC ;
29402943 SWIFT_DOCC_BUILD = " $ ( $Arch.BinaryCache ) \swift-docc\release" ;
29412944 SWIFT_DOCC_RENDER_ARTIFACT_ROOT = " ${SourceCache} \swift-docc-render-artifact" ;
@@ -3099,8 +3102,8 @@ if (-not $SkipBuild) {
30993102
31003103Install-HostToolchain
31013104
3102- if (-not $SkipBuild -and $Allocator -eq " mimalloc " ) {
3103- Invoke-BuildStep Build-Mimalloc $HostArch
3105+ if (-not $SkipBuild ) {
3106+ Invoke-BuildStep Build-mimalloc $HostArch
31043107}
31053108
31063109if (-not $SkipBuild -and -not $IsCrossCompiling ) {
0 commit comments