|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Changes to Rust's WASI targets |
| 4 | +author: Yosh Wuyts |
| 5 | +--- |
| 6 | + |
| 7 | +[WASI 0.2 was recently |
| 8 | +stabilized](https://bytecodealliance.org/articles/WASI-0.2), and Rust has begun |
| 9 | +implementing first-class support for it in the form of a dedicated new target. |
| 10 | +In this post we'll discuss the introduction of the new target, what that means |
| 11 | +for the older targets, and the schedule by which we plan to roll out these |
| 12 | +changes. |
| 13 | + |
| 14 | +## Introducing `wasm32-wasip2` |
| 15 | + |
| 16 | +After nearly five years of work the [WASI 0.2 specification](https://wasi.dev) |
| 17 | +was recently stabilized. This work builds on [WebAssembly |
| 18 | +Components](https://component-model.bytecodealliance.org) (think: strongly-typed |
| 19 | +ABI for Wasm), providing standard interfaces for things like asynchronous IO, |
| 20 | +networking, and HTTP. This will finally make it possible to write asynchronous |
| 21 | +networked services on top of WASI, something which wasn't possible using WASI |
| 22 | +0.1. |
| 23 | + |
| 24 | +People interested in compiling Rust code to WASI 0.2 today are able to do so |
| 25 | +using the [cargo-component](https://github.com/bytecodealliance/cargo-component) |
| 26 | +tool. This tool is able to take WASI 0.1 binaries, and transform them to WASI 0.2 |
| 27 | +Components using a shim. It also provides native support for common cargo |
| 28 | +commands such as `cargo build`, `cargo test`, and `cargo run`. While it |
| 29 | +introduces some inefficiencies because of the additional translation layer, in |
| 30 | +practice this already works really well and people should be enough able to get |
| 31 | +started with WASI 0.2 development. |
| 32 | + |
| 33 | +We're however keen to begin making that translation layer obsolete. And for |
| 34 | +that reason we're happy to share that Rust has made its first steps towards |
| 35 | +that with the introduction of the [tier |
| 36 | +3](https://doc.rust-lang.org/rustc/platform-support.html#tier-3) `wasm32-wasip2` |
| 37 | +target landing in Rust 1.78. **This will initially miss a lot of expected** |
| 38 | +**features such as stdlib support, and we don't recommend people use this target** |
| 39 | +**quite yet.** But as we fill in those missing features over the coming months, we |
| 40 | +aim to eventually hit meet the criteria to become a tier 2 target, at which |
| 41 | +point the `wasm32-wasip2` target would be considered ready for general use. This |
| 42 | +work will happen through 2024, and we expect for this to land before the end of |
| 43 | +the calendar year. |
| 44 | + |
| 45 | +## Renaming `wasm32-wasi` to `wasm32-wasip1` |
| 46 | + |
| 47 | +The original name for what we now call WASI 0.1 was "WebAssembly System |
| 48 | +Interface, snapshot 1". Rust shipped support for this in 2019, and we did so |
| 49 | +knowing the target would likely undergo significant changes in the future. With |
| 50 | +the knowledge we have today though, we would not have chosen to introduce the |
| 51 | +"WASI, snapshot 1" target as `wasm32-wasi`. We should have instead chosen to add |
| 52 | +some suffix to the initial target triple so that the eventual stable WASI 1.0 |
| 53 | +target can just be called `wasm32-wasi`. |
| 54 | + |
| 55 | +In anticipation of both an eventual WASI 1.0 target, and to preserve consistency |
| 56 | +between target names, we'll begin rolling out a name change to the existing WASI |
| 57 | +0.1 target. Starting in Rust 1.78 (May 2nd, 2024) a new `wasm32-wasip1` target |
| 58 | +will become available. Starting Rust 1.81 we will begin warning existing users |
| 59 | +of `wasm32-wasi` to migrate to `wasm32-wasip1`. And finally in Rust 1.84 |
| 60 | +(January 9th, 2025) the `wasm32-wasi` target will no shipped on the stable |
| 61 | +release channel. This will provide an 8 month transition period for projects to |
| 62 | +switch to the new target name when they update their Rust toolchains. |
| 63 | + |
| 64 | +The name `wasip1` can be read as either "WASI (zero) point one" or "WASI preview |
| 65 | +one". The official specification uses the "preview" moniker, however in most |
| 66 | +communication the form "WASI 0.1" is now preferred. This target triple was |
| 67 | +chosen because it not only maps to both terms, but also more closely resembles |
| 68 | +the target terminology used in [other programming |
| 69 | +languages](https://go.dev/blog/wasi). This is something the WASI Preview 2 |
| 70 | +specification [also makes note |
| 71 | +of](https://github.com/WebAssembly/WASI/tree/f45e72e5294e990c23d548eea32fd35c80525fd6/preview2#introduction). |
| 72 | + |
| 73 | +## Timeline |
| 74 | + |
| 75 | +This table provides the dates and cut-offs for the target rename from |
| 76 | +`wasm32-wasi` to `wasm32-wasip1`. The dates in this table do not apply to the |
| 77 | +newly-introduced `wasm32-wasi-preview1-threads` target; this will be renamed to |
| 78 | +`wasm32-wasip1-threads` in Rust 1.78 without going through a transition period. |
| 79 | +The tier 3 `wasm32-wasip2` target will also be made available in Rust 1.78. |
| 80 | + |
| 81 | +| date | Rust Stable | Rust Beta | Rust Nightly | Notes | |
| 82 | +| ---------- | ----------- | --------- | ------------ | ---------------------------------------- | |
| 83 | +| 2024-02-08 | 1.76 | 1.77 | 1.78 | `wasm32-wasip1` available on nightly | |
| 84 | +| 2024-03-21 | 1.77 | 1.78 | 1.79 | `wasm32-wasip1` available on beta | |
| 85 | +| 2024-05-02 | 1.78 | 1.79 | 1.80 | `wasm32-wasip1` available on stable | |
| 86 | +| 2024-06-13 | 1.79 | 1.80 | 1.81 | warn if `wasm32-wasi` is used on nightly | |
| 87 | +| 2024-07-25 | 1.80 | 1.81 | 1.82 | warn if `wasm32-wasi` is used on beta | |
| 88 | +| 2024-09-05 | 1.81 | 1.82 | 1.83 | warn if `wasm32-wasi` is used on stable | |
| 89 | +| 2024-10-17 | 1.82 | 1.83 | 1.84 | `wasm32-wasi` unavailable on nightly | |
| 90 | +| 2024-11-28 | 1.83 | 1.84 | 1.85 | `wasm32-wasi` unavailable on beta | |
| 91 | +| 2025-01-09 | 1.84 | 1.85 | 1.86 | `wasm32-wasi` unavailable on stable | |
| 92 | + |
| 93 | +## Conclusion |
| 94 | + |
| 95 | +In this post we've discussed the upcoming updates to Rust's WASI targets. Come |
| 96 | +Rust 1.78 the `wasm32-wasip1` (tier 2) and `wasm32-wasip2` (tier 3) targets will |
| 97 | +be added. In Rust 1.81 we will begin warning if `wasm32-wasi` is being used. And in Rust 1.84, the existing `wasm32-wasi` target will be removed. |
| 98 | +Users will have 8 months to switch to the new target name when they update their |
| 99 | +Rust toolchains. |
| 100 | + |
| 101 | +The `wasm32-wasip2` target marks the start of native support for WASI 0.2. In |
| 102 | +order to target it today from Rust, people are encouraged to use |
| 103 | +[cargo-component](https://github.com/bytecodealliance/cargo-component) tool |
| 104 | +instead. The plan is to eventually graduate `wasm32-wasip2` to a tier-2 target, |
| 105 | +at which point `cargo-component` will be upgraded to support it natively instead. |
| 106 | + |
| 107 | +With WASI 0.2 finally stable, it's an exciting time for WebAssembly development. |
| 108 | +We're happy for Rust to begin implementing native support for WASI 0.2, and |
| 109 | +we're excited for what this will enable people to build. |
0 commit comments