@@ -18,16 +18,16 @@ Rust compiler and the [official C ABI][tool-conventions] will be used instead.
18
18
## History of ` wasm32-unknown-unknown ` 's C ABI
19
19
20
20
When the ` wasm32-unknown-unknown ` target [ was originally added] [ inception ] in
21
- 2017 not much care was given to the exact definition of the ` extern "C" ` ABI at
22
- the time. In 2018 [ an ABI definition wasm added just for wasm] [ orig-abi ] and the
21
+ 2017, not much care was given to the exact definition of the ` extern "C" ` ABI at
22
+ the time. In 2018 [ an ABI definition was added just for wasm] [ orig-abi ] and the
23
23
target is still using this definition [ to this day] [ current-abi ] . This
24
24
definitions has become more and more problematic over time and while some issues
25
25
have been fixed, the root cause still remains.
26
26
27
27
Notably this ABI definition does not match the [ tool-conventions] definition of
28
28
the C API, which is the current standard for how WebAssembly toolchains should
29
29
talk to one another. Originally this non-standard definition was used for all
30
- WebAssembly based target except Emscripten, but [ this changed in 2021] [ fix-wasi ]
30
+ WebAssembly based targets except Emscripten, but [ this changed in 2021] [ fix-wasi ]
31
31
where the WASI targets for Rust use a corrected ABI definition. Still, however,
32
32
the non-standard definition remained in use for ` wasm32-unknown-unknown ` .
33
33
@@ -48,7 +48,7 @@ The definition of an ABI answers questions along the lines of:
48
48
* What is the size and alignment of a type in memory?
49
49
50
50
For WebAssembly these answers are a little different than native platforms.
51
- WebAssembly does not have physical registers for example and functions must all
51
+ For example, WebAssembly does not have physical registers and functions must all
52
52
be annotated with a type. What WebAssembly does have is types such as ` i32 ` ,
53
53
` i64 ` , ` f32 ` , and ` f64 ` . This means that for WebAssembly an ABI needs to define
54
54
how to represent values in these types.
@@ -61,14 +61,14 @@ is passed directly as a parameter as a function argument. If the Rust structure
61
61
` #[repr(C)] struct Pair(f32, f64) ` is returned from a function then a return
62
62
pointer is used which must have alignment 8 and size of 16 bytes.
63
63
64
- In essence the WebAssembly C ABI is acting as a bridge between C's type system
64
+ In essence, the WebAssembly C ABI is acting as a bridge between C's type system
65
65
and the WebAssembly type system. This includes details such as in-memory layouts
66
66
and translations of a C function signature to a WebAssembly function signature.
67
67
68
68
## How is ` wasm32-unknown-unknown ` non-standard?
69
69
70
- Despite the ABI definition today being non-standard many aspects of it are
71
- still the same as what [ tool-conventions] specifies. For example size/alignment
70
+ Despite the ABI definition today being non-standard, many aspects of it are
71
+ still the same as what [ tool-conventions] specifies. For example, size/alignment
72
72
of types is the same as it is in C. The main difference is how function
73
73
signatures are calculated. An example (where you can follow along on [ godbolt] )
74
74
is:
@@ -133,17 +133,17 @@ The Diplomat project has [compiled a much more comprehensive overview][quirks]
133
133
than this and it's recommended to check that out if you're curious for an even
134
134
deeper dive.
135
135
136
- ## What hasn't this been fixed?
136
+ ## Why hasn't this been fixed long ago already ?
137
137
138
138
For ` wasm32-unknown-unknown ` it was well-known at the time in 2021 when WASI's
139
- ABI was updated that the ABI was non-standard. Why then, in the 4 years within
140
- that duration and 4 years afterward has the ABI not been fixed like with WASI?
139
+ ABI was updated that the ABI was non-standard. Why then has the ABI not been
140
+ fixed like with WASI?
141
141
The main reason originally for this was the [ wasm-bindgen
142
142
project] [ wasm-bindgen ] .
143
143
144
144
In ` wasm-bindgen ` the goal is to make it easy to integrate Rust into a web
145
145
browser with WebAssembly. JavaScript is used to interact with host APIs and the
146
- Rust module itself. Naturally this communication touches on a lot of ABI
146
+ Rust module itself. Naturally, this communication touches on a lot of ABI
147
147
details! The problem was that ` wasm-bindgen ` relied on the above example,
148
148
specifically having ` Pair ` "splatted" across arguments instead of passed
149
149
indirectly. The generated JS wouldn't work correctly if the argument was passed
@@ -160,7 +160,7 @@ gotten greater that there are more unknown projects relying on the non-standard
160
160
behavior.
161
161
162
162
In late 2023 [ the wasm-bindgen project fixed bindings generation] [ wbgfix ] to be
163
- compatible with the standard definition of ` extern "C" ` . In the following months
163
+ unaffected by the transition to the standard definition of ` extern "C" ` . In the following months
164
164
a [ future-incompat lint was added to rustc] [ fcw1 ] to specifically migrate users
165
165
of old ` wasm-bindgen ` versions to a "fixed" version. This was in anticipation of
166
166
changing the ABI of ` wasm32-unknown-unknown ` once enough time had passed. Since
0 commit comments