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

William/perf new #1

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c6cdd71
[Examples] Move the plug-in examples to the correct directory.
q82419 May 23, 2022
c6dfa12
[Examples] Move the examples in the `tools` into the `examples`.
q82419 May 23, 2022
e0e41c2
[Changelog] Update the changelog for the 0.10.0-rc.1 pre-release.
q82419 May 23, 2022
42d930b
[Rust] Implemented vm in wasmedge-sdk crate (#1488)
apepkuss May 24, 2022
11ee9b3
[RPM] Update RPM SPEC file to build on koji
dm4 May 24, 2022
1c4decc
[Docs] Add zh go dev doc (#1483)
cyw3 May 25, 2022
42aed9f
[Docs] Update the host function and externref examples to 0.10.0.
q82419 May 24, 2022
4fd39f4
[Docs] Add the example repo link.
q82419 May 25, 2022
0c36dbe
[Changelog] Update the changelog for the 0.10.0 release.
q82419 May 25, 2022
97f49ac
[Docs] Update the build instructions for Windows (#1495)
abhinandanudupa May 27, 2022
a7aa08e
[Rust SDK][CI] (rust-wasmedge-sdk-release): Used nightly channel of R…
apepkuss May 27, 2022
b8ce275
[Installer]: Fix #1497, version more than 1 digit was excluded
0yi0 May 27, 2022
afb6b8c
[Utils] Install Script improvements (#1479)
SAtacker May 27, 2022
af9e27a
[Utils] Installer Script: Tweak sort version sort for better semantic…
SAtacker May 29, 2022
396d7d0
[Docs] Translate embed/go/ref.md to zh. (#1092) (#1198)
swartz-k May 29, 2022
024c012
[Utils] Installer Script: Prevent writing relative path to login shel…
spacewander May 30, 2022
6549138
perf(interpreter): use a more effective memcpy in interpreter memory …
wenym1 May 28, 2022
92fd9a3
improve memory store with effective memcpy
wenym1 May 28, 2022
cceac74
fix unit test compile
wenym1 May 28, 2022
3ba8465
add volatile for effective memcpy
wenym1 May 30, 2022
5113739
use volatile in floating point memory load
wenym1 May 30, 2022
bcc492d
try only use memcpy
wenym1 May 31, 2022
b84cb38
add alignment check in memcpy
wenym1 May 31, 2022
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: 5 additions & 3 deletions .CurrentChangelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### 0.10.0-alpha.2 (2022-05-20)
### 0.10.0 (2022-05-26)

Breaking changes:

Expand Down Expand Up @@ -38,6 +38,7 @@ Breaking changes:

Features:

* Supported LLVM 14.
* Supported the WASM `tail-call` proposal.
* Added the `WasmEdge_Proposal_TailCall` for the configuration in WasmEdge C API.
* Users can use the `--enable-tail-call` to enable the proposal in `wasmedge` and `wasmedgec` tools.
Expand Down Expand Up @@ -114,12 +115,13 @@ Tests:

* Updated the spec tests to the date `20220504`.
* Added the spec tests for the `tail-call` proposal.
* Added the spec tests for the `extended-const` proposal.
* Added the mixed invocation tests between interpreter mode and AOT mode WASM functions.
* Added the thread-safe and multi-thread execution tests.
* Added wasi-socket tests for `poll_oneoff`, `send_to`, and `recv_from`.

Thank all the contributors that made this release possible!

朱亚光, Abhinandan Udupa, Ang Lee, Binbin Zhang, Chin Zhi Wei, DarumaDocker, Elon Cheng, FlyingOnion, Hanged Fish, Herschel Wang, JIAN ZHONG, JcJinChen, Jeremy, JessesChou, JieDing, Kodalien, Kunshuai Zhu, LFsWang, LaingKe, Michael Yuan, Nicholas Zhan, 华德禹, O3Ol, Rui Li, Shen-Ta Hsieh, Shreyas Atre, Sylveon, TheLightRunner, Vaniot, Vinson, 罗泽轩, Xin Liu, Yi Huang, YiYing He, YoungLH, abhinandanudupa, border1px, eat4toast, hydai, jerbmarx, luckyJ-nj, meoww-bot, mydreamer4134, situ2001, tpmccallum, treeplus, wangyuan249, 王琦
朱亚光, Abhinandan Udupa, Ang Lee, Binbin Zhang, Chin Zhi Wei, DarumaDocker, Elon Cheng, FlyingOnion, Hanged Fish, Herschel Wang, JIAN ZHONG, JcJinChen, Jeremy, JessesChou, JieDing, Kodalien, Kunshuai Zhu, LFsWang, LaingKe, MediosZ, Michael Yuan, Nicholas Zhan, 华德禹, O3Ol, Rui Li, Shen-Ta Hsieh, Shreyas Atre, Sylveon, TheLightRunner, Vaniot, Vinson, 罗泽轩, Xin Liu, Yi Huang, YiYing He, YoungLH, abhinandanudupa, border1px, dm4, eat4toast, hydai, jerbmarx, luckyJ-nj, meoww-bot, mydreamer4134, situ2001, tpmccallum, treeplus, wangyuan249, yale, 王琦

If you want to build from source, please use WasmEdge-0.10.0-alpha.1-src.tar.gz instead of the zip or tarball provided by GitHub directly.
If you want to build from source, please use WasmEdge-0.10.0-src.tar.gz instead of the zip or tarball provided by GitHub directly.
4 changes: 2 additions & 2 deletions .github/workflows/rust-wasmedge-sdk-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
with:
fetch-depth: 0

- name: Install Stable Rust
- name: Install Nightly Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: nightly

- name: Build WasmEdge using clang
run: |
Expand Down
129 changes: 129 additions & 0 deletions .github/workflows/test-install-script.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,78 @@ jobs:
grep -qE *.wasmedge/env* ~/.bashrc && echo "Failed: Source Lines found" || echo "Pass: Source Lines Removed"
grep -qE *.wasmedge/env* ~/.bash_profile && echo "Failed: Source Lines found" || echo "Pass: Source Lines Removed"
grep -qE *.wasmedge/env* ~/.profile && echo "Failed: Source Lines found" || echo "Pass: Source Lines Removed"
- name: Plugins Install check
run: |
bash utils/install.sh -v 0.10.0-alpha.1
ls ~/.wasmedge/plugin/ | grep .so && echo "Pass: Plugins found" || (echo "Fail: Plugins not found" && exit 1)
bash utils/install.sh -v 0.10.0-alpha.1 -p ~/new_wasmedge
ls ~/new_wasmedge/plugin/ | grep .so && echo "Pass: Plugins found" || (echo "Fail: Plugins not found" && exit 1)
bash utils/install.sh -v 0.10.0-alpha.1 -p /usr
ls /usr/lib/wasmedge/ | grep libwasmedgePluginWasmEdgeProcess.so && echo "Pass: Plugins found" || (echo "Fail: Plugins not found" && exit 1)
- name: Image Extensions - Version Based Conditions check
run: |
VERSION_IM_DEPS=0.9.1
# arch64
[ "$(printf %s\\n%s\\n "0.9.1-beta.1" "$VERSION_IM_DEPS")" != "$(printf %s\\n%s "0.9.1-beta.1" "$VERSION_IM_DEPS" | awk '{ if ($1 ~ /-/) print; else print $0"_" ; }' | sort --version-sort | sed 's/_$//')" ] &&
(echo "Fail: Sort failed" && exit 1) || echo "Pass: Extensions Compatible"

VERSION_IM_DEPS=0.9.1-rc.1
# arch64
[ "$(printf %s\\n%s\\n "0.9.1-beta.1" "$VERSION_IM_DEPS")" != "$(printf %s\\n%s "0.9.1-beta.1" "$VERSION_IM_DEPS" | awk '{ if ($1 ~ /-/) print; else print $0"_" ; }' | sort --version-sort | sed 's/_$//')" ] &&
(echo "Fail: Sort failed" && exit 1) || echo "Pass: Extensions Compatible"

VERSION_IM_DEPS=0.9.1-beta.2
# arch64
[ "$(printf %s\\n%s\\n "0.9.1-beta.1" "$VERSION_IM_DEPS")" != "$(printf %s\\n%s "0.9.1-beta.1" "$VERSION_IM_DEPS" | awk '{ if ($1 ~ /-/) print; else print $0"_" ; }' | sort --version-sort | sed 's/_$//')" ] &&
(echo "Fail: Sort failed" && exit 1) || echo "Pass: Extensions Compatible"

VERSION_IM_DEPS=0.9.1-alpha.1
# arch64
[ "$(printf %s\\n%s\\n "0.9.1-beta.1" "$VERSION_IM_DEPS")" != "$(printf %s\\n%s "0.9.1-beta.1" "$VERSION_IM_DEPS" | awk '{ if ($1 ~ /-/) print; else print $0"_" ; }' | sort --version-sort | sed 's/_$//')" ] &&
echo "Pass: Extensions incompatible" || (echo "Fail: Extensions Compatible" && exit 1)

VERSION_IM_DEPS=0.8.1
# Normal Test
[ "$(printf %s\\n%s\\n "$VERSION_IM_DEPS" "0.8.2")" = "$(printf %s\\n%s "$VERSION_IM_DEPS" "0.8.2" | awk '{ if ($1 ~ /-/) print; else print $0"_" ; }' | sort --version-sort | sed 's/_$//')" ] &&
echo "Pass: Image deps needed" || (echo "Fail: Image deps needed" && exit 1)

VERSION_IM_DEPS=0.8.3
# Normal Test
[ "$(printf %s\\n%s\\n "$VERSION_IM_DEPS" "0.8.2")" = "$(printf %s\\n%s "$VERSION_IM_DEPS" "0.8.2" | awk '{ if ($1 ~ /-/) print; else print $0"_" ; }' | sort --version-sort | sed 's/_$//')" ] &&
(echo "Fail: Image deps not needed" && exit 1) || echo "Pass: Image deps not needed"

VERSION_IM_DEPS=0.8.2
# Normal Test
[ "$(printf %s\\n%s\\n "$VERSION_IM_DEPS" "0.8.2")" = "$(printf %s\\n%s "$VERSION_IM_DEPS" "0.8.2" | awk '{ if ($1 ~ /-/) print; else print $0"_" ; }' | sort --version-sort | sed 's/_$//')" ] &&
echo "Pass: Image Needed" || (echo "Fail: Image deps needed" && exit 1)
- name: Tensorflow Extensions - Version Based Conditions check
run: |
VERSION_TF_DEPS=0.9.1
# arch64
[ "$(printf %s\\n%s\\n "0.9.1-beta.1" "$VERSION_TF_DEPS")" != "$(printf %s\\n%s "0.9.1-beta.1" "$VERSION_TF_DEPS" | awk '{ if ($1 ~ /-/) print; else print $0"_" ; }' | sort --version-sort | sed 's/_$//')" ] &&
(echo "Fail: Sort failed" && exit 1) || echo "Pass: Extensions Compatible"

VERSION_TF_DEPS=0.9.1-rc.1
# arch64
[ "$(printf %s\\n%s\\n "0.9.1-beta.1" "$VERSION_TF_DEPS")" != "$(printf %s\\n%s "0.9.1-beta.1" "$VERSION_TF_DEPS" | awk '{ if ($1 ~ /-/) print; else print $0"_" ; }' | sort --version-sort | sed 's/_$//')" ] &&
(echo "Fail: Sort failed" && exit 1) || echo "Pass: Extensions Compatible"

VERSION_TF_DEPS=0.9.1-beta.2
# arch64
[ "$(printf %s\\n%s\\n "0.9.1-beta.1" "$VERSION_TF_DEPS")" != "$(printf %s\\n%s "0.9.1-beta.1" "$VERSION_TF_DEPS" | awk '{ if ($1 ~ /-/) print; else print $0"_" ; }' | sort --version-sort | sed 's/_$//')" ] &&
(echo "Fail: Sort failed" && exit 1) || echo "Pass: Extensions Compatible"

VERSION_TF_DEPS=0.9.1-alpha.1
# arch64
[ "$(printf %s\\n%s\\n "0.9.1-beta.1" "$VERSION_TF_DEPS")" != "$(printf %s\\n%s "0.9.1-beta.1" "$VERSION_TF_DEPS" | awk '{ if ($1 ~ /-/) print; else print $0"_" ; }' | sort --version-sort | sed 's/_$//')" ] &&
echo "Pass: Extensions incompatible" || (echo "Fail: Sort failed" && exit 1)
- name: Latest Release Check
run: |
_res_git_=$(git ls-remote --refs --tags "https://github.com/WasmEdge/WasmEdge.git" | cut -d '/' -f 3 | awk '{ if ($1 ~ /-/) print; else print $0"_" ; }' | sort --version-sort | sed 's/_$//' | grep -e '^[0-9]\+.[0-9]\+.[0-9]\+$' | tail -1)
_res_curl_=$(curl --silent "https://api.github.com/repos/WasmEdge/WasmEdge/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' )
[ "$_res_git_" = "$_res_curl_" ] && echo "Pass: Fetched version equals release" ||
(echo "Fail: Fetched version does not equal GitHub Ref\nFetched:$_res_git_\nCI:$_res_curl_" && exit 1)


macos:
strategy:
Expand Down Expand Up @@ -175,3 +247,60 @@ jobs:
- name: Uninstall WasmEdge with all extensions
run: |
bash utils/uninstall.sh -q -V
- name: Plugins Install check
run: |
bash utils/install.sh -v 0.10.0-alpha.1
ls ~/.wasmedge/plugin/ | grep .dylib && echo "Pass: Plugins found" || (echo "Fail: Plugins not found" && exit 1)
bash utils/install.sh -v 0.10.0-alpha.1 -p ~/new_wasmedge
ls ~/new_wasmedge/plugin/ | grep .dylib && echo "Pass: Plugins found" || (echo "Fail: Plugins not found" && exit 1)
# MacOS container does not have access for /usr directory
# bash utils/install.sh -v 0.10.0-alpha.1 -p /usr
# ls /usr/lib/wasmedge/ | grep libwasmedgePluginWasmEdgeProcess.dylib && echo "Pass: Plugins found" || (echo "Fail: Plugins not found" && exit 1)
- name: Image Extensions - Version Based Conditions check
run: |
VERSION_IM_DEPS=0.10.0
# Darwin test
[ "$(printf %s\\n%s\\n "0.10.0-alpha.1" "$VERSION_IM_DEPS")" != "$(printf %s\\n%s "0.10.0-alpha.1" "$VERSION_IM_DEPS" | awk '{ if ($1 ~ /-/) print; else print $0"_" ; }' | sort --version-sort | sed 's/_$//')" ] &&
(echo "Fail: Sort failed" && exit 1) || echo "Pass: Extensions Compatible"

VERSION_IM_DEPS=0.10.0-alpha.2
# Darwin test
[ "$(printf %s\\n%s\\n "0.10.0-alpha.1" "$VERSION_IM_DEPS")" != "$(printf %s\\n%s "0.10.0-alpha.1" "$VERSION_IM_DEPS" | awk '{ if ($1 ~ /-/) print; else print $0"_" ; }' | sort --version-sort | sed 's/_$//')" ] &&
(echo "Fail: Sort failed" && exit 1) || echo "Pass: Extensions Compatible"

VERSION_IM_DEPS=0.9.1
# Darwin test
[ "$(printf %s\\n%s\\n "0.10.0-alpha.1" "$VERSION_IM_DEPS")" != "$(printf %s\\n%s "0.10.0-alpha.1" "$VERSION_IM_DEPS" | awk '{ if ($1 ~ /-/) print; else print $0"_" ; }' | sort --version-sort | sed 's/_$//')" ] &&
echo "Pass: Extensions incompatible" || (echo "Fail: Extensions Compatible" && exit 1)
- name: Tensorflow Extensions - Version Based Conditions check
run: |
VERSION_TF=0.10.0-alpha.1
# Darwin
[ "$(printf %s\\n%s\\n "0.10.0-alpha.1" "$VERSION_TF")" != "$(printf %s\\n%s "0.10.0-alpha.1" "$VERSION_TF" | awk '{ if ($1 ~ /-/) print; else print $0"_" ; }' | sort --version-sort | sed 's/_$//')" ] &&
(echo "Fail: Extensions incompatible" && exit 1) || echo "Pass: Extensions compatible"

VERSION_TF=0.10.0-alpha.2
# Darwin
[ "$(printf %s\\n%s\\n "0.10.0-alpha.1" "$VERSION_TF")" != "$(printf %s\\n%s "0.10.0-alpha.1" "$VERSION_TF" | awk '{ if ($1 ~ /-/) print; else print $0"_" ; }' | sort --version-sort | sed 's/_$//')" ] &&
(echo "Fail: Extensions incompatible" && exit 1) || echo "Pass: Extensions compatible"

VERSION_TF=0.10.0-rc.1
# Darwin
[ "$(printf %s\\n%s\\n "0.10.0-alpha.1" "$VERSION_TF")" != "$(printf %s\\n%s "0.10.0-alpha.1" "$VERSION_TF" | awk '{ if ($1 ~ /-/) print; else print $0"_" ; }' | sort --version-sort | sed 's/_$//')" ] &&
(echo "Fail: Extensions incompatible" && exit 1) || echo "Pass: Extensions compatible"

VERSION_TF=0.10.0
# Darwin
[ "$(printf %s\\n%s\\n "0.10.0-alpha.1" "$VERSION_TF")" != "$(printf %s\\n%s "0.10.0-alpha.1" "$VERSION_TF" | awk '{ if ($1 ~ /-/) print; else print $0"_" ; }' | sort --version-sort | sed 's/_$//')" ] &&
(echo "Fail: Extensions incompatible" && exit 1) || echo "Pass: Extensions compatible"

VERSION_TF=0.9.1
# Darwin
[ "$(printf %s\\n%s\\n "0.10.0-alpha.1" "$VERSION_TF")" != "$(printf %s\\n%s "0.10.0-alpha.1" "$VERSION_TF" | awk '{ if ($1 ~ /-/) print; else print $0"_" ; }' | sort --version-sort | sed 's/_$//')" ] &&
echo "Pass: Extensions incompatible" || (echo "Fail: Extensions Compatible" && exit 1)
- name: Latest Release Check
run: |
_res_git_=$(git ls-remote --refs --tags "https://github.com/WasmEdge/WasmEdge.git" | cut -d '/' -f 3 | awk '{ if ($1 ~ /-/) print; else print $0"_" ; }' | sort --version-sort | sed 's/_$//' | grep -e '^[0-9]\+.[0-9]\+.[0-9]\+$' | tail -1)
_res_curl_=$(curl --silent "https://api.github.com/repos/WasmEdge/WasmEdge/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' )
[ "$_res_git_" = "$_res_curl_" ] && echo "Pass: Fetched version equals release" ||
(echo "Fail: Fetched version does not equal GitHub Ref\nFetched:$_res_git_\nCI:$_res_curl_" && exit 1)
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ if(WASMEDGE_BUILD_TOOLS)
add_subdirectory(tools)
endif()
if(WASMEDGE_BUILD_EXAMPLE)
add_subdirectory(example/get-string)
add_subdirectory(examples/plugin/get-string)
endif()

include(CPack)
Expand Down
8 changes: 5 additions & 3 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### 0.10.0-alpha.2 (2022-05-20)
### 0.10.0 (2022-05-26)

Breaking changes:

Expand Down Expand Up @@ -38,6 +38,7 @@ Breaking changes:

Features:

* Supported LLVM 14.
* Supported the WASM `tail-call` proposal.
* Added the `WasmEdge_Proposal_TailCall` for the configuration in WasmEdge C API.
* Users can use the `--enable-tail-call` to enable the proposal in `wasmedge` and `wasmedgec` tools.
Expand Down Expand Up @@ -114,15 +115,16 @@ Tests:

* Updated the spec tests to the date `20220504`.
* Added the spec tests for the `tail-call` proposal.
* Added the spec tests for the `extended-const` proposal.
* Added the mixed invocation tests between interpreter mode and AOT mode WASM functions.
* Added the thread-safe and multi-thread execution tests.
* Added wasi-socket tests for `poll_oneoff`, `send_to`, and `recv_from`.

Thank all the contributors that made this release possible!

朱亚光, Abhinandan Udupa, Ang Lee, Binbin Zhang, Chin Zhi Wei, DarumaDocker, Elon Cheng, FlyingOnion, Hanged Fish, Herschel Wang, JIAN ZHONG, JcJinChen, Jeremy, JessesChou, JieDing, Kodalien, Kunshuai Zhu, LFsWang, LaingKe, Michael Yuan, Nicholas Zhan, 华德禹, O3Ol, Rui Li, Shen-Ta Hsieh, Shreyas Atre, Sylveon, TheLightRunner, Vaniot, Vinson, 罗泽轩, Xin Liu, Yi Huang, YiYing He, YoungLH, abhinandanudupa, border1px, eat4toast, hydai, jerbmarx, luckyJ-nj, meoww-bot, mydreamer4134, situ2001, tpmccallum, treeplus, wangyuan249, 王琦
朱亚光, Abhinandan Udupa, Ang Lee, Binbin Zhang, Chin Zhi Wei, DarumaDocker, Elon Cheng, FlyingOnion, Hanged Fish, Herschel Wang, JIAN ZHONG, JcJinChen, Jeremy, JessesChou, JieDing, Kodalien, Kunshuai Zhu, LFsWang, LaingKe, MediosZ, Michael Yuan, Nicholas Zhan, 华德禹, O3Ol, Rui Li, Shen-Ta Hsieh, Shreyas Atre, Sylveon, TheLightRunner, Vaniot, Vinson, 罗泽轩, Xin Liu, Yi Huang, YiYing He, YoungLH, abhinandanudupa, border1px, dm4, eat4toast, hydai, jerbmarx, luckyJ-nj, meoww-bot, mydreamer4134, situ2001, tpmccallum, treeplus, wangyuan249, yale, 王琦

If you want to build from source, please use WasmEdge-0.10.0-alpha.1-src.tar.gz instead of the zip or tarball provided by GitHub directly.
If you want to build from source, please use WasmEdge-0.10.0-src.tar.gz instead of the zip or tarball provided by GitHub directly.

### 0.9.1 (2022-02-10)

Expand Down
2 changes: 1 addition & 1 deletion bindings/rust/wasmedge-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ version = "0.1.0"
anyhow = "1.0"
thiserror = "1.0.30"
wasmedge-sys = {path = "../wasmedge-sys", version = "0.7"}
wasmedge-types = "0.1.2"
wasmedge-types = "0.1"
wat = "1.0"

[features]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let module_name = "extern";
let _import = ImportObjectBuilder::new()
// add a function
.with_func::<(i32, i32), i32>("add", Box::new(real_add))?
.with_func::<(i32, i32), i32>("add", real_add)?
// add a global
.with_global("global", global_const)?
// add a memory
Expand Down
2 changes: 1 addition & 1 deletion bindings/rust/wasmedge-sdk/examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn main() -> anyhow::Result<()> {

// create an import module
let import = ImportObjectBuilder::new()
.with_func::<(), ()>("say_hello", Box::new(say_hello_world))?
.with_func::<(), ()>("say_hello", say_hello_world)?
.build("env")?;

// loads a wasm module from the given in-memory bytes
Expand Down
2 changes: 2 additions & 0 deletions bindings/rust/wasmedge-sdk/examples/table.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(explicit_generic_args_with_impl_trait)]

use wasmedge_sdk::{params, types::Val, Executor, Func, Module, Store, WasmVal};
use wasmedge_sys::types::WasmValue;
use wasmedge_types::{wat2wasm, RefType, TableType, ValType};
Expand Down
2 changes: 2 additions & 0 deletions bindings/rust/wasmedge-sdk/examples/table_and_funcref.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(explicit_generic_args_with_impl_trait)]

use wasmedge_sdk::{
config::{CommonConfigOptions, ConfigBuilder},
params,
Expand Down
68 changes: 68 additions & 0 deletions bindings/rust/wasmedge-sdk/examples/vm.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//! This example presents how to register a module as named module in a Vm instance and run a target wasm function.

#![feature(explicit_generic_args_with_impl_trait)]

use wasmedge_sdk::{params, Vm, WasmVal};
use wasmedge_types::{wat2wasm, ValType};

#[cfg_attr(test, test)]
fn main() -> Result<(), Box<dyn std::error::Error>> {
// create a Vm context
let vm = Vm::new(None)?;

// register a wasm module from the given in-memory wasm bytes
let wasm_bytes = wat2wasm(
br#"(module
(export "fib" (func $fib))
(func $fib (param $n i32) (result i32)
(if
(i32.lt_s
(get_local $n)
(i32.const 2)
)
(return
(i32.const 1)
)
)
(return
(i32.add
(call $fib
(i32.sub
(get_local $n)
(i32.const 2)
)
)
(call $fib
(i32.sub
(get_local $n)
(i32.const 1)
)
)
)
)
)
)
"#,
)?;
let mut vm = vm.register_module_from_bytes("extern", wasm_bytes)?;

// get func type of `fib`
let func_ty = vm.func_ty(Some("extern"), "fib")?;

// get the argument types
assert_eq!(func_ty.args_len(), 1);
let args = func_ty.args().expect("No argument types.");
assert_eq!(args, [ValType::I32]);

// get the return types
assert_eq!(func_ty.returns_len(), 1);
let returns = func_ty.returns().expect("No return types.");
assert_eq!(returns, [ValType::I32]);

// run `fib` function in the named module instance
let returns = vm.run_func(Some("extern"), "fib", params!(10))?;
assert_eq!(returns.len(), 1);
assert_eq!(returns[0].to_i32(), 89);

Ok(())
}
Loading