Skip to content

Commit

Permalink
Merge pull request #15 from second-state/dev
Browse files Browse the repository at this point in the history
Update to `wasmedge-sdk v0.14.0`
  • Loading branch information
L-jasmine authored Jul 23, 2024
2 parents f0d2f84 + 0a76a5c commit f54a726
Show file tree
Hide file tree
Showing 87 changed files with 594 additions and 1,282 deletions.
40 changes: 12 additions & 28 deletions .github/workflows/latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-22.04, ubuntu-20.04]
rust: [1.73, 1.72, 1.71]
rust: [1.78, 1.77, 1.76]
container:
image: wasmedge/wasmedge:ubuntu-build-clang

Expand Down Expand Up @@ -68,25 +68,25 @@ jobs:
working-directory: async-wasi
run: |
cargo build -p wasm-app --target wasm32-wasi --release
cargo run -p run-wasm-app -- ./target/wasm32-wasi/release/wasm-app.wasm
cargo run -p run-wasm-app -- ../target/wasm32-wasi/release/wasm-app.wasm
- name: async-wasi-socket
working-directory: async-wasi-socket-addr
run: |
cargo build -p socket-addr --target wasm32-wasi --release
cargo run -p main-app -- ./target/wasm32-wasi/release/socket-addr.wasm
cargo run -p main-app -- ../target/wasm32-wasi/release/socket-addr.wasm
- name: call-wasm-lib-from-host example
working-directory: call-wasm-lib-from-host
run: |
cargo build -p wasm-lib --target wasm32-wasi --release
cargo run -p call-wasm-lib -- ./target/wasm32-wasi/release/wasm_lib.wasm 5
cargo run -p call-wasm-lib -- ../target/wasm32-wasi/release/wasm_lib.wasm 5
- name: call-wasm-lib-with-external-deps
working-directory: call-wasm-lib-with-external-deps
run: |
cargo build -p wasm-lib --target wasm32-wasi --release
cargo run -p host-app -- ./target/wasm32-wasi/release/wasm_lib.wasm 2 3
cargo build -p call-host --target wasm32-wasi --release
cargo run -p host-app -- ../target/wasm32-wasi/release/call_host.wasm 2 3
- name: define-async-host-func
working-directory: define-async-host-func
Expand All @@ -98,24 +98,20 @@ jobs:
run: |
cargo run
- name: define-host-func-with-string-args
working-directory: define-host-func-with-string-args
run: |
cargo run
- name: load-module-in-module
working-directory: load-module-in-module
run: |
cargo build -p alice-wasm-lib --target wasm32-wasi --release
cargo build -p bob-wasm-lib --target wasm32-wasi --release
cargo run -p host-app -- 2 3
cargo run -p multi-module-host-app -- 2 3
- name: manipulate-linear-memory
working-directory: manipulate-linear-memory
run: |
cargo run
- name: multi-threaded-parallel
if: false
working-directory: multi-threaded-parallel
run: |
cd mandelbrot-c
Expand All @@ -136,8 +132,8 @@ jobs:
- name: run-wasm-app-from-host
working-directory: run-wasm-app-from-host
run: |
cargo build -p wasm-app --target wasm32-wasi --release
cargo run -p run-wasm-app -- ./target/wasm32-wasi/release/wasm-app.wasm
cargo build -p sync-wasm-app --target wasm32-wasi --release
cargo run -p sync-run-wasm-app -- ../target/wasm32-wasi/release/sync-wasm-app.wasm
- name: run-wasm-func-in-aot-mode
working-directory: run-wasm-func-in-aot-mode
Expand All @@ -153,22 +149,10 @@ jobs:
working-directory: set-env-vars-via-wasi
run: |
cargo build -p print-env-vars --target wasm32-wasi --release
cargo run -p set-env-vars-via-wasi -- ./target/wasm32-wasi/release/print_env_vars.wasm
- name: simple-plugin
working-directory: simple-plugin
run: |
cargo build -p naive-math-plugin --release
cp target/release/libnaive_math_plugin.so /usr/local/lib/wasmedge
cargo build -p naive-math-wasm --target wasm32-wasi --release
cargo run -p run-with-plugin
- name: table-and-funcref
working-directory: table-and-funcref
run: |
cargo run
cargo run -p set-env-vars-via-wasi -- ../target/wasm32-wasi/release/print_env_vars.wasm
- name: wasmedge-bindgen
if: false
working-directory: wasmedge-bindgen
run: |
cargo build -p wasm-lib --target wasm32-wasi --release
Expand Down
42 changes: 13 additions & 29 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-22.04, ubuntu-20.04]
rust: [1.73, 1.72, 1.71]
rust: [1.78, 1.77, 1.76]
container:
image: wasmedge/wasmedge:ubuntu-build-clang

