1bf526b62SAlex Crichton# Platform Support 2bf526b62SAlex Crichton 35054d400SAlex CrichtonThis page is intended to give a high-level overview of Wasmtime's platform 45054d400SAlex Crichtonsupport along with some aspirations of Wasmtime. For more details see the 55054d400SAlex Crichtondocumentation on [tiers of stability](./stability-tiers.md) which has specific 65054d400SAlex Crichtoninformation about what's supported in Wasmtime on a per-matrix-combination 75054d400SAlex Crichtonbasis. 839e57e3eSAlex Crichton 95054d400SAlex CrichtonWasmtime strives to support hardware that anyone wants to run WebAssembly on. 107f9049b9SAlex CrichtonWasmtime is intended to work out-of-the-box on most platforms by having 117f9049b9SAlex Crichtonplatform-specific defaults for the runtime. For example the native Cranelift 127f9049b9SAlex Crichtonbackend is enabled by default if supported, but otherwise the Pulley 137f9049b9SAlex Crichtoninterpreter backend is used if it's not supported. 1439e57e3eSAlex Crichton 155054d400SAlex Crichton## Compiler Support 1639e57e3eSAlex Crichton 175054d400SAlex CrichtonCranelift supports x86\_64, aarch64, s390x, and riscv64. No 32-bit platform is 185054d400SAlex Crichtoncurrently supported. Building a new backend for Cranelift is a relatively large 195054d400SAlex Crichtonundertaking which maintainers are willing to help with but it's recommended to 205054d400SAlex Crichtonreach out to Cranelift maintainers first to discuss this. 2139e57e3eSAlex Crichton 225054d400SAlex CrichtonWinch supports x86\_64. The aarch64 backend is in development. Winch is built on 235054d400SAlex CrichtonCranelift's support for emitting instructions so Winch's possible backend list 245054d400SAlex Crichtonis currently limited to what Cranelift supports. 255054d400SAlex Crichton 265054d400SAlex CrichtonUsage of the Cranelift or Winch requires a host operating system which supports 275054d400SAlex Crichtoncreating executable memory pages on-the-fly. Support for statically linking in a 285054d400SAlex Crichtonsingle precompiled module is not supported at this time. 295054d400SAlex Crichton 305054d400SAlex CrichtonBoth Cranelift and Winch can be used either in AOT or JIT mode. In AOT mode one 315054d400SAlex Crichtonprocess precompiles a module/component and then loads it into another process. 325054d400SAlex CrichtonIn JIT mode this is all done within the same process. 335054d400SAlex Crichton 345054d400SAlex CrichtonNeither Cranelift nor Winch support tiering at this time in the sense of having 355054d400SAlex Crichtona WebAssembly module start from a Winch compilation and automatically switch to 365054d400SAlex Crichtona Cranelift compilation. Modules are either entirely compiled with Winch or 375054d400SAlex CrichtonCranelift. 3839e57e3eSAlex Crichton 3939e57e3eSAlex Crichton## Interpreter support 4039e57e3eSAlex Crichton 418a969897SAlex CrichtonThe `wasmtime` crate provides an implementation of a [WebAssembly interpreter 428a969897SAlex Crichtonnamed "Pulley"](./examples-pulley.md) which is a portable implementation of 438a969897SAlex Crichtonexecuting WebAssembly code. Pulley uses a custom bytecode which is created from 448a969897SAlex Crichtoninput WebAssembly similarly to how native architectures are supported. Pulley's 458a969897SAlex Crichtonbytecode is created via a Cranelift backend for Pulley, so compile times for 468a969897SAlex Crichtonthe interpreter are expected to be similar to natively compiled code. 477f9049b9SAlex Crichton 487f9049b9SAlex CrichtonThe main advantage of Pulley is that the bytecode can be executed on any 497f9049b9SAlex Crichtonplatform with the same pointer-width and endianness. For example to execute 507f9049b9SAlex CrichtonPulley on a 32-bit ARM platform you'd use the target `pulley32`. Similarly if 517f9049b9SAlex Crichtonyou wanted to run Pulley on x86\_64 you'd use the target `pulley64` for 527f9049b9SAlex CrichtonWasmtime. 537f9049b9SAlex Crichton 547f9049b9SAlex CrichtonPulley's platform requirements are no greater than that of Wasmtime itself, 557f9049b9SAlex Crichtonmeaning that the goal is that if you can compile Wasmtime for a Rust target then 567f9049b9SAlex CrichtonPulley can run on that target. 577f9049b9SAlex Crichton 587f9049b9SAlex CrichtonFinally, note that while Pulley is optimized to be an efficient interpreter it 597f9049b9SAlex Crichtonwill never be as fast as native Cranelift backends. A performance penalty should 607f9049b9SAlex Crichtonbe expected when using Pulley. 617f9049b9SAlex Crichton 627f9049b9SAlex Crichton## OS Support 637f9049b9SAlex Crichton 647f9049b9SAlex CrichtonWasmtime with Pulley should work out-of-the-box on any Rust target, but for 657f9049b9SAlex Crichtonoptimal runtime performance of WebAssembly OS integration is required. In the 667f9049b9SAlex Crichtonsame way that Pulley is slower than a native Cranelift backend Wasmtime will be 677f9049b9SAlex Crichtonslower on Rust targets it has no OS support for. Wasmtime will for example use 687f9049b9SAlex Crichtonvirtual memory when possible to implement WebAssembly linear memories to 697f9049b9SAlex Crichtonefficiently allocate/grow/deallocate. 707f9049b9SAlex Crichton 717f9049b9SAlex CrichtonOS support at this time primarily includes Windows, macOS, and Linux. Other 727f9049b9SAlex CrichtonOSes such as iOS, Android, and Illumos are supported but less well tested. 737f9049b9SAlex CrichtonPRs to the Wasmtime repository are welcome for new OSes for better native 747f9049b9SAlex Crichtonplatform support of a runtime environment. 7539e57e3eSAlex Crichton 765054d400SAlex Crichton## Support for `#![no_std]` 7739e57e3eSAlex Crichton 785054d400SAlex CrichtonThe `wasmtime` crate supports being build on no\_std platforms in Rust, but 795054d400SAlex Crichtononly for a subset of its compile-time Cargo features. Currently supported 805054d400SAlex CrichtonCargo features are: 8139ea6414SAlex Crichton 825054d400SAlex Crichton* `runtime` 835054d400SAlex Crichton* `gc` 845054d400SAlex Crichton* `component-model` 857f9049b9SAlex Crichton* `pulley` 86*7746998dSPiotr Sikora* `async` 87*7746998dSPiotr Sikora* `debug` 88*7746998dSPiotr Sikora* `debug-builtins` 89*7746998dSPiotr Sikora* `demangle` 90*7746998dSPiotr Sikora* `anyhow` 9139ea6414SAlex Crichton 925054d400SAlex CrichtonThis notably does not include the `default` feature which means that when 935054d400SAlex Crichtondepending on Wasmtime you'll need to specify `default-features = false`. This 945054d400SAlex Crichtonalso notably does not include Cranelift or Winch at this time meaning that 955054d400SAlex Crichtonno\_std platforms must be used in AOT mode where the module is precompiled 965054d400SAlex Crichtonelsewhere. 9739ea6414SAlex Crichton 985054d400SAlex CrichtonWasmtime's support for no\_std requires the embedder to implement the equivalent 995054d400SAlex Crichtonof a C header file to indicate how to perform basic OS operations such as 1005054d400SAlex Crichtonallocating virtual memory. This API can be found as `wasmtime-platform.h` in 1015054d400SAlex CrichtonWasmtime's release artifacts or at 1025054d400SAlex Crichton`examples/min-platform/embedding/wasmtime-platform.h` in the source tree. Note 1035054d400SAlex Crichtonthat this API is not guaranteed to be stable at this time, it'll need to be 1045054d400SAlex Crichtonupdated when Wasmtime is updated. 10539ea6414SAlex Crichton 1065054d400SAlex CrichtonWasmtime's runtime will use the symbols defined in this file meaning that if 1075054d400SAlex Crichtonthey're not defined then a link-time error will be generated. Embedders are 1085054d400SAlex Crichtonrequired to implement these functions in accordance with their documentation to 1095054d400SAlex Crichtonenable Wasmtime to run on custom platforms. 1107f9049b9SAlex Crichton 1117f9049b9SAlex CrichtonNote that many functions in this header file are gated behind off-by-default 1127f9049b9SAlex Crichton`#ifdef` directives indicating that Wasmtime doesn't require them by default. 1137f9049b9SAlex CrichtonThe `wasmtime` crate features `custom-{virtual-memory,native-signals}` can be 1147f9049b9SAlex Crichtonused to enable usage of these APIs if desired. 115