Cross-compilation under macOS

For Linux

Source

First, install the following tap:

$ brew tap messense/macos-cross-toolchains

Then, install the toolchain for the desired Linux target:

$ brew install x86_64-unknown-linux-gnu

Then, set the environment variables for your shell (here Fish, use export for Bash or Zsh):

set -x CC_x86_64_unknown_linux_gnu "x86_64-unknown-linux-gnu-gcc"
set -x CXX_x86_64_unknown_linux_gnu "x86_64-unknown-linux-gnu-g++"
set -x AR_x86_64_unknown_linux_gnu "x86_64-unknown-linux-gnu-ar"
set -x CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER "x86_64-unknown-linux-gnu-gcc"

Warning : the fact that the Cargo environment variable is all in capital letters is important.

For Windows

$ brew install mingw-w64