Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the new rust compiler target for wasm #262

Closed
wants to merge 2 commits into from
Closed
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/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
```
10 changes: 5 additions & 5 deletions docs/develop/python/hello_world.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ 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:[email protected]:3306
wasmedge --env "DATABASE_URL=mysql://user:[email protected]:3306/mysql" target/wasm32-wasi/release/crud.wasm
wasmedge --env "DATABASE_URL=mysql://user:[email protected]: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
4 changes: 2 additions & 2 deletions docs/develop/rust/os.md
Original file line number Diff line number Diff line change
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
4 changes: 2 additions & 2 deletions docs/develop/rust/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ 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.
Expand All @@ -54,7 +54,7 @@ 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
8 changes: 4 additions & 4 deletions docs/develop/rust/socket_networking/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ git clone https://github.com/second-state/wasmedge_wasi_socket.git
cd wasmedge_wasi_socket/http_client/

# Build the Rust Code
cargo build --target wasm32-wasi --release
cargo build --target wasm32-wasip1 --release
# Use the AoT compiler to get better performance
wasmedge compile target/wasm32-wasi/release/http_client.wasm http_client.wasm
wasmedge compile target/wasm32-wasip1/release/http_client.wasm http_client.wasm

# Run the example
wasmedge http_client.wasm
Expand Down Expand Up @@ -69,9 +69,9 @@ git clone https://github.com/second-state/wasmedge_wasi_socket
cd wasmedge_wasi_socket/nonblock_http_client/

# Build the Rust Code
cargo build --target wasm32-wasi --release
cargo build --target wasm32-wasip1 --release
# Use the AoT compiler for better performance
wasmedge compile target/wasm32-wasi/release/nonblock_http_client.wasm nonblock_http_client.wasm
wasmedge compile target/wasm32-wasip1/release/nonblock_http_client.wasm nonblock_http_client.wasm

# Run the example
wasmedge nonblock_http_client.wasm
Expand Down
8 changes: 4 additions & 4 deletions docs/develop/rust/socket_networking/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ git clone https://github.com/second-state/wasmedge_wasi_socket
cd wasmedge_wasi_socket/http_server

# Build the Rust code
cargo build --target wasm32-wasi --release
cargo build --target wasm32-wasip1 --release
# Use the AoT compiler for better performance
wasmedge compile target/wasm32-wasi/release/http_server.wasm http_server.wasm
wasmedge compile target/wasm32-wasip1/release/http_server.wasm http_server.wasm

# Run the example
$wasmedge http_server.wasm
Expand Down Expand Up @@ -117,9 +117,9 @@ git clone https://github.com/second-state/wasmedge_wasi_socket
cd wasmedge_wasi_socket

# Build the Rust code
cargo build --target wasm32-wasi --release
cargo build --target wasm32-wasip1 --release
# Use the AoT compiler for better performance
wasmedge compile target/wasm32-wasi/release/poll_tcp_listener.wasm poll_tcp_listener.wasm
wasmedge compile target/wasm32-wasip1/release/poll_tcp_listener.wasm poll_tcp_listener.wasm

# Run the example
wasmedge poll_tcp_listener.wasm
Expand Down
4 changes: 2 additions & 2 deletions docs/develop/rust/ssr.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ Next, build and run the server.

```bash
cd ../server-wasmedge
cargo build --target wasm32-wasi
OUTPUT_CSS="$(pwd)/../client/build/app.css" wasmedge --dir /static:../client/build ../../../target/wasm32-wasi/debug/isomorphic-server-wasmedge.wasm
cargo build --target wasm32-wasip1
OUTPUT_CSS="$(pwd)/../client/build/app.css" wasmedge --dir /static:../client/build ../../../target/wasm32-wasip1/debug/isomorphic-server-wasmedge.wasm
```

Navigate to `http://127.0.0.1:3000`, and you will see the web application in action.
Expand Down
4 changes: 2 additions & 2 deletions docs/develop/rust/wasinn/llm_inference.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ cd chat
Second, use `cargo` to build the example project.

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

The output WASM file is `target/wasm32-wasi/release/llama-chat.wasm`. Next, use WasmEdge to load the llama-3.1-8b model and then ask the model questions.
The output WASM file is `target/wasm32-wasip1/release/llama-chat.wasm`. Next, use WasmEdge to load the llama-3.1-8b model and then ask the model questions.

```bash
wasmedge --dir .:. --nn-preload default:GGML:AUTO:Meta-Llama-3.1-8B-Instruct-Q5_K_M.gguf llama-chat.wasm -p llama-3-chat
Expand Down
Loading
Loading