Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/contribute/source/os/android/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ git clone https://github.com/second-state/wasm-learning.git
cd wasm-learning/rust/birds_v1
```

Use the `cargo` command to build a WASM bytecode file from the Rust source code. The WASM file is located at `target/wasm32-wasi/release/birds_v1.wasm`.
Use the `cargo` command to build a WASM bytecode file from the Rust source code. The WASM file is located at `target/wasm32-wasip1/release/birds_v1.wasm`.

```bash
rustup target add wasm32-wasi
cargo build --release --target=wasm32-wasi
rustup target add wasm32-wasip1
cargo build --release --target=wasm32-wasip1
```

Push the WASM bytecode file, tensorflow lite model file, and the test bird picture file onto the Android device using `adb`.

```bash
adb push target/wasm32-wasi/release/birds_v1.wasm /data/local/tmp/WasmEdge-tensorflow-tools
adb push target/wasm32-wasip1/release/birds_v1.wasm /data/local/tmp/WasmEdge-tensorflow-tools
adb push lite-model_aiy_vision_classifier_birds_V1_3.tflite /data/local/tmp/WasmEdge-tensorflow-tools
adb push bird.jpg /data/local/tmp/WasmEdge-tensorflow-tools
```
Expand Down
4 changes: 2 additions & 2 deletions docs/develop/c/simd.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ sidebar_position: 4

[128-bit packed Single Instruction Multiple Data (SIMD)](https://webassembly.github.io/simd/core/syntax/instructions.html#simd-instructions) instructions provide simultaneous computations over packed data in just one instruction. It's commonly used to improve performance for multimedia applications. With the SIMD proposal, the modules can benefit from using these commonly used instructions in modern hardware to gain more speedup.

If you are interested in enabling the SIMD proposal will improve how much performance of the applications, please refer to our [wasm32-wasi benchmark](https://github.com/second-state/wasm32-wasi-benchmark) for more information. The Mandelbrot Set application can have a **2.65x** speedup in our benchmark.
If you are interested in enabling the SIMD proposal will improve how much performance of the applications, please refer to our [wasm32-wasip1 benchmark](https://github.com/second-state/wasm32-wasi-benchmark) for more information. The Mandelbrot Set application can have a **2.65x** speedup in our benchmark.

We modified the Mandelbrot Set example from our [wasm32-wasi benchmark project](https://github.com/second-state/wasm32-wasi-benchmark/blob/master/src/mandelbrot.c). We will use this as an example in this article.
We modified the Mandelbrot Set example from our [wasm32-wasip1 benchmark project](https://github.com/second-state/wasm32-wasi-benchmark/blob/master/src/mandelbrot.c). We will use this as an example in this article.

## Prerequisites

Expand Down
4 changes: 2 additions & 2 deletions docs/develop/javascript/hello_world.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ git clone https://github.com/second-state/wasmedge-quickjs
cd wasmedge-quickjs

# Build the QuickJS JavaScript interpreter
cargo build --target wasm32-wasi --release
cargo build --target wasm32-wasip1 --release
```

The WebAssembly-based JavaScript interpreter program is located in the build `target` directory.

WasmEdge provides a `wasmedgec` utility to compile and add a native machine code section to the `wasm` file. You can use `wasmedge` to run the natively instrumented `wasm` file to get a much faster performance.

```bash
wasmedge compile target/wasm32-wasi/release/wasmedge_quickjs.wasm wasmedge_quickjs.wasm
wasmedge compile target/wasm32-wasip1/release/wasmedge_quickjs.wasm wasmedge_quickjs.wasm
wasmedge --dir .:. wasmedge_quickjs.wasm example_js/hello.js
```

Expand Down
8 changes: 4 additions & 4 deletions docs/develop/javascript/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ The examples are in the `examples/embed_js` folder in the `wasmedge-quickjs` rep

```bash
cd examples/embed_js
cargo build --target wasm32-wasi --release
wasmedge --dir .:. target/wasm32-wasi/release/embed_js.wasm
cargo build --target wasm32-wasip1 --release
wasmedge --dir .:. target/wasm32-wasip1/release/embed_js.wasm
```

