Cross-compile Rust Applications
September 15 2018105 words, ~1 min. read
rust, cross-compile, linux, windows
The following steps were required to cross-compile a Rust application on a Debian host targeting 64-bit Microsoft Windows.
- Install
gcccross-compiler
$ sudo apt-get install gcc-mingw-w64
- Add rust toolchain
$ rustup target add x86_64-pc-windows-gnu
Note: To see the list of available toolchain targets, use the command rustup target list. Typically, the each value in the list will be a triplet containing architecture, vendor, system and optionally ABI.
- Configure the target linker
~./cargo/config
[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc"
- Build the application by providing the appropriate target triplet.
$ cargo build --target=x86_64-pc-windows-gnu
- Verify build output
$ file target/x86_64-pc-windows-gnu/debug/<app>.exe
target/x86_64-pc-windows-gnu/debug/<app>.exe: PE32+ executable (console) x86-64, for MS Windows
References