Which Crates Will Work Off-the-Shelf with WebAssembly? (original) (raw)
- 1. Introduction
- 2. Why Rust and WebAssembly?
- 3. Background And Concepts
- 4. Tutorial
- 5. Reference
- 5.1. Crates You Should Know
- 5.2. Tools You Should Know
- 5.3. Project Templates
- 5.4. Debugging
- 5.5. Time Profiling
- 5.6. Shrinking .wasm Size
- 5.7. JavaScript Interoperation
- 5.8. Which Crates Will Work Off-the-Shelf with WebAssembly?
- 5.9. How to Add WebAssembly Support to a General-Purpose Crate
- 5.10. Deploying Rust and WebAssembly to Production
Rust and WebAssembly
Which Crates Will Work Off-the-Shelf with WebAssembly?
It is easiest to list the things that do not currently work with WebAssembly; crates which avoid these things tend to be portable to WebAssembly and usually_Just Work_. A good rule of thumb is that if a crate supports embedded and#![no_std]
usage, it probably also supports WebAssembly.
Things a Crate Might do that Won't Work with WebAssembly C and System Library Dependencies
There are no system libraries in wasm, so any crate that tries to bind to a system library won't work.
Using C libraries will also probably fail to work, since wasm doesn't have a stable ABI for cross-language communication, and cross-language linking for wasm is very finicky. Everyone wants this to work eventually, especially sinceclang
is shipping their wasm32
target by default now, but the story isn't quite there yet.
WebAssembly does not have access to a file system, so crates that assume the existence of a file system — and don't have wasm-specific workarounds — will not work.
There are plans to add threading to WebAssembly, but it isn't shipping yet. Attempts to spawn on a thread on the wasm32-unknown-unknown
target will panic, which triggers a wasm trap.
So Which General Purpose Crates Tend to Work Off-the-Shelf with WebAssembly? Algorithms and Data Structures
Crates that provide the implementation of a particularalgorithm or data structure, for example A* graph search or splay trees, tend to work well with WebAssembly.
Crates that do not rely on the standard library tend to work well with WebAssembly.
Parsers — so long as they just take input and don't perform their own I/O — tend to work well with WebAssembly.
Crates that deal with the complexities of human language when expressed in textual form tend to work well with WebAssembly.
Shared solutions for particular situations specific to programming in Rust tend to work well with WebAssembly.