Bala's Blog

Cross-compile Rust Applications

September 15 2018
105 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.

  1. Install gcc cross-compiler
$ sudo apt-get install gcc-mingw-w64
  1. 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.

  1. Configure the target linker ~./cargo/config
[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc"
  1. Build the application by providing the appropriate target triplet.
$ cargo build --target=x86_64-pc-windows-gnu
  1. 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