fix(sys): compile mimalloc as C++ on windows-msvc targets#65
Merged
Brooooooklyn merged 1 commit intoMay 14, 2026
Conversation
Contributor
Author
|
Test in rolldown/rolldown#9373 |
This was referenced May 15, 2026
shulaoda
added a commit
to rolldown/rolldown
that referenced
this pull request
May 15, 2026
camc314
added a commit
to oxc-project/oxc
that referenced
this pull request
May 16, 2026
See napi-rs/mimalloc-safe#65 Co-authored-by: Cameron <cameron.clark@hey.com>
IWANABETHATGUY
pushed a commit
to rolldown/rolldown
that referenced
this pull request
May 18, 2026
V1OL3TF0X
pushed a commit
to V1OL3TF0X/rolldown
that referenced
this pull request
May 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #64
Summary
Force
libmimalloc-sys/c_src/mimalloc/src/static.cto be compiled as C++ on every windows-msvc target, not just MSVC-style drivers. This fixes theaarch64-pc-windows-msvcbuild underTARGET_CC=clangand aligns the post-#16cc-rspath with the pre-#16cmakepath, which explicitly setMI_USE_CXX=ON.Why
Since
libmimalloc-sys2 0.1.55bumped the bundled mimalloc submodule,aarch64-pc-windows-msvcbuilds invoked withTARGET_CC=clangfail:Failing CI run (rolldown): https://github.com/rolldown/rolldown/actions/runs/25723489236/job/75533705378
Same regression reported in oxc: oxc-project/oxc#22329
Root cause
atomic.hhas three mutually exclusive branches:clang --target=*-pc-windows-msvcdefines_MSC_VERfor MSVC ABI compatibility, so when the source is compiled as C it takes the_MSC_VERbranch._M_ARM64sub-branch of that path calls__ldar64/__stlr64, which are MSVC-only intrinsics. clang does not declare them in C mode on Windows, hence the build failure.set_source_files_properties(... LANGUAGE CXX)in its ownCMakeLists.txtto enforce this. Compiling as C++ takes the#if defined(__cplusplus)branch and avoids the MSVC-intrinsics path entirely.Why the previous code did not already do this
build_mimalloc_winwas introduced in #16, replacing acmakepath that explicitly setMI_USE_CXX=ON. The intent was preserved as:However
cc::Build::cpp(true)does not inject/TPor-x c++(a search ofcc-1.2.xconfirms this) — it only changes which env vars are read (CXX/CXXFLAGS), the compiler binary name resolution (clang→clang++,gcc→g++), and C++ stdlib linking.cl.exestill compilesstatic.cas C, andclang++dispatches by extension and also compiles.cas C. SoMI_USE_CXX=ONwas never actually re-implemented after thecmake→cc-rsmigration; the bug was masked by coincidence:cl.exe_M_X64__iso_volatile_load64etc.cl.exe_M_ARM64__ldar64/__stlr64nativelyclang(msvc target)_M_X64__iso_volatile_load64clang(msvc target)_M_ARM64__ldar64/__stlr64→ failsThe recent mimalloc submodule bump made the
_M_ARM64sub-branch the only path that matters on ARM64, exposing the coincidence.Fix
Explicitly force C++ compilation of
static.cregardless of driver:cpp(true)is still kept soCXX/ C++ stdlib resolution behave correctly./TPcoverscl.exeandclang-cl.exe;-xc++covers plainclang.exe(gnu-driver) with--target=*-pc-windows-msvc.This restores the original
MI_USE_CXX=ONsemantics that #16 intended to carry over.Related
Downstream pin workarounds (can be reverted once this lands and a new
libmimalloc-sys2is published):mimalloc-safe = "=0.1.58"libmimalloc-sys2 = "=0.1.54"inCargo.lock