Skip to content

Commit 6e86668

Browse files
committed
Docs: add section on running under qemu.
1 parent f22f415 commit 6e86668

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

docs/contributing-building.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,55 @@ cargo build --target aarch64-unknown-linux-gnu --release
142142
The built executable will be located at
143143
`target/aarch64-unknown-linux-gnu/release/wasmtime`. Note that you can
144144
cross-compile the C API in the same manner as the CLI too.
145+
146+
Note that if you are using these invocations regularly, you can avoid the need
147+
to set environment variables by adding some configuration to your persistent
148+
Cargo configuration. In the file `~/.cargo/config.toml` (in your home
149+
directory), add the section:
150+
151+
```plain
152+
[target.aarch64-unknown-linux-gnu]
153+
linker = 'aarch64-linux-gnu-gcc'
154+
```
155+
156+
Then the above `cargo build --target aarch64-unknown-linux-gnu` command should
157+
work without setting any extra environment variables beforehand.
158+
159+
## Running a Cross-Compiled Wasmtime in qemu (emulation)
160+
161+
Once you have cross-compiled a binary, it is possible to run it on an emulator
162+
if you do not have access to (or do not wish to use) hardware with the given
163+
architecture. This can be done using an emulator such as `qemu`. The `qemu`
164+
user-space emulation support allows running, for example, a Linux/aarch64
165+
binary on a Linux/x86-64 host, as long as you have the system libraries for
166+
aarch64 as well.
167+
168+
To try this out, first install `qemu`, making sure that the user-space emulator
169+
option for your target architecture is enabled. On Debian-based Linux
170+
distributions (including Ubuntu), this is in the `qemu-user` package, for
171+
example.
172+
173+
Next, make sure that you have system libraries for the target. You will already
174+
have these present if you cross-compiled as described above.
175+
176+
Finally, you can run the `wasmtime` binary under `qemu`; the following example
177+
is for an `aarch64` target. Adjust the library paths as appropriate; these are
178+
correct for Ubuntu/Debian's cross-compilation packages.
179+
180+
```shell
181+
qemu-aarch64 \
182+
-L /usr/aarch64-linux-gnu \
183+
-E LD_LIBRARY_PATH=/usr/aarch64-linux-gnu/lib \
184+
target/aarch64-unknown-linux-gnu/release/wasmtime [ARGS]
185+
```
186+
187+
You can add this to your persistent Cargo configuration as well. Extending the
188+
above example in `~/.cargo/config.toml`, you can add:
189+
190+
```plain
191+
[target.aarch64-unknown-linux-gnu]
192+
linker = 'aarch64-linux-gnu-gcc'
193+
runner = "qemu-aarch64 -L /usr/aarch64-linux-gnu -E LD_LIBRARY_PATH=/usr/aarch64-linux-gnu/lib"
194+
```
195+
196+
Then a simple `cargo test --target aarch64-unknown-linux-gnu` should work.

0 commit comments

Comments
 (0)