Skip to content

Commit eb47be3

Browse files
authored
Clarify emscripten vs unknown-unknown target usecases
1 parent 8b58ea1 commit eb47be3

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/doc/rustc/src/platform-support/wasm32-unknown-emscripten.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,25 @@
55
The `wasm32-unknown-emscripten` target is a WebAssembly compilation target which
66
uses the [Emscripten](https://emscripten.org/) compiler toolchain. Emscripten is
77
a C/C++ toolchain designed to make it as easy as possible to port C/C++ code
8-
written for Linux to run on the web. It thus provides POSIX-compatible (musl) `libc`
9-
and `libstd` implementations and many Linux APIs, access to the OpenGL and SDL APIs,
10-
and the ability to run arbitrary JavaScript code, all based on web APIs using JS
11-
glue code. With the `wasm32-unknown-emscripten` target, Rust code can interoperate
12-
with Emscripten's ecosystem, C/C++ and JS code, and web APIs.
8+
written for Linux to run on the web or in other JavaScript runtimes such as Node.
9+
It thus provides POSIX-compatible (musl) `libc` and `libstd` implementations and
10+
many Linux APIs, access to the OpenGL and SDL APIs, and the ability to run arbitrary
11+
JavaScript code, all based on web APIs using JS glue code. With the
12+
`wasm32-unknown-emscripten` target, Rust code can interoperate with Emscripten's
13+
ecosystem, C/C++ and JS code, and web APIs.
1314

1415
One existing user of this target is the
1516
[`pyodide` project](https://pyodide.org/) which provides a Python runtime in
1617
WebAssembly using Emscripten and compiles Python extension modules written in Rust
1718
to the `wasm32-unknown-emscripten` target.
1819

19-
If you want to generate a standalone WebAssembly binary that does not
20-
require access to the web APIs or the Rust standard library,
21-
the [`wasm32-unknown-unknown`](./wasm32-unknown-unknown.md) target may be better
22-
suited for you. However, [`wasm32-unknown-unknown`](./wasm32-unknown-unknown.md) does not (easily)
23-
support interop with C/C++ code.
20+
If you want to generate a standalone WebAssembly binary that does not require
21+
access to the web APIs or the Rust standard library, the
22+
[`wasm32-unknown-unknown`](./wasm32-unknown-unknown.md) target may be better
23+
suited for you. However, [`wasm32-unknown-unknown`](./wasm32-unknown-unknown.md)
24+
does not (easily) support interop with C/C++ code. Please refer to the
25+
[wasm-bindgen](https://crates.io/crates/wasm-bindgen) crate in case you want to
26+
interoperate with JavaScript with this target.
2427

2528
Like Emscripten, the WASI targets [`wasm32-wasip1`](./wasm32-wasip1.md) and
2629
[`wasm32-wasip2`](./wasm32-wasip2.md) also provide access to the host environment,
@@ -118,8 +121,8 @@ To run these tests, both `emcc` and `node` need to be in your `$PATH`. You can
118121
install `node`, for example, using `nvm` by following the instructions at
119122
<https://github.com/nvm-sh/nvm#install--update-script>.
120123

121-
Still, it's recommended to test the [`wasm32-wasip1`](./wasm32-wasip1.md) target
122-
instead for WebAssembly compatibility.
124+
If you need to test WebAssembly compatibility *in general*, it is recommended
125+
to test the [`wasm32-wasip1`](./wasm32-wasip1.md) target instead.
123126

124127
## Conditionally compiling code
125128

0 commit comments

Comments
 (0)