Expand All @@ -47,7 +47,7 @@ jobs:
- name: Install WasmEdge with Wasi-NN PyTorch plugin
env:
CMAKE_BUILD_TYPE: "Release"
VERSION: "0.13.5"
VERSION: "0.14.0"
run: |
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$(pwd)/libtorch/lib
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -v $VERSION -p /usr/local --plugins wasi_nn-pytorch
Expand All @@ -63,25 +63,25 @@ jobs:
working-directory: async-wasi
run: |
cargo build -p wasm-app --target wasm32-wasi --release
cargo run -p run-wasm-app -- ./target/wasm32-wasi/release/wasm-app.wasm
cargo run -p run-wasm-app -- ../target/wasm32-wasi/release/wasm-app.wasm
- name: async-wasi-socket
working-directory: async-wasi-socket-addr
run: |
cargo build -p socket-addr --target wasm32-wasi --release
cargo run -p main-app -- ./target/wasm32-wasi/release/socket-addr.wasm
cargo run -p main-app -- ../target/wasm32-wasi/release/socket-addr.wasm
- name: call-wasm-lib-from-host example
working-directory: call-wasm-lib-from-host
run: |
cargo build -p wasm-lib --target wasm32-wasi --release
cargo run -p call-wasm-lib -- ./target/wasm32-wasi/release/wasm_lib.wasm 5
cargo run -p call-wasm-lib -- ../target/wasm32-wasi/release/wasm_lib.wasm 5
- name: call-wasm-lib-with-external-deps
working-directory: call-wasm-lib-with-external-deps
run: |
cargo build -p wasm-lib --target wasm32-wasi --release
cargo run -p host-app -- ./target/wasm32-wasi/release/wasm_lib.wasm 2 3
cargo build -p call-host --target wasm32-wasi --release
cargo run -p host-app -- ../target/wasm32-wasi/release/call_host.wasm 2 3
- name: define-async-host-func
working-directory: define-async-host-func
Expand All @@ -93,24 +93,20 @@ jobs:
run: |
cargo run
- name: define-host-func-with-string-args
working-directory: define-host-func-with-string-args
run: |
cargo run
- name: load-module-in-module
working-directory: load-module-in-module
run: |
cargo build -p alice-wasm-lib --target wasm32-wasi --release
cargo build -p bob-wasm-lib --target wasm32-wasi --release
cargo run -p host-app -- 2 3
cargo run -p multi-module-host-app -- 2 3
- name: manipulate-linear-memory
working-directory: manipulate-linear-memory
run: |
cargo run
- name: multi-threaded-parallel
if: false
working-directory: multi-threaded-parallel
run: |
cd mandelbrot-c
Expand All @@ -131,8 +127,8 @@ jobs:
- name: run-wasm-app-from-host
working-directory: run-wasm-app-from-host
run: |
cargo build -p wasm-app --target wasm32-wasi --release
cargo run -p run-wasm-app -- ./target/wasm32-wasi/release/wasm-app.wasm
cargo build -p sync-wasm-app --target wasm32-wasi --release
cargo run -p sync-run-wasm-app -- ../target/wasm32-wasi/release/sync-wasm-app.wasm
- name: run-wasm-func-in-aot-mode
working-directory: run-wasm-func-in-aot-mode
Expand All @@ -148,22 +144,10 @@ jobs:
working-directory: set-env-vars-via-wasi
run: |
cargo build -p print-env-vars --target wasm32-wasi --release
cargo run -p set-env-vars-via-wasi -- ./target/wasm32-wasi/release/print_env_vars.wasm
- name: simple-plugin
working-directory: simple-plugin
run: |
cargo build -p naive-math-plugin --release
cp target/release/libnaive_math_plugin.so /usr/local/lib/wasmedge
cargo build -p naive-math-wasm --target wasm32-wasi --release
cargo run -p run-with-plugin
- name: table-and-funcref
working-directory: table-and-funcref
run: |
cargo run
cargo run -p set-env-vars-via-wasi -- ../target/wasm32-wasi/release/print_env_vars.wasm
- name: wasmedge-bindgen
if: false
working-directory: wasmedge-bindgen
run: |
cargo build -p wasm-lib --target wasm32-wasi --release
Expand Down
34 changes: 34 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[workspace]
resolver = "2"
members = [
"say_hello",
"async-wasi/run-wasm-app",
"async-wasi/wasm-app",
"async-wasi-socket-addr/main-app",
"async-wasi-socket-addr/socket-addr",
"call-wasm-lib-from-host/call-wasm-lib",
"call-wasm-lib-from-host/wasm-lib",
"call-wasm-lib-with-external-deps/host-app",
"call-wasm-lib-with-external-deps/wasm-lib",
"define-async-host-func",
"define-async-host-func-with-host-data",
"define-host-func",
"define-host-func-with-host-data",
"run-wasm-app-from-host/run-wasm-app",
"run-wasm-app-from-host/wasm-app",
"run-wasm-func-in-aot-mode",
"load-module-in-module/alice-wasm-lib",
"load-module-in-module/bob-wasm-lib",
"load-module-in-module/host-app",
"manipulate-linear-memory",
"ggml-llama-via-wasinn/run-ggml-llama-inference",
"ggml-llama-via-wasinn/ggml-llama-wasm",
"object-detection-via-wasinn",
"set-env-vars-via-wasi/print-env-vars",
"set-env-vars-via-wasi/set-env-vars-via-wasi",
]


