You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A lot has happened since we shipped the first version of our Wasm Language Module for Unit.
19
-
Back in September 2023 we said: ::
19
+
Back in September 2023 we said:
20
20
21
-
We introduce WebAssembly support as a Technology Preview - we expect to replace it with WASI-HTTP
22
-
support as soon as that is possible.
21
+
|We introduce WebAssembly support as a Technology Preview - we expect to replace it with WASI-HTTP support as soon as that is possible.
23
22
24
23
We have done just that with Unit 1.32.0. This release supports Wasm Components using the WASI 0.2 APIs and the wasi:http/proxy world as its main interface.
25
24
@@ -48,7 +47,7 @@ As we are creating Wasm components for server-side runtimes, we cannot target br
48
47
The code we write can be compiled into an executable binary file. After launching it, we will see "Hello World" printed on the command line. The magic behind this is a standard called POSIX, which defines system calls. System calls work differently on different operating systems.
49
48
50
49
WASI provides an abstraction layer for those syscalls, that can be targeted from the Code that will be compiled to Wasm.
51
-
A WASI compatible runtime will be able to handle the execution of that code. We see this in action in our `Rust tutorial </news/2024/wasm-component-model-part-2>`-- further in part 2 of this blog series. Since Preview2 of the WASI proposal - `the WASI-APIs are defined in WIT-files <https://bytecodealliance.org/articles/webassembly-the-updated-roadmap-for-developers#webassembly-system-interface-wasi>`__.
50
+
A WASI compatible runtime will be able to handle the execution of that code. We see this in action in our `Rust tutorial </news/2024/wasm-component-model-part-2>`__ further in part 2 of this blog series. Since Preview2 of the WASI proposal - `the WASI-APIs are defined in WIT-files <https://bytecodealliance.org/articles/webassembly-the-updated-roadmap-for-developers#webassembly-system-interface-wasi>`__.
52
51
53
52
WIT (Wasm Interface Types) is a descriptive `interface description language (IDL) <https://en.wikipedia.org/wiki/IDL_(programming_language)>`__ to define interfaces. It isn't a general-purpose coding language. The written WIT files don't contain any business logic; they are pure definitions of contracts. Multiple interfaces can be further combined into worlds. While it is not required to deeply understand the way you can create your own WIT-files, it will help to track down issues or trouble-shoot them while building components. To learn more about the WIT programming language, see the official `documentation. <https://component-model.bytecodealliance.org/design/wit.html#structure-of-a-wit-file>`__
This is Part 2 of our Blog series about the Wasm Component Model, it's ecosytem and how to use Wasm Components with NGINX Unit.
8
8
In `Part 1 </news/2024/wasm-component-model-part-1>`__ we have covered all the conceptional parts. In this part, we will focus on the process of creating a Wasm Component.
Rust is the premier language for WebAssembly development and the most mature in terms of support. In the example, we will use Rust and its ecosystem to create a Wasm Component that can be hosted directly on NGINX Unit.
15
15
16
16
This tutorial targets Linux-based operating systems and macOS. If you are on Windows, we recommend using WSL2 (Windows Subsystem for Linux) to follow along. If you haven't already installed NGINX Unit alongside with the WebAssembly language module, please refer to the `docs <https://unit.nginx.org/installation/#official-packages>`__ on how to do it or use the official `Docker Image <https://unit.nginx.org/installation/#docker-images>`__ **unit:wasm**.
Let's start by installing the Rust ecosystem, if not already done. At the time of writing, Rust 1.76 is the latest stable version.
23
23
To install Rust, see the instructions on their `website <https://www.rust-lang.org/tools/install>`__.
@@ -31,19 +31,19 @@ After the installation completes, you can confirm the current version of Rust by
31
31
32
32
To work with Wasm Components, we need some additional tooling. This is a one-time setup for you to be able to write Rust source code and compile it to a Wasm Component.
Our experience with the official WASI Rust library was very interesting and exciting. The component build time was fascinating, and the library has a low dependency footprint. However, there are some costs in terms of developer experience. See for yourselves:
76
76
@@ -80,7 +80,7 @@ Start by creating a new Wasm Component using **cargo component**:
80
80
81
81
$ cargo component new --lib test-wasi-component
82
82
83
-
At the time of writing, the wasi crate (Version 0.12.1) available on `crates.io <https://crates.io/crates/wasi>`__ didn't include the latest version available on GitHub. As we are making use of a Macro in Rust, we will have to clone the repository <https://github.com/bytecodealliance/wasi>`__ and reference it from our new Wasm Component project.
83
+
At the time of writing, the wasi crate (Version 0.12.1) available on `crates.io <https://crates.io/crates/wasi>`__ didn't include the latest version available on GitHub. As we are making use of a Macro in Rust, we will have to clone the `repository <https://github.com/bytecodealliance/wasi>`__ and reference it from our new Wasm Component project.
84
84
85
85
Clone the bytecodealliances wasi repository
86
86
@@ -157,7 +157,7 @@ The actual code from **src/lib.rs** should look like this:
157
157
}
158
158
}
159
159
160
-
Targeting the wasi crate requires some low-level Rust work by us. Not bad at all, but something to consider when choosing this option. For the **wasi:http/proxy** world there is an interface description available on `Github<https://github.com/WebAssembly/wasi-http/blob/main/proxy.md>`__ which will help to write your code.
160
+
Targeting the wasi crate requires some low-level Rust work by us. Not bad at all, but something to consider when choosing this option. For the **wasi:http/proxy** world there is an interface description available on `GitHub<https://github.com/WebAssembly/wasi-http/blob/main/proxy.md>`__ which will help to write your code.
161
161
162
162
Let's build the component. Run the following command from the **test-wasi-component** directory:
163
163
@@ -232,7 +232,7 @@ Apply the configuration using **unitc**:
232
232
233
233
.. code-block:: bash
234
234
235
-
unitc config.json /config
235
+
$ unitc config.json /config
236
236
237
237
Sending a request to the exposed endpoint will create the same output from a different runtime implementation:
0 commit comments