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
{{ message }}
This repository was archived by the owner on Oct 8, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: source/news/2024/wasm-component-model-part-1.rst
+3-7Lines changed: 3 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,10 +57,7 @@ The WIT files used by the Wasm Component Model and the **wasi:http/proxy** world
57
57
One of the interesting facts about WIT-files is the versioning system. As the host implementing the Wasm runtime as well as the component we are about to build are creating bindings for the contracts defined by the WIT files, it is important to target the same version of those contracts or choose a runtime that supports multiple versions of those WIT files. But this is worth another blog post. For now, we should focus on the latest stable release, which it was published in February 2024 and is labeled as WASI 0.2.
58
58
This release included **wasi:cli** and the **wasi:http** worlds.
59
59
60
-
In the Wasm ecosystem these contracts are called worlds. So, we will do from now on. For the use cases of NGINX Unit it was pretty
61
-
clear we will targeting the **wasi/http:proxy** world. You can think of the **wasi:http/proxy** world as the set of interfaces describing
62
-
how a HTTP request and response will look like including all its data (HTTP Method, Headers, Body, etc.). If you are an old school web
63
-
developer, this might remind you of CGI.
60
+
In the WebAssembly ecosystem, these contracts are referred to as "worlds." Therefore, we will use that term from now on. For the use cases of NGINX Unit, it was pretty clear we will be targeting the **wasi:http/proxy** world. You can think of the **wasi:http/proxy** world as the set of interfaces describing how a HTTP request and response will look like, including all its data (HTTP Method, Headers, Body, and more). If you are an old-school web developer, this might remind you of CGI.
NGINX Unit, Wasmtime and Rust - A runtime implementation
@@ -71,10 +68,9 @@ After a brief investigation, we discovered that the WASI/WIT pair we'd already h
71
68
As mentioned at the beginning of this article, any challenge, regardless of its complexity, can be solved when the right people and community share the same mindset.
72
69
Fermyon has been, and continues to be, a valuable and significant partner for us. After a late-night Slack and Zoom Session, we found it too complex to add native support for the Component Model to the Wasmtime C-API. Additionally, implementing the interfaces manually with WIT files without help from automation tools like **bindgen** would result in a significant amount of ongoing upkeep work.
73
70
74
-
While explaining how the internals of NGINX Unit and the current C-based Language Module work to Fermyon they shared a prototype of a
75
-
Rust based Unit Language Module targeting the Rust-API of Wasmtime. Not the C-API anymore.
71
+
While explaining how the internals of NGINX Unit and the current C-based Language Module work to Fermyon, they shared a prototype of a Rust-based Unit Language Module targeting the Rust API of Wasmtime. Not the C-API anymore.
76
72
77
-
This was the moment we added Rust to the core of NGINX Unit. With all this knowledge we are now ready to write some code.
73
+
Now we are equipped with the necessary knowledge to write some code.
Copy file name to clipboardExpand all lines: source/news/2024/wasm-component-model-part-2.rst
+3-6Lines changed: 3 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,8 +29,7 @@ After the installation completes, you can confirm the current version of Rust by
29
29
$ rustc -V
30
30
rustc 1.76.0 (07dca489a 2024-02-04)
31
31
32
-
To work with Wasm Components, we need some additional tooling. This is a one-time setup for your machine to be able to write Rust source
33
-
code and compile it to a WebAssembly Component.
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:
77
76
78
-
Start by creating a new Wasm Component using cargo component:
77
+
Start by creating a new Wasm Component using **cargo component**:
79
78
80
79
.. code-block:: bash
81
80
@@ -158,9 +157,7 @@ The actual code from **src/lib.rs** should look like this:
158
157
}
159
158
}
160
159
161
-
As you can see, targeting the wasi crate requires some low-level Rust work by us. Not bad at all but something to consider when choosing this
162
-
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>`__
163
-
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.
164
161
165
162
Let's build the component. Run the following command from the **test-wasi-component** directory:
0 commit comments