rust-lang / cc-rs

Rust library for build scripts to compile C/C++ code into a Rust library
https://docs.rs/cc
Apache License 2.0
1.79k stars 434 forks source link

Ability to cross-compile MASM files #1022

Open russelltg opened 4 months ago

russelltg commented 4 months ago

LLVM has a MASM assembler, llvm-ml, which can perform the tasks of ml.exe and ml64.exe (with the -m64 flag), that can be used when cross-compiling to Windows.

Currently, these .exe names are hardcoded, which feels a bit kludgy, but at least there is the woarkaround of adding a script like

$ cat tools/ml64.exe
#!/bin/bash
llvm-ml -m64 $@

which does indeed work. Ideally cc-rs could be taught about llvm-ml though. I see a few options, that may not be mutually exclusive:

  1. Fallback to llvm-ml if ml64.exe isn't found
  2. Use llvm-ml if host is not Windows
  3. Add a MASM_ASM env var (or similar) to allow selection of an assembler. cc-rs would also have to detect the special case of llvm-ml and 64-bit and be able to add the -m64 flag.

Thoughts?

NobodyXu commented 4 months ago

Thanks, I think option 1 and option 3 makes sense.

Fallback to llvm-ml helps with cross compilation, and having an environment for selecting ar makes a lot of sense.

Though I wonder if we could use existing env variable AR instead of a new one.

russelltg commented 4 months ago

AR is for archivers, not assemblers....

But you're saying "assume you want an LLVM assember if you want an LLVM archiver"?

NobodyXu commented 4 months ago

Thanks for correction, yeah I mixed them up

In that case having a MASM_ASM env var does make sense.

russelltg commented 4 months ago

Since there's no "standard" env var name for this maybe CC_MASM_ASM to match the other cc-specific env var CC_ENABLE_DEBUG_OUTPUT?

NobodyXu commented 4 months ago

Yeah, having CC_ prefix definitely makes sense