Path: blob/main/docs/contributing-cross-compiling.md
1685 views
Cross Compiling
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.
Install Rust Targets
First, use rustup
to install Rust targets for the other architectures that Wasmtime and Cranelift support:
Install GCC Cross-Compilation Toolchains
Next, you'll need to install a gcc
for each cross-compilation target to serve as a linker for rustc
.
Install qemu
You will also need to install qemu
to emulate the cross-compilation targets.
Configure Cargo
The final bit to get out of the way is to configure cargo
to use the appropriate gcc
and qemu
when cross-compiling and running tests for other architectures.
You will need to set CARGO_TARGET_<triple>_RUNNER
and CARGO_TARGET_<triple>_LINKER
for the target.
aarch64:
riscv64:
s390x:
Cross-Compile Tests and Run Them!
Now you can use cargo build
, cargo run
, and cargo test
as you normally would for any crate inside the Wasmtime repository, just add the appropriate --target
flag!
A few examples:
Build the
wasmtime
binary foraarch64
:Run the tests under
riscv
emulation:Run the
wasmtime
binary unders390x
emulation: