rustcross-compilingvst

How to cross-compile Rust to Windows using xwin and xtask


I'm trying to cross-compile an example audio plugin from Nih-plug from Linux (Ubuntu) to Windows.

Cross-compiling works when using the target x86_64-pc-windows-gnu (Mingw-w64), but the binaries produced aren't compatible with Win7, because they call the entry point waitonaddress api-ms-win-core-synch-l1-2-0.dll. I think Mingw-w64 is the culprit.

I would like to try to cross-compile using msvc instead of gnu; cargo-xwin offers to do this.

However, Nih-plug uses xtask to create specific binaries (vst3 and clap) via a "bundle" task, and it seems xwin only lets one use the standard cargo build command.

How would one proceed to use cargo-xwin with xtask?


Solution

  • Trying to use cargo-xwin combined with xtask is probably possible but quite difficult, esp. when one cannot directly access the xtask script to change the cargo command. (Both GPT4o and Gemini 1.5 couldn't find a solution.)

    The approach is in fact quite straightforward, it's to NOT use cargo-xwin at all, but instead target x86_64-pc-windows-msvc in the compilation command.

    But just installing the target with rustup isn't enough (that will result in the error linker 'link.exe' not found). The proper approach is documented here and is as follows:

    And then it just works!

    (It doesn't solve my problem though because at present the whole chain seems to target Win8.1 (?), and the executables produced aren't compatible with Win7; but at least it compiles with no error.)