Skip to content

Commit a957f00

Browse files
committed
Expand doc section about "what about #![no_std]?"
This commit expands the `#![no_std]` section of the documentation with an FAQ-style set of words which explains in more detail about why we don't support `#![no_std]` at this time, and how we can support it in the future.
1 parent 12a31c8 commit a957f00

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

docs/stability-platform-support.md

+68
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,71 @@ cases for for what `#[no_std]` might entail, so if you're interested in this
4242
we'd love to hear about your use case! Feel free to [open an
4343
issue](https://github.com/bytecodealliance/wasmtime/issues/new) on the
4444
`wasmtime` repository to discuss this.
45+
46+
This is a common question we are asked, however, so to provide some more context
47+
on why Wasmtime is the way it is, here's some responses to frequent points
48+
raised about `#![no_std]`:
49+
50+
* **What if my platform doesn't have `std`?** - For platforms without support
51+
for the Rust standard library the JIT compiler of Wasmtime often won't run on
52+
the platform as well. The JIT compiler requires `mmap` (or an equivalent), and
53+
presence of `mmap` often implies presence of a libc which means Rust's `std`
54+
library works. We're interested in running Wasmtime without a JIT compiler in
55+
the future, but that is not implemented at this time. Implementing this will
56+
require a lot more work than tagging crates `#![no_std]` as well! The Wasmtime
57+
developers are also very interested in supporting as many targets as possible,
58+
so if Wasmtime doesn't work on your platform yet we'd love to learn why and
59+
what we can do to support that platform, but the conversation here is
60+
typically more nuanced than simply making `wasmtime` compile without `std`.
61+
62+
* **Doesn't `#![no_std]` have smaller binary sizes?** - There's a lot of factors
63+
that affect binary size in Rust. Compilation options are a huge one but beyond
64+
that idioms and libraries linked matter quite a lot as well. Code is not
65+
inherently large when using `std` instead of `core`, it's just that often code
66+
using `std` has more dependencies (like `std::thread`) which requires code to
67+
bind. Code size improvements can be made to code using `std` and `core`
68+
equally, and switching to `#![no_std]` is not a silver bullet for compile
69+
sizes.
70+
71+
* **The patch to switch to `#![no_std]` is small, why not accept it?** - PRs to
72+
switch to `#![no_std]` are often relatively small or don't impact too many
73+
parts of the system. There's a lot more to developing a `#![no_std]`
74+
WebAssembly runtime than switching a few crates, however. Maintaining a
75+
`#![no_std]` library over time has a number of costs associated with it:
76+
77+
* There needs to be CI to ensure that when compiled with the right flags the
78+
library does not actually use the Rust standard library. Currently there is
79+
no stable way to do this in Rust, meaning that although a library may be
80+
`#![no_std]` at one point in time it's easy to add a dependency that
81+
accidentally sneaks in the `std` crate later.
82+
83+
* Idioms in `#![no_std]` are quite different than normal Rust code. You'll
84+
import from different crates (`core` instead of `std`) and data structures
85+
have to all be manually imported from `alloc`. These idioms are difficult to
86+
learn for newcomers to the project and are not well documented in the
87+
ecosystem. This cost of development and maintenance is not unique to
88+
Wasmtime but in general affects the `#![no_std]` ecosystem at large,
89+
unfortunately.
90+
91+
* Currently Wasmtime does not have a target use case which requires
92+
`#![no_std]` support, so it's hard to justify these costs of development.
93+
We're very interested in supporting as many use cases and targets as
94+
possible, but the decision to support a target needs to take into account
95+
the costs associated so we can plan accordingly. Effectively we need to have
96+
a goal in mind instead of taking on the costs of `#![no_std]` blindly.
97+
98+
* **How can Wasmtime support `#![no_std]` if it uses X?** - Wasmtime as-is today
99+
is not suitable for many `#![no_std]` contexts. For example it might use
100+
`mmap` for allocating JIT code memory, leverage threads for caching, or use
101+
thread locals when calling into JIT code. These features are difficult to
102+
support in their full fidelity on all platforms, but the Wasmtime developers
103+
are very much aware of this! Wasmtime is intended to be configurable where
104+
many of these features are compile-time or runtime options. For example caches
105+
can be disabled, JITs can be removed and replaced with interpreters, or users
106+
could provide a callback to allocate memory instead of using the OS. The
107+
ambitious goals of Wasmtime take time and energy to implement, however, so we
108+
need help from others in order to prioritize what's most important to tackle.
109+
This is sort of a long-winded way of saying that Wasmtime on the surface may
110+
today look like it won't support `#![no_std]`, but this is almost always
111+
simply a matter of time and development priorities rather than a fundamental
112+
reason why Wasmtime *couldn't* support `#![no_std]`.

0 commit comments

Comments
 (0)