Warning: this page has not been updated for Bevy 0.10 yet!

Build Windows EXEs from Linux

(also check out the Windows Platform page for info about developing for Windows generally)


Rust offers two different toolchains for building for Windows:

  • MSVC: the default when working in Windows, requires downloading Microsoft SDKs
  • GNU: alternative MINGW-based build, may be easier to setup

First-Time Setup (MSVC)

Rust Toolchain (MSVC)

You can actually use the same MSVC-based Rust toolchain, that is the standard when working on Windows, from Linux.

Add the target to your Rust installation (assuming you use rustup):

rustup target add x86_64-pc-windows-msvc

This installs the files Rust needs to compile for Windows, including the Rust standard library.

Microsoft Windows SDKs

You need to install the Microsoft Windows SDKs, just like when working on Windows. On Linux, this can be done with an easy script called xwin. You need to accept Microsoft's proprietary license.

Install xwin:

cargo install xwin

Now, use xwin to accept the Microsoft license, download all the files from Microsoft servers, and install them to a directory of your choosing.

For example, to install to ~/.xwin/:

xwin --accept-license splat --output ~/.xwin

Linking (MSVC)

Rust needs to know how to link the final EXE file.

The default Microsoft linker (link.exe) is not available on Linux. Instead, we need to use the LLD linker (this is also recommended when working on Windows anyway). Just install the lld package from your Linux distro.

We also need to tell Rust the location of the Microsoft Windows SDK libraries (that were installed with xwin in the previous step).

Add this to .cargo/config.toml (in your home folder or in your bevy project):

[target.x86_64-pc-windows-msvc]
linker = "lld"
rustflags = [
  "-Lnative=/home/me/.xwin/crt/lib/x86_64",
  "-Lnative=/home/me/.xwin/sdk/lib/um/x86_64",
  "-Lnative=/home/me/.xwin/sdk/lib/ucrt/x86_64"
]

First-Time Setup (GNU)

Rust Toolchain (GNU)

You can also use the alternative GNU-based Windows toolchain.

Add the target to your Rust installation (assuming you use rustup):

rustup target add x86_64-pc-windows-gnu

This installs the files Rust needs to compile for Windows, including the Rust standard library.

MINGW

The GNU toolchain requires the MINGW environment to be installed. Your distro likely provides a package for it. Search your distro for a cross-compilation mingw package.

It might be called something like: cross-x86_64-w64-mingw32, but that varies in different distros.

You don't need any files from Microsoft.

Building Your Project

Finally, with all the setup done, you can just build your Rust/Bevy projects for Windows:

MSVC:

cargo build --target=x86_64-pc-windows-msvc --release

MinGW:

cargo build --target=x86_64-pc-windows-gnu --release