1. 安装multirust:
https://github.com/brson/multirust
2. 安装 linux stable, windows stable:
multirust update stable // 安装 linux stable
multirust update gnu-win --installer http://static.rust-lang.org/dist/rust-1.7.0-x86_64-pc-windows-gnu.tar.gz
3. 进入 multirust toolchain目录在 linux stable rustlib目录建立 gnu-win 的软链接(目的是让cargo找到windows 的std文件):
cd ~/.multirust/toolchain
cd ~/.multirust/toolchains/stable/lib/rustlib
ln -s ~/.multirust/toolchains/gnu-win/lib/rustlib/win-x86_64-gnu .
现在看看stable目录结构:
ll ~/.multirust/toolchains/stable/lib/rustlib
total 144
drwxr-xr-x 4 xxxx xxxx 4096 Apr 8 11:16 ./
drwxr-xr-x 3 xxxx xxxx 4096 Apr 6 11:49 ../
-rw-r--r-- 1 xxxx xxxx 56 Apr 6 11:49 components
drwxr-xr-x 2 xxxx xxxx 4096 Apr 6 11:49 etc/
-rw-r--r-- 1 xxxx xxxx 69406 Apr 6 11:49 install.log
-rw-r--r-- 1 xxxx xxxx 606 Apr 6 11:49 manifest-cargo
-rw-r--r-- 1 xxxx xxxx 3360 Apr 6 11:49 manifest-rustc
-rw-r--r-- 1 xxxx xxxx 68 Apr 6 11:49 manifest-rust-docs
-rw-r--r-- 1 xxxx xxxx 5877 Apr 6 11:49 manifest-rust-std-x86_64-unknown-linux-gnu
-rw-r--r-- 1 xxxx xxxx 2 Apr 6 11:49 rust-installer-version
-rwxr--r-- 1 xxxx xxxx 26960 Apr 6 11:49 uninstall.sh*
lrwxrwxrwx 1 xxxx xxxx 85 Apr 8 11:16 x86_64-pc-windows-gnu -> /home/xxxx/.multirust/toolchains/win-x86_64-gnu/lib/rustlib/x86_64-pc-windows-gnu/
drwxr-xr-x 3 xxxx xxxx 4096 Apr 6 11:49 x86_64-unknown-linux-gnu/
4. 安装mingw-w64
sudo apt-get install mingw-w64
5. 配置cargo使用的linker
vi ~/.cargo/config
[target.x86_64-pc-windows-gnu]
linker = "/usr/bin/x86_64-w64-mingw32-gcc"
ar = "/usr/bin/x86_64-w64-mingw32-ar"
6. 编译检查
cargo build --target "x86_64-pc-windows-gnu"
参考:
1. http://wiki.archlinux.org/index.php/Rust
2. https://github.com/japaric/rust-cross