Building Win 10 exe at Mac


#1

Is it possible to build Win exe using Mac.

I understood from here that tool chain x86_64-pc-windows-msvc is available as valid cross complier tool chain for 64-bit MSVC (Windows 7+), and I was able to get it at my mac.

Hasans-MacBook-Air:rust_lib_for_android h_ajsf$ rustup toolchain install stable-x86_64-pc-windows-msvc
info: syncing channel updates for 'stable-x86_64-pc-windows-msvc'
info: latest update on 2018-11-08, rust version 1.30.1 (1433507eb 2018-11-07)
info: downloading component 'rustc'
 53.3 MiB /  53.3 MiB (100 %)   1.0 MiB/s ETA:   0 s                
info: downloading component 'rust-std'
 46.7 MiB /  46.7 MiB (100 %)   1.1 MiB/s ETA:   0 s                 
info: downloading component 'cargo'
  2.7 MiB /   2.7 MiB (100 %)   1.8 MiB/s ETA:   0 s                
info: downloading component 'rust-docs'
  8.9 MiB /   8.9 MiB (100 %)   2.1 MiB/s ETA:   0 s                
info: installing component 'rustc'
info: installing component 'rust-std'
info: installing component 'cargo'
info: installing component 'rust-docs'

  stable-x86_64-pc-windows-msvc installed - (rustc does not exist)

But once I tried to compile using it, I got an error that:

error: toolchain ‘stable-x86_64-pc-windows-msvc’ does not have the binary cargo

As below:

Hasans-MacBook-Air:rust_lib_for_android h_ajsf$ rustup override set stable-x86_64-pc-windows-msvc
info: using existing install for 'stable-x86_64-pc-windows-msvc'
info: override toolchain for '/Users/h_ajsf/Documents/greetings/rust_lib_for_android' set to 'stable-x86_64-pc-windows-msvc'

  stable-x86_64-pc-windows-msvc unchanged - (rustc does not exist)

Hasans-MacBook-Air:rust_lib_for_android h_ajsf$ cargo build
error: toolchain 'stable-x86_64-pc-windows-msvc' does not have the binary `cargo`
Hasans-MacBook-Air:rust_lib_for_android h_ajsf$ rustup target add x86_64-pc-windows-msvc
error: component 'rust-std' for target 'x86_64-pc-windows-msvc' was automatically added because it is required for toolchain 'stable-x86_64-pc-windows-msvc'
Hasans-MacBook-Air:rust_lib_for_android h_ajsf$ cargo build --target x86_64-pc-windows-msvc --release
error: toolchain 'stable-x86_64-pc-windows-msvc' does not have the binary `cargo`

Though the toolchain looks to be installed and ready to use:

Hasans-MacBook-Air:rust_lib_for_android h_ajsf$ rustup show

**Default host:** x86_64-apple-darwin

**installed toolchains**

**--------------------**

stable-x86_64-apple-darwin

stable-x86_64-pc-windows-msvc

nightly-x86_64-apple-darwin

**active toolchain**

**----------------**

stable-x86_64-pc-windows-msvc (directory override for '/Users/h_ajsf/Documents/greetings/rust_lib_for_android')

(rustc does not exist)

Hasans-MacBook-Air:rust_lib_for_android h_ajsf$ rustup override unset

**info:** override toolchain for '/Users/h_ajsf/Documents/greetings/rust_lib_for_android' removed

Am I missing something here, or have misunderstanding about cross compiling!


#2

You installed a toolchain designed to run on Windows, not compile for Windows.

All Rust compilers are native cross-compilers. Both of the already-installed Mac compilers can target Windows. What you need in addition to that are the standard libraries (which rustup calls components, not toolchains), cross-linkers (which Rust doesn’t provide), and any third-party libraries you’re using (which Rust also doesn’t provide).

Also, you don’t set the target platform using rustup, you pass a --target flag to cargo or rustc; rustup just makes sure the necessary standard libraries for that platform are available.

Hopefully someone will be along presently with more details; that’s the limit of what I know.


#3

I covered the remaining steps you need in a blog post. This is a couple years old, so it may be slightly in need of updating, but the gist should still be correct.


#4

Great, thanks