[workspace.dependencies]
wasmedge-sdk = { version = "0.14.0", features = ["async"] }
tokio = { version = "1", features = ["full"] }
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
- [Host Functions](#host-functions)
- [Example: Define a host function](#example-define-a-host-function)
- [Example: Define a host function with host context data](#example-define-a-host-function-with-host-context-data)
- [Example: Define a host function with string arguments](#example-define-a-host-function-with-string-arguments)
- [Example: Arguments of non-standard wasm types in wasm function (wasmedge-bindgen)](#example-arguments-of-non-standard-wasm-types-in-wasm-function-wasmedge-bindgen)
- [Memory and Table](#memory-and-table)
- [Example: Manipulate WebAssembly linear memory](#example-manipulate-webassembly-linear-memory)
- [Example: Use WebAssembly `Table` and `FuncRef` to invoke host functions](#example-use-webassembly-table-and-funcref-to-invoke-host-functions)
- [AOT](#aot)
- [Example: Call wasm library in AOT mode](#example-call-wasm-library-in-aot-mode)
- [WASI](#wasi)
Expand Down
2 changes: 0 additions & 2 deletions async-wasi-socket-addr/Cargo.toml

This file was deleted.

8 changes: 5 additions & 3 deletions async-wasi-socket-addr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ Now let's build and run this example.
# NOTICE that the installation script needs `sudo` access

# install wasmedge to the directory /usr/local/
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -v 0.13.5 -p /usr/local
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -v 0.14.0
source $HOME/.wasmedge/env
```

> For users in China mainland (中国大陆地区), try the following command to install WasmEdge Runtime if failed to run the command above
>
> ```bash
> # NOTICE that the installation script needs `sudo` access
>
> bash install_zh.sh -v 0.13.5 -p /usr/local
> bash install_zh.sh -v 0.14.0
> source $HOME/.wasmedge/env
> ```
- Download example
Expand All @@ -59,7 +61,7 @@ Now let's build and run this example.
- Build and run `main-app`

```bash
cargo run -p main-app -- ./target/wasm32-wasi/release/socket-addr.wasm
cargo run -p main-app -- ../target/wasm32-wasi/release/socket-addr.wasm
```

If the command runs successfully, then the following message is printed out on the screen:
Expand Down
4 changes: 2 additions & 2 deletions async-wasi-socket-addr/main-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ version = "0.4.0"
edition = "2021"

[dependencies]
wasmedge-sdk = { version = "0.13.0", features = ["async"] }
tokio = { version = "1", features = ["full"] }
wasmedge-sdk.workspace = true
tokio.workspace = true
42 changes: 20 additions & 22 deletions async-wasi-socket-addr/main-app/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use std::collections::HashMap;

use wasmedge_sdk::{
config::{CommonConfigOptions, ConfigBuilder, HostRegistrationConfigOptions},
wasi::r#async::{AsyncState, WasiContext},
NeverType, VmBuilder,
r#async::{
vm::Vm,
wasi::{async_wasi::WasiCtx, AsyncWasiModule},
},
Module, Store,
};

#[tokio::main]
Expand All @@ -13,31 +17,25 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
}
let wasm_file = &args[1];

let config = ConfigBuilder::new(CommonConfigOptions::default())
.with_host_registration_config(HostRegistrationConfigOptions::default().wasi(true))
.build()
.expect("failed to create config");
assert!(config.wasi_enabled());
let wasi_ctx = WasiCtx::new();
let mut wasi = AsyncWasiModule::create_from_wasi_context(wasi_ctx).unwrap();

// let mut instance: HashMap<String, &mut (dyn AsInstance + Send)> = HashMap::new();
let mut instances = HashMap::new();
instances.insert(wasi.name().to_string(), wasi.as_mut().as_mut());

let store = Store::new(None, instances)?;

// create WasiContext
let wasi_ctx = WasiContext::default();
let module = Module::from_file(None, wasm_file)?;

// create a Vm
let mut vm = VmBuilder::default()
.with_config(config)
.with_wasi_context(wasi_ctx)
.build()
.expect("failed to create vm");

// run the wasm function from a specified wasm file
let async_state = AsyncState::new();
let _ = vm
.run_func_from_file_async(&async_state, wasm_file, "_start", [])
let mut vm = Vm::new(store);
vm.register_module(None, module)?;
vm.run_func(None, "_start", [])
.await
.expect("failed to run func from file");

let wasi_module = vm.wasi_module().ok_or("failed to get wasi module")?;
println!("exit_code: {}", wasi_module.exit_code());
println!("exit_code: {}", wasi.exit_code());

Ok(())
}
6 changes: 3 additions & 3 deletions async-wasi-socket-addr/socket-addr/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ fn main() -> std::io::Result<()> {
println!("[socket-addr] err: {:?}", err.kind());

// dns
let mut addr = ("localhost:3000").to_socket_addrs().unwrap();
assert_eq!(addr.next(), Some(SocketAddr::from(([127, 0, 0, 1], 3000))));
println!("[socket-addr] addr: {:?}", addr.next());
// let mut addr = ("localhost:3000").to_socket_addrs().unwrap();
// assert_eq!(addr.next(), Some(SocketAddr::from(([127, 0, 0, 1], 3000))));
// println!("[socket-addr] addr: {:?}", addr.next());

Ok(())
}
2 changes: 0 additions & 2 deletions async-wasi/Cargo.toml

This file was deleted.

Loading

0 comments on commit f54a726

Please sign in to comment.