Skip to content

Update mimalloc to v3.0.1 and enable mimalloc for win/arm64 #886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-toolchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ jobs:
tee -a "${GITHUB_OUTPUT}" <<-EOF
indexstore_db_revision=refs/tags/${{ inputs.swift_tag }}
llvm_project_revision=refs/tags/${{ inputs.swift_tag }}
mimalloc_revision=refs/tags/v2.1.7
mimalloc_revision=refs/tags/v3.0.1
sourcekit_lsp_revision=refs/tags/${{ inputs.swift_tag }}
swift_revision=refs/tags/${{ inputs.swift_tag }}
swift_argument_parser_revision=refs/tags/1.4.0
Expand Down
27 changes: 19 additions & 8 deletions .github/workflows/swift-toolchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3430,22 +3430,29 @@ jobs:
}

- uses: actions/checkout@v4
if: matrix.arch == 'amd64'
with:
repository: microsoft/mimalloc
ref: ${{ inputs.mimalloc_revision }}
path: ${{ github.workspace }}/SourceCache/mimalloc

- name: Build and apply mimalloc
if: matrix.arch == 'amd64'
run: |
$HostMSArch = if ("${{ matrix.arch }}" -eq "arm64") { "arm64" } else { "x64" }
$HostSuffix = if ("${{ matrix.arch }}" -eq "arm64") { "-arm64" } else { "" }
$BuildSuffix = if ("${{ inputs.build_arch }}" -eq "arm64") { "-arm64" } else { "" }
# Reference: https://github.com/microsoft/mimalloc/tree/dev/bin#minject
msbuild ${{ github.workspace }}\SourceCache\mimalloc\ide\vs2022\mimalloc.sln -p:Configuration=Release
msbuild ${{ github.workspace }}\SourceCache\mimalloc\ide\vs2022\mimalloc.sln -p:Configuration=Release -p:Platform=$HostMSArch
$ToolchainBin = "${{ github.workspace }}\BuildRoot\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain\usr\bin"
Copy-Item -Path "${{ github.workspace }}\SourceCache\mimalloc\out\msvc-x64\Release\mimalloc-override.dll" `
Copy-Item -Path "${{ github.workspace }}\SourceCache\mimalloc\out\msvc-$HostMSArch\Release\mimalloc.dll" `
-Destination "$ToolchainBin"
Copy-Item -Path "${{ github.workspace }}\SourceCache\mimalloc\out\msvc-x64\Release\mimalloc-redirect.dll" `
Copy-Item -Path "${{ github.workspace }}\SourceCache\mimalloc\out\msvc-$HostMSArch\Release\mimalloc-redirect$HostSuffix.dll" `
-Destination "$ToolchainBin"
# When cross-compiling, bundle the second mimalloc redirect dll as a workaround for
# https://github.com/microsoft/mimalloc/issues/997
if ("${{ inputs.build_arch }}" -ne "${{ matrix.arch }}") {
Copy-Item -Path "${{ github.workspace }}\SourceCache\mimalloc\out\msvc-$HostMSArch\Release\mimalloc-redirect$HostSuffix.dll" `
-Destination "$ToolchainBin/mimalloc-redirect$BuildSuffix.dll"
}
$MimallocExecutables = @("swift.exe",
"swiftc.exe",
"swift-driver.exe",
Expand All @@ -3459,21 +3466,25 @@ jobs:
"ld64.lld.exe")
foreach ($Exe in $MimallocExecutables) {
# Binary-patch in place
${{ github.workspace }}\SourceCache\mimalloc\bin\minject -f -i -v "$ToolchainBin\$Exe"
& "${{ github.workspace }}\SourceCache\mimalloc\bin\minject$BuildSuffix" -f -i -v "$ToolchainBin\$Exe"
# Log the import table
${{ github.workspace }}\SourceCache\mimalloc\bin\minject -l "$ToolchainBin\$Exe"
& "${{ github.workspace }}\SourceCache\mimalloc\bin\minject$BuildSuffix" -l "$ToolchainBin\$Exe"
}

- name: Package Build Tools
run: |
# When cross-compiling, bundle the second mimalloc redirect dll as a workaround for
# https://github.com/microsoft/mimalloc/issues/997
$WORKAROUND_MIMALLOC_ISSUE_997 = if ("${{ inputs.build_arch }}" -ne "${{ matrix.arch }}") { "true" } else { "false" }
msbuild -nologo -restore -maxCpuCount `
-p:BaseOutputPath=${{ github.workspace }}\BinaryCache\installer\ `
-p:Configuration=Release `
-p:SignOutput=${{ inputs.signed }} `
-p:CERTIFICATE=${env:CERTIFICATE} `
-p:PASSPHRASE=${{ secrets.PASSPHRASE }} `
-p:TOOLCHAIN_ROOT=${{ github.workspace }}/BuildRoot/Library/Developer/Toolchains/unknown-Asserts-development.xctoolchain `
-p:ENABLE_MIMALLOC=${{ matrix.arch == 'amd64' && 'true' || 'false' }} `
-p:ENABLE_MIMALLOC=true `
-p:WORKAROUND_MIMALLOC_ISSUE_997=$WORKAROUND_MIMALLOC_ISSUE_997 `
-p:ProductArchitecture=${{ matrix.arch }} `
-p:ProductVersion=${{ inputs.swift_version }} `
${{ github.workspace }}/SourceCache/swift-installer-scripts/platforms/Windows/bld/bld.wixproj
Expand Down
2 changes: 1 addition & 1 deletion default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

<project remote="github" name="madler/zlib" path="zlib" revision="refs/tags/v1.3.1" />

<project remote="github" name="microsoft/mimalloc" path="mimalloc" revision="refs/tags/v2.1.7" />
<project remote="github" name="microsoft/mimalloc" path="mimalloc" revision="refs/tags/v3.0.1" />

<project remote="github" name="ninja-build/ninja" path="ninja" groups="notdefault,dependencies" revision="master" />
</manifest>