I found these two posts where they ask about cross compiling for Windows on MacOS:
About a year ago I asked an LLM about it, and it uttered something that worked well for me (I did two smallish projects where I used it - both console, without GUI). As in the above posts I didn't see these simple few steps, I thought I post them here:
-
Add Windows as a Target
rustup target add x86_64-pc-windows-gnu -
Install Windows Linker
brew install mingw-w64 -
Create a
.cargo/config.tomlConfiguration
target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc" -
Build for Windows
cargo build --release --target x86_64-pc-windows-gnu
The compiled executable will be in target/x86_64-pc-windows-gnu/release/test.exe
Important Notes:
- Make sure a
config.tomlfile uses Windows-style line endings (CRLF) - Path separators in the code should handle both Unix and Windows styles
- File operations might need adjustments for Windows paths
- Consider using the (
std::path::PathBuf) type for cross-platform path handling - about installing brew see here: https://brew.sh