How to Cross-Compile Rust for Windows from Linux

Add the Windows target with rustup and build your Rust project using the --target flag to generate a Windows executable from Linux.

Use rustup to install the Windows target and then compile your code with the --target flag pointing to x86_64-pc-windows-gnu or x86_64-pc-windows-msvc.

rustup target add x86_64-pc-windows-gnu
cargo build --target x86_64-pc-windows-gnu --release

This generates a Windows executable in target/x86_64-pc-windows-gnu/release/.