@@ -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)
@@ -1692,44 +1686,56 @@ function Build-Compilers() {
16921686}
16931687
16941688# Reference: https://github.com/microsoft/mimalloc/tree/dev/bin#minject
1695- function Build-Mimalloc () {
1689+ function Build-mimalloc () {
16961690 [CmdletBinding (PositionalBinding = $false )]
16971691 param
16981692 (
16991693 [Parameter (Position = 0 , Mandatory = $true )]
17001694 [hashtable ]$Arch
17011695 )
17021696
1703- $MSBuildArgs = @ (" $SourceCache \mimalloc\ide\vs2022\mimalloc.sln" )
1697+ # TODO: migrate to the CMake build
1698+ $MSBuildArgs = @ ()
17041699 $MSBuildArgs += " -noLogo"
17051700 $MSBuildArgs += " -maxCpuCount"
1706- $MSBuildArgs += " -p:Configuration=Release"
1707- $MSBuildArgs += " -p:Platform=$ ( $Arch.ShortName ) "
1701+
1702+ $Properties = @ {}
1703+ TryAdd- KeyValue $Properties Configuration Release
1704+ TryAdd- KeyValue $Properties OutDir " $ ( $Arch.BinaryCache ) \mimalloc\bin\"
1705+ TryAdd- KeyValue $Properties Platform " $ ( $Arch.ShortName ) "
17081706
17091707 Isolate- EnvVars {
17101708 Invoke-VsDevShell $Arch
17111709 # Avoid hard-coding the VC tools version number
17121710 $VCRedistDir = (Get-ChildItem " ${env: VCToolsRedistDir} \$ ( $HostArch.ShortName ) " - Filter " Microsoft.VC*.CRT" ).FullName
17131711 if ($VCRedistDir ) {
1714- $MSBuildArgs += " -p:VCRedistDir= $VCRedistDir \"
1712+ TryAdd - KeyValue $Properties VCRedistDir " $VCRedistDir \"
17151713 }
17161714 }
17171715
1718- Invoke-Program $msbuild @MSBuildArgs
1716+ foreach ($Property in $Properties.GetEnumerator ()) {
1717+ if ($Property.Value.Contains (" " )) {
1718+ $MSBuildArgs += " -p:$ ( $Property.Key ) =$ ( $Property.Value.Replace (' \' , ' \\' )) "
1719+ } else {
1720+ $MSBuildArgs += " -p:$ ( $Property.Key ) =$ ( $Property.Value ) "
1721+ }
1722+ }
1723+
1724+ Invoke-Program $msbuild " $SourceCache \mimalloc\ide\vs2022\mimalloc-lib.vcxproj" @MSBuildArgs " -p:IntDir=$ ( $Arch.BinaryCache ) \mimalloc\mimalloc\"
1725+ Invoke-Program $msbuild " $SourceCache \mimalloc\ide\vs2022\mimalloc-override-dll.vcxproj" @MSBuildArgs " -p:IntDir=$ ( $Arch.BinaryCache ) \mimalloc\mimalloc-override-dll\"
17191726
17201727 $HostSuffix = if ($Arch -eq $ArchX64 ) { " " } else { " -arm64" }
17211728 $BuildSuffix = if ($BuildArch -eq $ArchX64 ) { " " } else { " -arm64" }
1722- $Products = @ ( " mimalloc.dll" )
1723- foreach ($Product in $Products ) {
1724- Copy-Item - Path " $SourceCache \mimalloc\out\msvc-$ ( $Arch.ShortName ) \Release\$Product " - Destination " $ ( $Arch.ToolchainInstallRoot ) \usr\bin"
1725- }
1726- Copy-Item - Path " $SourceCache \mimalloc\out\msvc-$ ( $Arch.ShortName ) \Release\mimalloc-redirect$HostSuffix .dll" - Destination " $ ( $Arch.ToolchainInstallRoot ) \usr\bin"
1729+
1730+ Copy-Item - Path " $ ( $Arch.BinaryCache ) \mimalloc\bin\mimalloc.dll" - Destination " $ ( $Arch.ToolchainInstallRoot ) \usr\bin\"
1731+ Copy-Item - Path " $ ( $Arch.BinaryCache ) \mimalloc\bin\mimalloc-redirect$HostSuffix .dll" - Destination " $ ( $Arch.ToolchainInstallRoot ) \usr\bin"
17271732 # When cross-compiling, bundle the second mimalloc redirect dll as a workaround for
17281733 # https://github.com/microsoft/mimalloc/issues/997
17291734 if ($IsCrossCompiling ) {
1730- Copy-Item - Path " $SourceCache \mimalloc\out\msvc- $ ( $Arch.ShortName ) \Release \mimalloc-redirect$HostSuffix .dll" - Destination " $ ( $Arch.ToolchainInstallRoot ) \usr\bin\mimalloc-redirect$BuildSuffix .dll"
1735+ Copy-Item - Path " $ ( $Arch.BinaryCache ) \mimalloc\bin \mimalloc-redirect$HostSuffix .dll" - Destination " $ ( $Arch.ToolchainInstallRoot ) \usr\bin\mimalloc-redirect$BuildSuffix .dll"
17311736 }
17321737
1738+ # TODO: should we split this out into its own function?
17331739 $Tools = @ (
17341740 " swift.exe" ,
17351741 " swiftc.exe" ,
@@ -1746,9 +1752,9 @@ function Build-Mimalloc() {
17461752 foreach ($Tool in $Tools ) {
17471753 $Binary = [IO.Path ]::Combine(" $ ( $Arch.ToolchainInstallRoot ) \usr\bin" , $Tool )
17481754 # Binary-patch in place
1749- Invoke-Program " $SourceCache \mimalloc\bin\minject$BuildSuffix " " -f" " -i" " -v" " $Binary "
1755+ Start-Process - Wait - WindowStyle Hidden - FilePath " $SourceCache \mimalloc\bin\minject$BuildSuffix " - ArgumentList @ ( " -f" , " -i" , " -v" , " $Binary " )
17501756 # Log the import table
1751- Invoke-Program " $SourceCache \mimalloc\bin\minject$BuildSuffix " " -l" " $Binary "
1757+ Start-Process - Wait - WindowStyle Hidden - FilePath " $SourceCache \mimalloc\bin\minject$BuildSuffix " - ArgumentList @ ( " -l" , " $Binary " )
17521758 }
17531759}
17541760
@@ -2995,16 +3001,13 @@ function Build-Installer($Arch) {
29953001 # TODO(hjyamauchi) Re-enable the swift-inspect and swift-docc builds
29963002 # when cross-compiling https://github.com/apple/swift/issues/71655
29973003 $INCLUDE_SWIFT_DOCC = if ($IsCrossCompiling ) { " false" } else { " true" }
2998- $ENABLE_MIMALLOC = if ($Allocator -eq " mimalloc" ) { " true" } else { " false" }
2999- # When cross-compiling, bundle the second mimalloc redirect dll as a workaround for
3000- # https://github.com/microsoft/mimalloc/issues/997
3001- $WORKAROUND_MIMALLOC_ISSUE_997 = if ($IsCrossCompiling ) { " true" } else { " false" }
30023004
30033005 $Properties = @ {
30043006 BundleFlavor = " offline" ;
30053007 TOOLCHAIN_ROOT = " $ ( $Arch.ToolchainInstallRoot ) \" ;
3006- ENABLE_MIMALLOC = $ENABLE_MIMALLOC ;
3007- WORKAROUND_MIMALLOC_ISSUE_997 = $WORKAROUND_MIMALLOC_ISSUE_997 ;
3008+ # When cross-compiling, bundle the second mimalloc redirect dll as a workaround for
3009+ # https://github.com/microsoft/mimalloc/issues/997
3010+ WORKAROUND_MIMALLOC_ISSUE_997 = if ($IsCrossCompiling ) { " true" } else { " false" };
30083011 INCLUDE_SWIFT_DOCC = $INCLUDE_SWIFT_DOCC ;
30093012 SWIFT_DOCC_BUILD = " $ ( $Arch.BinaryCache ) \swift-docc\release" ;
30103013 SWIFT_DOCC_RENDER_ARTIFACT_ROOT = " ${SourceCache} \swift-docc-render-artifact" ;
@@ -3178,8 +3181,8 @@ if (-not $SkipBuild) {
31783181
31793182Install-HostToolchain
31803183
3181- if (-not $SkipBuild -and $Allocator -eq " mimalloc " ) {
3182- Invoke-BuildStep Build-Mimalloc $HostArch
3184+ if (-not $SkipBuild ) {
3185+ Invoke-BuildStep Build-mimalloc $HostArch
31833186}
31843187
31853188if (-not $SkipBuild -and -not $IsCrossCompiling ) {
0 commit comments