## Code explanation: embed JavaScript into a Rust program
Expand Down Expand Up @@ -191,8 +191,8 @@ The project is in the [examples/embed_rust_module](https://github.com/second-sta

```bash
cd examples/embed_rust_module
cargo build --target wasm32-wasi --release
wasmedge --dir .:. target/wasm32-wasi/release/embed_rust_module.wasm
cargo build --target wasm32-wasip1 --release
wasmedge --dir .:. target/wasm32-wasip1/release/embed_rust_module.wasm
```

### Code explanation
Expand Down
4 changes: 2 additions & 2 deletions docs/develop/javascript/tensorflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ git clone https://github.com/second-state/wasmedge-quickjs
cd wasmedge-quickjs

# Build the QuickJS JavaScript interpreter with WASI NN
cargo build --target wasm32-wasi --release --features=wasi_nn
cargo build --target wasm32-wasip1 --release --features=wasi_nn
```

The WebAssembly-based JavaScript interpreter program is located in the build `target` directory.

WasmEdge provides a `wasmedge compile` utility to compile and add a native machine code section to the wasm file. You can use wasmedge to run the natively instrumented wasm file to get much faster performance.

```bash
wasmedge compile target/wasm32-wasi/release/wasmedge_quickjs.wasm wasmedge_quickjs_nn.wasm
wasmedge compile target/wasm32-wasip1/release/wasmedge_quickjs.wasm wasmedge_quickjs_nn.wasm
```
14 changes: 7 additions & 7 deletions docs/develop/python/hello_world.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,34 @@ Several different language implementations of the Python runtime exist, and some

## Compile RustPython

To compile RustPython, you should install the Rust toolchain on your machine. And `wasm32-wasi` platform support should be enabled.
To compile RustPython, you should install the Rust toolchain on your machine. And `wasm32-wasip1` platform support should be enabled.

```bash
rustup target add wasm32-wasi
rustup target add wasm32-wasip1
```

Then you could use the following command to clone and compile RustPython:

```bash
git clone https://github.com/RustPython/RustPython.git
cd RustPython
cargo build --release --target wasm32-wasi --features="freeze-stdlib"
cargo build --release --target wasm32-wasip1 --features="freeze-stdlib"
```

`freeze-stdlib` feature is enabled for including Python standard library inside the binary file. The output file should be at `target/wasm32-wasi/release/rustpython.wasm`.
`freeze-stdlib` feature is enabled for including Python standard library inside the binary file. The output file should be at `target/wasm32-wasip1/release/rustpython.wasm`.

## AOT Compile

WasmEdge supports compiling WebAssembly bytecode programs into native machine code for better performance. It is highly recommended to compile the RustPython to native machine code before running.

```bash
wasmedge compile ./target/wasm32-wasi/release/rustpython.wasm ./target/wasm32-wasi/release/rustpython.wasm
wasmedge compile ./target/wasm32-wasip1/release/rustpython.wasm ./target/wasm32-wasip1/release/rustpython.wasm
```

## Run

```bash
wasmedge ./target/wasm32-wasi/release/rustpython.wasm
wasmedge ./target/wasm32-wasip1/release/rustpython.wasm
```

Then you could get a Python shell in WebAssembly!
Expand All @@ -45,5 +45,5 @@ Then you could get a Python shell in WebAssembly!
You can pre-open directories to let WASI programs have permission to read and write files stored on the real machine. The following command mounted the current working directory to the WASI virtual file system.

```bash
wasmedge --dir .:. ./target/wasm32-wasi/release/rustpython.wasm
wasmedge --dir .:. ./target/wasm32-wasip1/release/rustpython.wasm
```
12 changes: 6 additions & 6 deletions docs/develop/rust/dapr.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ Build.

```bash
cd image-api-grayscale
cargo build --target wasm32-wasi --release
wasmedgec ./target/wasm32-wasi/release/image-api-grayscale.wasm image-api-grayscale.wasm
cargo build --target wasm32-wasip1 --release
wasmedgec ./target/wasm32-wasip1/release/image-api-grayscale.wasm image-api-grayscale.wasm
```

Deploy.
Expand All @@ -81,8 +81,8 @@ Build.

```bash
cd image-api-classify
cargo build --target wasm32-wasi --release
wasmedgec target/wasm32-wasi/release/wasmedge_hyper_server_tflite.wasm wasmedge_hyper_server_tflite.wasm
cargo build --target wasm32-wasip1 --release
wasmedgec target/wasm32-wasip1/release/wasmedge_hyper_server_tflite.wasm wasmedge_hyper_server_tflite.wasm
```

Deploy.
Expand All @@ -103,8 +103,8 @@ Build.

```bash
cd events-service
cargo build --target wasm32-wasi --release
wasmedgec target/wasm32-wasi/release/events_service.wasm events_service.wasm
cargo build --target wasm32-wasip1 --release
wasmedgec target/wasm32-wasip1/release/events_service.wasm events_service.wasm
```

Deploy.
Expand Down
4 changes: 2 additions & 2 deletions docs/develop/rust/database/my_sql_driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ git clone https://github.com/WasmEdge/wasmedge-db-examples
cd wasmedge-db-examples/mysql_async

# Compile the rust code into WASM
RUSTFLAGS="--cfg wasmedge --cfg tokio_unstable" cargo build --target wasm32-wasi --release
RUSTFLAGS="--cfg wasmedge --cfg tokio_unstable" cargo build --target wasm32-wasip1 --release

# Execute MySQL statements against a MySQL database at mysql://user:passwd@127.0.0.1:3306
wasmedge --env "DATABASE_URL=mysql://user:passwd@127.0.0.1:3306/mysql" target/wasm32-wasi/release/crud.wasm
wasmedge --env "DATABASE_URL=mysql://user:passwd@127.0.0.1:3306/mysql" target/wasm32-wasip1/release/crud.wasm
```

<!-- prettier-ignore -->
Expand Down
4 changes: 2 additions & 2 deletions docs/develop/rust/database/postgres_driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ git clone https://github.com/WasmEdge/wasmedge-db-examples
cd wasmedge-db-examples/postgres

# Compile the rust code into WASM
RUSTFLAGS="--cfg wasmedge --cfg tokio_unstable" cargo build --target wasm32-wasi --release
RUSTFLAGS="--cfg wasmedge --cfg tokio_unstable" cargo build --target wasm32-wasip1 --release

# Execute SQL statements against a PostgreSQL database at postgres://user:passwd@localhost/testdb
wasmedge --env "DATABASE_URL=postgres://user:passwd@localhost/testdb" target/wasm32-wasi/release/crud.wasm
wasmedge --env "DATABASE_URL=postgres://user:passwd@localhost/testdb" target/wasm32-wasip1/release/crud.wasm
```

## Configuration
Expand Down
4 changes: 2 additions & 2 deletions docs/develop/rust/database/qdrant_driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ git clone https://github.com/WasmEdge/wasmedge-db-examples
cd wasmedge-db-examples/qdrant

# Compile the rust code into WASM
RUSTFLAGS="--cfg wasmedge --cfg tokio_unstable" cargo build --target wasm32-wasi --release
RUSTFLAGS="--cfg wasmedge --cfg tokio_unstable" cargo build --target wasm32-wasip1 --release

# Perform vector data operations against a Qdrant at http://localhost:6333
wasmedge target/wasm32-wasi/release/qdrant_examples.wasm
wasmedge target/wasm32-wasip1/release/qdrant_examples.wasm
```

## Configuration
Expand Down
4 changes: 2 additions & 2 deletions docs/develop/rust/database/redis_driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ git clone https://github.com/WasmEdge/wasmedge-db-examples
cd wasmedge-db-examples/redis

# Compile the rust code into WASM
RUSTFLAGS="--cfg wasmedge --cfg tokio_unstable" cargo build --target wasm32-wasi --release
RUSTFLAGS="--cfg wasmedge --cfg tokio_unstable" cargo build --target wasm32-wasip1 --release

# Execute Redis command against a Redis instance at redis://localhost/
wasmedge --env "REDIS_URL=redis://localhost/" target/wasm32-wasi/release/wasmedge-redis-client-examples.wasm
wasmedge --env "REDIS_URL=redis://localhost/" target/wasm32-wasip1/release/wasmedge-redis-client-examples.wasm
```

## Configuration
Expand Down
8 changes: 4 additions & 4 deletions docs/develop/rust/hello_world.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ fn main() {
Build the WASM bytecode:

```bash
cargo build --target wasm32-wasi --release
cargo build --target wasm32-wasip1 --release
```

We will use the `wasmedge` command to run the program.

```bash
wasmedge target/wasm32-wasi/release/hello.wasm
wasmedge target/wasm32-wasip1/release/hello.wasm
```

## A simple function
Expand All @@ -47,15 +47,15 @@ pub fn add(a: i32, b: i32) -> i32 {
### Build the WASM bytecode

```bash
cargo build --target wasm32-wasi --release
cargo build --target wasm32-wasip1 --release
```

### Run the application from command line

We will use `wasmedge` in reactor mode to run the program. We pass the function name and its input parameters as command line arguments.

```bash
wasmedge --reactor target/wasm32-wasi/release/add.wasm add 2 2
wasmedge --reactor target/wasm32-wasip1/release/add.wasm add 2 2
```

## Pass parameters with complex data types
Expand Down
14 changes: 7 additions & 7 deletions docs/develop/rust/http_service/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ git clone https://github.com/WasmEdge/wasmedge_reqwest_demo
cd wasmedge_reqwest_demo

# Build the Rust code
RUSTFLAGS="--cfg wasmedge --cfg tokio_unstable" cargo build --target wasm32-wasi --release
RUSTFLAGS="--cfg wasmedge --cfg tokio_unstable" cargo build --target wasm32-wasip1 --release
# Use the AoT compiler to get better performance
wasmedge compile target/wasm32-wasi/release/http.wasm http.wasm
wasmedge compile target/wasm32-wasi/release/https.wasm https.wasm
wasmedge compile target/wasm32-wasip1/release/http.wasm http.wasm
wasmedge compile target/wasm32-wasip1/release/https.wasm https.wasm

# Run the HTTP GET and POST examples
wasmedge http.wasm
Expand Down Expand Up @@ -102,9 +102,9 @@ git clone https://github.com/WasmEdge/wasmedge_hyper_demo
cd wasmedge_hyper_demo/client

# Build the Rust code
RUSTFLAGS="--cfg wasmedge --cfg tokio_unstable" cargo build --target wasm32-wasi --release
RUSTFLAGS="--cfg wasmedge --cfg tokio_unstable" cargo build --target wasm32-wasip1 --release
# Use the AoT compiler to get better performance
wasmedge compile target/wasm32-wasi/release/wasmedge_hyper_client.wasm wasmedge_hyper_client.wasm
wasmedge compile target/wasm32-wasip1/release/wasmedge_hyper_client.wasm wasmedge_hyper_client.wasm

# Run the example
wasmedge wasmedge_hyper_client.wasm
Expand All @@ -130,8 +130,8 @@ The HTTPS version of the demo is as follows.
```bash
// Build
cd wasmedge_hyper_demo/client-https
RUSTFLAGS="--cfg wasmedge --cfg tokio_unstable" cargo build --target wasm32-wasi --release
wasmedge compile target/wasm32-wasi/release/wasmedge_hyper_client_https.wasm wasmedge_hyper_client_https.wasm
RUSTFLAGS="--cfg wasmedge --cfg tokio_unstable" cargo build --target wasm32-wasip1 --release
wasmedge compile target/wasm32-wasip1/release/wasmedge_hyper_client_https.wasm wasmedge_hyper_client_https.wasm

// Run
wasmedge wasmedge_hyper_client_https.wasm
Expand Down
8 changes: 4 additions & 4 deletions docs/develop/rust/http_service/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ git clone https://github.com/WasmEdge/wasmedge_hyper_demo
cd wasmedge_hyper_demo/server-axum

# Build the Rust code
RUSTFLAGS="--cfg wasmedge --cfg tokio_unstable" cargo build --target wasm32-wasi --release
RUSTFLAGS="--cfg wasmedge --cfg tokio_unstable" cargo build --target wasm32-wasip1 --release
# Use the AoT compiler for better performance
wasmedge compile target/wasm32-wasi/release/wasmedge_axum_server.wasm wasmedge_axum_server.wasm
wasmedge compile target/wasm32-wasip1/release/wasmedge_axum_server.wasm wasmedge_axum_server.wasm

# Run the example
wasmedge wasmedge_axum_server.wasm
Expand Down Expand Up @@ -103,9 +103,9 @@ git clone https://github.com/WasmEdge/wasmedge_hyper_demo
cd wasmedge_hyper_demo/server

# Build the Rust code
RUSTFLAGS="--cfg wasmedge --cfg tokio_unstable" cargo build --target wasm32-wasi --release
RUSTFLAGS="--cfg wasmedge --cfg tokio_unstable" cargo build --target wasm32-wasip1 --release
# Use the AoT compiler to get better performance
wasmedge compile target/wasm32-wasi/release/wasmedge_hyper_server.wasm wasmedge_hyper_server.wasm
wasmedge compile target/wasm32-wasip1/release/wasmedge_hyper_server.wasm wasmedge_hyper_server.wasm

# Run the example
wasmedge wasmedge_hyper_server.wasm
Expand Down
8 changes: 4 additions & 4 deletions docs/develop/rust/os.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sidebar_position: 3

# Access OS services

The WASI (WebAssembly Systems Interface) standard is designed to allow WebAssembly applications to access operating system services. The `wasm32-wasi` target in the Rust compiler supports WASI. This section will use [an example project](https://github.com/second-state/rust-examples/tree/main/wasi) to show how to use Rust standard APIs to access operating system services.
The WASI (WebAssembly Systems Interface) standard is designed to allow WebAssembly applications to access operating system services. The `wasm32-wasip1` target in the Rust compiler supports WASI. This section will use [an example project](https://github.com/second-state/rust-examples/tree/main/wasi) to show how to use Rust standard APIs to access operating system services.

<!-- prettier-ignore -->
:::note
Expand All @@ -13,7 +13,7 @@ Before we start, ensure [you have Rust and WasmEdge installed](setup.md).

## Random numbers

The WebAssembly VM is a pure software construct. It does not have a hardware entropy source for random numbers. That's why WASI defines a function for WebAssembly programs to call its host operating system to get a random seed. As a Rust developer, you only need to use the popular (de facto standard) `rand` and/or `getrandom` crates. With the `wasm32-wasi` compiler backend, these crates generate the correct WASI calls in the WebAssembly bytecode. The `Cargo.toml` dependencies are as follows.
The WebAssembly VM is a pure software construct. It does not have a hardware entropy source for random numbers. That's why WASI defines a function for WebAssembly programs to call its host operating system to get a random seed. As a Rust developer, you only need to use the popular (de facto standard) `rand` and/or `getrandom` crates. With the `wasm32-wasip1` compiler backend, these crates generate the correct WASI calls in the WebAssembly bytecode. The `Cargo.toml` dependencies are as follows.

```toml
[dependencies]
Expand Down Expand Up @@ -117,13 +117,13 @@ fn main() {
Use the command below to compile [the Rust project](https://github.com/second-state/rust-examples/blob/main/wasi/).

```bash
cargo build --target wasm32-wasi --release
cargo build --target wasm32-wasip1 --release
```

To run it in `wasmedge`, do the following. The `--dir` option maps the current directory of the command shell to the file system's current directory inside the WebAssembly app.

```bash
$ wasmedge --dir .:. target/wasm32-wasi/release/wasi.wasm
$ wasmedge --dir .:. target/wasm32-wasip1/release/wasi.wasm
Random number: -1157533356
Random bytes: [159, 159, 9, 119, 106, 172, 207, 82, 173, 145, 233, 214, 104, 35, 23, 53, 155, 12, 102, 231, 117, 67, 192, 215, 207, 202, 128, 198, 213, 41, 235, 57, 89, 223, 138, 70, 185, 137, 74, 162, 42, 20, 226, 177, 114, 170, 172, 39, 149, 99, 122, 68, 115, 205, 155, 202, 4, 48, 178, 224, 124, 42, 24, 56, 215, 90, 203, 150, 106, 128, 127, 201, 177, 187, 20, 195, 172, 56, 72, 28, 53, 163, 59, 36, 129, 160, 69, 203, 196, 72, 113, 61, 46, 249, 81, 134, 94, 134, 159, 51, 233, 247, 253, 116, 202, 210, 100, 75, 74, 95, 197, 44, 81, 87, 89, 115, 20, 226, 143, 139, 50, 60, 196, 59, 206, 105, 161, 226]
Printed from wasi: This is from a main function
Expand Down
10 changes: 5 additions & 5 deletions docs/develop/rust/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

## Set up the Rust compiler's target

To build a WASM file running in server-side WebAssembly like WasmEdge, we need to add the `wasm32-wasi` target for the Rust compiler after Rust is installed.
To build a WASM file running in server-side WebAssembly like WasmEdge, we need to add the `wasm32-wasip1` target for the Rust compiler after Rust is installed.

```bash
rustup target add wasm32-wasi
rustup target add wasm32-wasip1
```

## Special notes for networking apps
Expand All @@ -40,21 +40,21 @@ WasmEdge supports async networking APIs provided by [Tokio](https://tokio.rs/) a
need to add a few config flags to help the Rust compiler choose the correct feature branches in the library source code. Here is an example of `cargo build` command for compiling a tokio app to Wasm.

```bash
RUSTFLAGS="--cfg wasmedge --cfg tokio_unstable" cargo build --target wasm32-wasi --release
RUSTFLAGS="--cfg wasmedge --cfg tokio_unstable" cargo build --target wasm32-wasip1 --release
```

Alternatively, you could add these lines to the `.cargo/config.toml` file.

```toml
[build]
target = "wasm32-wasi"
target = "wasm32-wasip1"
rustflags = ["--cfg", "wasmedge", "--cfg", "tokio_unstable"]
```

Once you have these lines in `.cargo/config.toml`, you can simply use the regular `cargo` command.

```bash
cargo build --target wasm32-wasi --release
cargo build --target wasm32-wasip1 --release
```

### TLS on MacOS
Expand Down
Loading
Loading