Repository navigation
feat: add CC_MASM_ASM and fall back to llvm-ml for MASM files - #1975
Merged
Merged
Conversation
`CC_MASM_ASM` overrides the assembler for `.asm` files on MSVC targets. It is read with target prefixes and can include arguments, like `AR`. When it is not set and neither Visual Studio nor `PATH` has `ml64.exe` or `ml.exe`, x86 targets fall back to `llvm-ml`: next to clang-cl, the way the archiver already finds `llvm-lib` (now one shared helper), then on `PATH`. llvm-ml gets `-m64` or `-m32` for the target, before any user arguments so a `-m` there still wins, and no `-Zi`, which it ignores with a warning.
NobodyXu
requested changes
Oct 5, 2026
NobodyXu
left a comment
Contributor
There was a problem hiding this comment.
Thank you! Just two feedback
NobodyXu
requested changes
Oct 5, 2026
NobodyXu
left a comment
Contributor
There was a problem hiding this comment.
Sorry one more for the tests
The test shim now records the program it runs as, before its arguments, so tests can check which shim cc invoked. The tests for the MASM assembler and the clang-cl archiver use it, and the ARM test checks that nothing ran.
Windows file names are case-insensitive, so `LLVM-ML.exe` is llvm-ml too and needs `-m64` or `-m32`.
`msvc_macro_assembler` returns a `Tool` now. `compile_objects` keeps it in an `Option` that the first `.asm` file fills, so the assembler lookup and the `CC_MASM_ASM` read run once per build instead of once per file.
1 task
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.
Cross compiling a crate with
.asmfiles for an MSVC target from Linux or macOS fails withfailed to find tool "ml64.exe", because cc always runsml64.exeorml.exefor them. The usual workaround is anml64.exescript onPATHthat runsllvm-ml -m64, as in conda-forge/polars-feedstock#240.This implements both parts agreed in the issue:
CC_MASM_ASMoverrides the assembler for.asmfiles on MSVC targets. It is read with the usual target prefixes (CC_MASM_ASM_<target>,TARGET_CC_MASM_ASMand so on) and parsed likeAR, soCC_MASM_ASM="llvm-ml -m64"works.PATHhasml64.exeorml.exe, x86 and x86_64 targets fall back tollvm-ml. cc looks next to clang-cl first, with the lookup the archiver already uses forllvm-lib(now one shared helper), then onPATH.When the assembler is llvm-ml (by file name, ignoring case), cc passes
-m64or-m32for the target, since llvm-ml assembles 32 bit code unless it runs asllvm-ml64. The flag goes before the arguments fromCC_MASM_ASMandasm_flag, and llvm-ml takes the last-m, so a user's choice still wins. cc also leaves out-Zifor llvm-ml, which ignores it with a warning on every debug build.Behavior change
PATHhasml64.exeorml.exe, including wrapper scripts with that name, cc runs it as before.armasm.exeandarmasm64.exewith no fallback, since llvm-ml only assembles x86.CC_MASM_ASMapplies to them too..asmcompiles on MSVC targets now readCC_MASM_ASMand its target variants, so Cargo getsrerun-if-env-changedlines for them.llvm-liblookup for clang-cl moved into the shared helper without changes.compilecall instead of once per.asmfile, so itsrerun-if-env-changedlines no longer repeat for every file.Validation
tests/test.rs. The 5CC_MASM_ASMtests run on every host. The 5 inmsvc_masm_fallbackarecfg(not(windows)), because a Windows host with Visual Studio findsml64.exeand never reaches the fallback, and their shims have no.exesuffix. The test shim now records the program it runs as, so the tests check which program cc ran, or that nothing ran.failed to find tool "ml64.exe". The other 3 pass on main and guard unchanged behavior:ml64.exeonPATHstill wins over llvm-ml, ARM doesn't fall back, and clang-cl still findsllvm-libnext to it.cargo testwith and without--features parallel(except 7clang_apple_*/gnu_apple_*tests that need a full Xcode install),cargo clippy --workspace --all-targets -- -D warnings(also withparallel, and-p ccforx86_64-pc-windows-msvc),cargo fmt --check,cargo doc, and a rustc 1.65 check of the library.dev-tools/cc-test, and a real llvm-ml binary. llvm-ml's handling of-m,-Ziand the other flags cc passes (-nologo,-c,-Fo,-I,-D,-safeseh) was checked against its option table andGetTripleinllvm/tools/llvm-ml.Limitations
AR, a wrapper such assccacheinCC_MASM_ASMis dropped.llvm-mlonly.Fixes #1022