Hello everyone,

I have set up the rust compiler on linux as cross compiler for windows 64bit and linux. It’s not hard, but there are some fiddly bits. I post my instructions here for your ease.

Setting up a linux VM

Demo in virtualbox of debian 8.2 amd64 netinst, 512MB ram, 8GB disk, NAT network.

In tasksel I selected to install nothing – not even the standard system utilities

Getting started on linux

We install some packages: curl, file and sudo are used by the installer, gcc is used for its linker. After that, just run the rust installer – I did it as root but that’s not even necessary.

root@debian:~# apt-get install curl file sudo gcc root@debian:~# curl -sSf https://static.rust-lang.org/rustup.sh|sh

This is enough to compile local native packages

A note for the rust developers: rustup crashes if sudo is not available. Re-running the script re-downloads everything, maybe it should check first or reuse the downloaded version…

Cross compiling for windows 64bit

You need win64 specific binutils and the necessary rust libraries:

root@debian:~# apt-get install gcc-mingw-w64-x86-64 root@debian:~# curl -O https://static.rust-lang.org/dist/rust-1.4.0-x86_64-pc-windows-gnu.tar.gz root@debian:~# tar xzf rust-1.4.0-x86_64-pc-windows-gnu.tar.gz root@debian:~# mv rust-1.4.0_x86_64-pc-windows-gnu/rustc/bin/rustlib/x86_64-pc-windows-gnu /usr/local/lib/rustlib root@debian:~# chown -R root.staff /usr/local/lib/rustlib/x86_64-pc-windows-gnu

And you need to configure cargo for cross compilation by adding some data to cargo’s config. You can do this in ~/.cargo or in a .cargo subfolder of your project:

user@debian:~# mkdir ~/.cargo user@debian:~# nano ~/.cargo/config [target.x86_64-pc-windows-gnu] ar="x86_64-w64-mingw32-gcc" linker="x86_64-w64-mingw32-gcc"

That’s all, you can now create win64 exes:

Cross compiling for windows 32bit

I can’t get this one to work yet. The idea is the same for windows 32bit, replacing x86_64 with i686:

root@debian:~# apt-get install gcc-mingw-w64-i686 root@debian:~# curl -O https://static.rust-lang.org/dist/rust-1.4.0-i686-pc-windows-gnu.tar.gz root@debian:~# tar xzf rust-1.4.0-i686-pc-windows-gnu.tar.gz root@debian:~# mv rust-1.4.0_i686-pc-windows-gnu/rustc/bin/rustlib/i686-pc-windows-gnu /usr/local/lib/rustlib root@debian:~# chown -R root.staff /usr/local/lib/rustlib/i686-pc-windows-gnu

Add another section to the cargo config, e.g. at the bottom:

user@debian:~# nano ~/.cargo/config

[target.i686-pc-windows-gnu] ar="i686-w64-mingw32-gcc" linker="i686-w64-mingw32-gcc"

This did work on my real computer, but today it errors like this:

As far as I understand, it seems you can build mingw32 in 2 variants: sjlj and dwarf2. This error means the variant of the compiler used while building rust does not match the variant used by debian.

No idea how to handle this one, but if I find out, i’ll let you know.