-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add component examples built from example core modules
Also, specify how to reproduce the wasi-component-adapter binaries.
- Loading branch information
Showing
17 changed files
with
613 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,8 @@ jobs: | |
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | ||
- name: Install Wasm32-wasi target | ||
run: rustup target add wasm32-wasi | ||
- name: Install wasm-tools | ||
run: cargo install --locked [email protected] | ||
- name: Build Rust examples | ||
working-directory: ./examples | ||
run: make all | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,32 @@ | ||
.PHONY: all rust-* pdf-create | ||
SUBDIRS = rust-basic rust-fetch rust-kv rust-wasi-nn rust-wasi-nn-preload rust-pdf-create | ||
COMPONENTS = $(addprefix components/, $(SUBDIRS)) | ||
COMPONENT_TARGETS = components/rust-basic components/rust-kv components/rust-params | ||
|
||
rust-basic: | ||
cd rust-basic && \ | ||
cargo build --target wasm32-wasi --release && \ | ||
cp target/wasm32-wasi/release/rust-basic.wasm ./basic.wasm | ||
all: $(SUBDIRS) rust-params $(COMPONENT_CURRENT_SUPPORTED_TARGETS) components/rust-params | ||
|
||
rust-fetch: | ||
cd rust-fetch && \ | ||
cargo build --target wasm32-wasi --release && \ | ||
cp target/wasm32-wasi/release/rust-fetch.wasm ./index.wasm | ||
.PHONY: $(SUBDIRS) rust-params $(COMPONENT_CURRENT_SUPPORTED_TARGETS) components/rust-params | ||
|
||
rust-kv: | ||
cd rust-kv && \ | ||
cargo build --target wasm32-wasi --release && \ | ||
mv target/wasm32-wasi/release/rust-kv.wasm ./kv.wasm | ||
$(SUBDIRS): | ||
cd $@ && \ | ||
cargo build --target wasm32-wasi --release && \ | ||
cp target/wasm32-wasi/release/$@.wasm ./$@.wasm | ||
|
||
rust-params: | ||
cd rust-params && \ | ||
cargo build --target wasm32-wasi --release && \ | ||
mv target/wasm32-wasi/release/rust-params.wasm "./[id].wasm" | ||
|
||
rust-wasi-nn: | ||
cd rust-wasi-nn && \ | ||
cargo build --target wasm32-wasi --release && \ | ||
mv target/wasm32-wasi/release/rust-wasi-nn.wasm "./inference.wasm" | ||
|
||
rust-wasi-nn-preload: | ||
cd rust-wasi-nn-preload && \ | ||
cargo build --target wasm32-wasi --release && \ | ||
mv target/wasm32-wasi/release/rust-wasi-nn-preload.wasm "./inference.wasm" | ||
|
||
rust-pdf-create: | ||
cd rust-pdf-create && \ | ||
cargo build --target wasm32-wasi --release && \ | ||
mv target/wasm32-wasi/release/rust-pdf-create.wasm ./index.wasm | ||
|
||
all: rust-basic rust-fetch rust-kv rust-params rust-wasi-nn | ||
cd $@ && \ | ||
cargo build --target wasm32-wasi --release && \ | ||
cp target/wasm32-wasi/release/$@.wasm "./[id].wasm" | ||
|
||
$(COMPONENTS): | ||
mkdir -p $@ | ||
make $(@:components/%=%) | ||
cp $(@:components/%=%)/*.toml $@/ | ||
wasm-tools component new $(@:components/%=%)/$(@:components/%=%).wasm \ | ||
--adapt wasi_snapshot_preview1=components/wasi-component-adapter/wasi_snapshot_preview1-command.wasm \ | ||
-o $@/$(@:components/%=%).wasm | ||
|
||
components/rust-params: | ||
mkdir -p $@ | ||
make rust-params | ||
wasm-tools component new rust-params/[id].wasm \ | ||
--adapt wasi_snapshot_preview1=components/wasi-component-adapter/wasi_snapshot_preview1-command.wasm \ | ||
-o $@/[id].wasm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/rust-* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Component model examples | ||
|
||
This directory contains core module examples found in the parent | ||
directory, adapted with the | ||
[`wasi-component-adapter`](./wasi-component-adapter/README.md) so that they are | ||
converted to WebAssembly components. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# WASI component adapter | ||
|
||
The Bytecode Alliance provides a WASI component adapter that allows a | ||
WASI WebAssembly module to be compiled to a WebAssembly component. | ||
|
||
You can reproduce this WASI component adapter by running: | ||
|
||
```shell-session | ||
$ git clone [email protected]:bytecodealliance/wasmtime.git | ||
$ cd wasmtime | ||
$ cargo build -p wasi-preview1-component-adapter \ | ||
--target wasm32-unknown-unknown --release | ||
``` | ||
|
||
You can find the WASI component adapter at | ||
`target/wasm32-unknown-unknown/release/wasi_snapshot_preview1.wasm`. | ||
|
||
This adapter is valid for a WASI reactor. If you want to build an | ||
adapter for a WASI command, you can run: | ||
|
||
```shell-session | ||
$ git clone [email protected]:bytecodealliance/wasmtime.git | ||
$ cd wasmtime | ||
$ cargo build -p wasi-preview1-component-adapter \ | ||
--features command \ | ||
--no-default-features \ | ||
--target wasm32-unknown-unknown --release | ||
``` | ||
|
||
## Converting a WebAssembly module to a WebAssembly component | ||
|
||
In order to convert a WebAssemby module to a WebAssembly component, | ||
you can achieve this goal by using `wasm-tools`, along with the WASI | ||
component adapter you have just built. | ||
|
||
You can link to the reactor WASI adapter like so: | ||
|
||
```shell-session | ||
$ wasm-tools component new my-wasm-module.wasm \ | ||
--adapt wasi_snapshot_preview1=wasi_snapshot_preview1-reactor.wasm \ | ||
-o my-wasm-component.wasm | ||
``` | ||
|
||
Or you can link to the command WASI adapter like the following: | ||
|
||
```shell-session | ||
$ wasm-tools component new my-wasm-module.wasm \ | ||
--adapt wasi_snapshot_preview1=wasi_snapshot_preview1-command.wasm \ | ||
-o my-wasm-component.wasm | ||
``` | ||
|
||
In both cases, you can check that the component is valid, and output | ||
the WIT definition associated with it, like: | ||
|
||
```shell-session | ||
$ wasm-tools validate my-wasm-component.wasm --features component-model | ||
$ wasm-tools component wit component.wasm | ||
``` |
Binary file added
BIN
+2.21 MB
examples/components/wasi-component-adapter/wasi_snapshot_preview1-command.wasm
Binary file not shown.
Binary file added
BIN
+2.23 MB
examples/components/wasi-component-adapter/wasi_snapshot_preview1-reactor.wasm
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.