When contributing to Wasmtime and Cranelift you may run into issues that only
reproduce on a different architecture from your development machine. Luckily,
cargo makes cross compilation and running tests under QEMU pretty easy.
This guide will assume you are on an x86-64 with Ubuntu/Debian as your OS. The basic approach (with commands, paths, and package names appropriately tweaked) applies to other Linux distributions as well.
On Windows you can install build tools for AArch64 Windows, but targeting platforms like Linux or macOS is not easy. While toolchains exist for targeting non-Windows platforms you'll have to hunt yourself to find the right one.
On macOS you can install, through Xcode, toolchains for iOS but the main
x86_64-apple-darwin is really the only easy target to install. You'll need to
hunt for toolchains if you want to compile for Linux or Windows.
rustup to install Rust targets for the other architectures that
Wasmtime and Cranelift support:
$ rustup target add \
Next, you'll need to install a
gcc for each cross-compilation target to serve
as a linker for
$ sudo apt install \
You will also need to install
qemu to emulate the cross-compilation targets.
$ sudo apt install qemu-user
The final bit to get out of the way is to configure
cargo to use the
qemu when cross-compiling and running tests for other
Add this to
.cargo/config.toml in the Wasmtime repository (or create that file
if none already exists).
linker = "aarch64-linux-gnu-gcc"
runner = "qemu-aarch64 -L /usr/aarch64-linux-gnu -E LD_LIBRARY_PATH=/usr/aarch64-linux-gnu/lib -E WASMTIME_TEST_NO_HOG_MEMORY=1"
linker = "riscv64-linux-gnu-gcc"
runner = "qemu-riscv64 -L /usr/riscv64-linux-gnu -E LD_LIBRARY_PATH=/usr/riscv64-linux-gnu/lib -E WASMTIME_TEST_NO_HOG_MEMORY=1"
linker = "s390x-linux-gnu-gcc"
runner = "qemu-s390x -L /usr/s390x-linux-gnu -E LD_LIBRARY_PATH=/usr/s390x-linux-gnu/lib -E WASMTIME_TEST_NO_HOG_MEMORY=1"
Now you can use
cargo run, and
cargo test as you normally
would for any crate inside the Wasmtime repository, just add the appropriate
A few examples:
$ cargo build --target aarch64-unknown-linux-gnu
Run the tests under
$ cargo test --target riscv64gc-unknown-linux-gnu
$ cargo run --target s390x-unknown-linux-gnu -- compile example.wasm