Skip to content

Commit

Permalink
Update the docs for WasmEdge 0.14.0.
Browse files Browse the repository at this point in the history
Signed-off-by: YiYing He <[email protected]>
  • Loading branch information
q82419 committed Feb 23, 2024
1 parent e571172 commit 8ad1b5b
Show file tree
Hide file tree
Showing 73 changed files with 7,390 additions and 639 deletions.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
WASMEDGE_VERSION='0.13.4'
WASMEDGE_VERSION='0.14.0'
WASMEDGE_GO_VERSION='0.13.4'
2 changes: 1 addition & 1 deletion docs/contribute/installer.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ The actual installer handles all stuff. It supports python2.7 (not tested on ear
- Full Option: `--dist ubuntu20.04` or `--dist manylinux2014`
- Note - the `ubuntu20.04` and `manylinux2014` values are case insensitive and only these two are currently supported.
- Note - Specifying `--dist` value for `Darwin` has no effect.
- Note - For `Linux` platform if the distribution matches exactly as `Ubuntu 20.04`, which is checked using `lsb_release` and python's ` platform.dist()` functionality is then set to `ubuntu20.04` if not specified, or it is used without questioning. However different release packages for WasmEdge are available only after `0.11.1` release, below which there is no effect of specifying this option.
- Note - For `Linux` platform if the distribution matches exactly as `Ubuntu 20.04`, which is checked using `lsb_release` and python's `platform.dist()` functionality is then set to `ubuntu20.04` if not specified, or it is used without questioning. However different release packages for WasmEdge are available only after `0.11.1` release, below which there is no effect of specifying this option.

### Platform and OS

Expand Down
42 changes: 21 additions & 21 deletions docs/contribute/plugin/develop_plugin_c.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,17 @@ WasmEdge_Result HostFuncSub(void *Data,
WasmEdge_ModuleInstanceContext *
CreateTestModule(const struct WasmEdge_ModuleDescriptor *Desc) {
/*
* The `Desc` is the const pointer to the module descriptor struct:
*
* typedef struct WasmEdge_ModuleDescriptor {
* const char *Name;
* const char *Description;
* WasmEdge_ModuleInstanceContext *(*Create)(
* const struct WasmEdge_ModuleDescriptor *);
* } WasmEdge_ModuleDescriptor;
*
* Developers can get the name and description from this descriptor.
*/
* The `Desc` is the const pointer to the module descriptor struct:
*
* typedef struct WasmEdge_ModuleDescriptor {
* const char *Name;
* const char *Description;
* WasmEdge_ModuleInstanceContext *(*Create)(
* const struct WasmEdge_ModuleDescriptor *);
* } WasmEdge_ModuleDescriptor;
*
* Developers can get the name and description from this descriptor.
*/
/* Exported module name of this module instance. */
WasmEdge_String ModuleName =
Expand All @@ -117,10 +117,10 @@ WasmEdge_Result HostFuncSub(void *Data,
WasmEdge_String FuncName;
WasmEdge_FunctionTypeContext *FType;
WasmEdge_FunctionInstanceContext *FuncCxt;
enum WasmEdge_ValType ParamTypes[2], ReturnTypes[1];
ParamTypes[0] = WasmEdge_ValType_I32;
ParamTypes[1] = WasmEdge_ValType_I32;
ReturnTypes[0] = WasmEdge_ValType_I32;
WasmEdge_ValType ParamTypes[2], ReturnTypes[1];
ParamTypes[0] = WasmEdge_ValTypeGenI32();
ParamTypes[1] = WasmEdge_ValTypeGenI32();
ReturnTypes[0] = WasmEdge_ValTypeGenI32();
/* Create and add the host function instances into the module instance. */
FType = WasmEdge_FunctionTypeCreate(ParamTypes, 2, ReturnTypes, 1);
Expand Down Expand Up @@ -148,9 +148,9 @@ WasmEdge_Result HostFuncSub(void *Data,
/* The module descriptor array. There can be multiple modules in a plug-in. */
static WasmEdge_ModuleDescriptor ModuleDesc[] = {{
/*
* Module name. This is the name for searching and creating the module
* instance context by the `WasmEdge_PluginCreateModule()` API.
*/
* Module name. This is the name for searching and creating the module
* instance context by the `WasmEdge_PluginCreateModule()` API.
*/
.Name = "wasmedge_plugintest_c_module",
/* Module description. */
.Description = "This is for the plugin tests in WasmEdge C API.",
Expand All @@ -161,9 +161,9 @@ WasmEdge_Result HostFuncSub(void *Data,
/* The plug-in descriptor */
static WasmEdge_PluginDescriptor Desc[] = {{
/*
* Plug-in name. This is the name for searching the plug-in context by the
* `WasmEdge_PluginFind()` API.
*/
* Plug-in name. This is the name for searching the plug-in context by the
* `WasmEdge_PluginFind()` API.
*/
.Name = "wasmedge_plugintest_c",
/* Plug-in description. */
.Description = "",
Expand Down
2 changes: 1 addition & 1 deletion docs/contribute/plugin/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@ Due to the `OpenVINO` dependency, we only release the WASI-NN plug-in for the `O
[wasmedge_process_interface]: https://crates.io/crates/wasmedge_process_interface
[wasmedge_tensorflow_interface]: https://crates.io/crates/wasmedge_tensorflow_interface
[wasi-crypto]: https://crates.io/crates/wasi-crypto
[wasi-nn]: https://crates.io/crates/wasi-nn
[wasi-nn]: https://crates.io/crates/wasi-nn
4 changes: 0 additions & 4 deletions docs/contribute/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ sidebar_position: 9

Following projects will be updated with the `Alpha`, `Beta`, and `RC` pre-releases and the official release:

- [ ] [WasmEdge-Image](https://github.com/second-state/WasmEdge-image)
- [ ] [WasmEdge-TensorFlow-Deps](https://github.com/second-state/WasmEdge-tensorflow-deps)
- [ ] [WasmEdge-TensorFlow](https://github.com/second-state/WasmEdge-tensorflow)
- [ ] [WasmEdge-TensorFlow-Tools](https://github.com/second-state/WasmEdge-tensorflow-tools)
- [ ] [WasmEdge-Go SDK](https://github.com/second-state/WasmEdge-go)
- [ ] [WasmEdge-core NAPI package](https://github.com/second-state/wasmedge-core)
- [ ] [WasmEdge-extensions NAPI package](https://github.com/second-state/wasmedge-extensions)
4 changes: 2 additions & 2 deletions docs/contribute/source/build_from_src.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ WasmEdge provides various tools for enabling different runtime environments for
Developers can set the CMake options to customize the WasmEdge building.

1. `WASMEDGE_BUILD_TESTS`: build the WasmEdge tests. Default is `OFF`.
2. `WASMEDGE_BUILD_AOT_RUNTIME`: build with the Ahead-of-Time compiler supporting. Default is `ON`.
2. `WASMEDGE_USE_LLVM`: build with LLVM-based runtime for supporting Ahead-of-Time and Just-In-Time compiler. Default is `ON`.
3. `WASMEDGE_BUILD_SHARED_LIB`: build the WasmEdge shared library (`libwasmedge.so`, `libwasmedge.dylib`, or `wasmedge.dll`). Default is `ON`.
- By default, the WasmEdge shared library will link to the LLVM shared library.
4. `WASMEDGE_BUILD_STATIC_LIB`: build the WasmEdge static library (`libwasmedge.a`, Linux and MacOS platforms, experimental). Default is `OFF`.
Expand All @@ -60,7 +60,7 @@ Developers can set the CMake options to customize the WasmEdge building.
- For linking with `libwasmedge.a`, developers should also add the `-ldl`, `-pthread`, `-lm`, and `-lstdc++` linker options on both Linux and MacOS platforms, and `-lrt` on Linux platforms.
5. `WASMEDGE_BUILD_TOOLS`: build the `wasmedge` and `wasmedgec` tools. Default is `ON`.
- The `wasmedge` and `wasmedgec` tools will link to the WasmEdge shared library by default.
- If this option is set as `ON` and `WASMEDGE_BUILD_AOT_RUNTIME` is set as `OFF`, the `wasmedgec` tool for the AOT compiler will not be built.
- If this option is set as `ON` and `WASMEDGE_USE_LLVM` is set as `OFF`, the `wasmedgec` tool for the AOT compiler will not be built.
- If this option is set as `ON` but the option `WASMEDGE_LINK_TOOLS_STATIC` is set as `OFF`, the option `WASMEDGE_BUILD_SHARED_LIB` will forcefully be set as `ON`.
- If this option and the option `WASMEDGE_LINK_TOOLS_STATIC` are both set as `ON`, the `WASMEDGE_LINK_LLVM_STATIC` and `WASMEDGE_BUILD_STATIC_LIB` will both be set as `ON`, and the `wasmedge` and `wasmedgec` tools will link to the WasmEdge static library instead. In this case, the plug-ins will not work in tools.
6. `WASMEDGE_BUILD_PLUGINS`: build the WasmEdge plug-ins. Default is `ON`.
Expand Down
2 changes: 1 addition & 1 deletion docs/contribute/source/os/openwrt.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ After that, create a virtual machine in VMware and install the OpenWrt system.

After setting the IP address of OpenWrt according to the gateway of the host, use `scp` to transfer the wasm file on the host to the OpenWrt system.

For example, we set the IP address of OpenWrt as 192.168.0.111, then we use the following commands to upload [hello.wasm](https://github.com/WasmEdge/WasmEdge/raw/master/examples/wasm/hello.wasm) and [add.wasm](https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/examples/wasm/add.wasm) these two test files to OpenWrt.
For example, we set the IP address of OpenWrt as 192.168.0.111, then we use the following commands to upload [hello.wasm (compiled from this example)](https://github.com/WasmEdge/WasmEdge/tree/master/examples/wasm) and [add.wasm (in text format)](https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/examples/wasm/add.wat) these two test files to OpenWrt.

```bash
scp hello.wasm [email protected]:/
Expand Down
33 changes: 18 additions & 15 deletions docs/embed/c/externref.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ sidebar_position: 4

[External References](https://webassembly.github.io/spec/core/syntax/types.html#syntax-reftype) denotes an opaque and unforgettable reference to a host object. A new `externref` type can be passed into a WASM module or returned. The WASM module cannot reveal an `externref` value's bit pattern nor create a fake host reference by an integer value.

<!-- prettier-ignore -->
:::note
For all WASM example codes used in this chapter, users can convert `wat` to `wasm` through [wat2wasm](https://webassembly.github.io/wabt/demo/wat2wasm/) live tool.
:::

## Tutorial

The following tutorial summarizes the `externref` example in WasmEdge.

### Prepare Your WASM File

The WASM file should contain importing host functions that take the `externref`. Take [the test WASM file](https://github.com/WasmEdge/WasmEdge/raw/master/test/externref/externrefTestData/funcs.wasm) ([this WAT](https://github.com/WasmEdge/WasmEdge/blob/master/test/externref/externrefTestData/funcs.wat) is the corresponding text format) as an example:
The WASM file should contain importing host functions that take the `externref`. Take [this WAT](https://github.com/WasmEdge/WasmEdge/blob/master/test/externref/externrefTestData/funcs.wat) as an example:

```wasm
(module
Expand Down Expand Up @@ -46,8 +51,6 @@ The WASM file should contain importing host functions that take the `externref`.
(memory $memory (export "memory") 1))
```

Users can convert `wat` to `wasm` through [wat2wasm](https://webassembly.github.io/wabt/demo/wat2wasm/) live tool. Noted that the `reference types` checkbox should be checked on this page.

### Implement Host Module and Register into WasmEdge

The host module should be implemented and registered into WasmEdge before executing Wasm. Assume that the following code is saved as `main.c`:
Expand Down Expand Up @@ -99,17 +102,17 @@ WasmEdge_ModuleInstanceContext *CreateExternModule() {
WasmEdge_String HostName;
WasmEdge_FunctionTypeContext *HostFType = NULL;
WasmEdge_FunctionInstanceContext *HostFunc = NULL;
enum WasmEdge_ValType P[3], R[1];
WasmEdge_ValType P[3], R[1];

HostName = WasmEdge_StringCreateByCString("extern_module");
WasmEdge_ModuleInstanceContext *HostMod =
WasmEdge_ModuleInstanceCreate(HostName);
WasmEdge_StringDelete(HostName);

// Add host function "functor_square": {externref, i32} -> {i32}
P[0] = WasmEdge_ValType_ExternRef;
P[1] = WasmEdge_ValType_I32;
R[0] = WasmEdge_ValType_I32;
P[0] = WasmEdge_ValTypeGenExternRef();
P[1] = WasmEdge_ValTypeGenI32();
R[0] = WasmEdge_ValTypeGenI32();
HostFType = WasmEdge_FunctionTypeCreate(P, 2, R, 1);
HostFunc = WasmEdge_FunctionInstanceCreate(HostFType, ExternSquare, NULL, 0);
WasmEdge_FunctionTypeDelete(HostFType);
Expand All @@ -118,7 +121,7 @@ WasmEdge_ModuleInstanceContext *CreateExternModule() {
WasmEdge_StringDelete(HostName);

// Add host function "class_add": {externref, i32, i32} -> {i32}
P[2] = WasmEdge_ValType_I32;
P[2] = WasmEdge_ValTypeGenI32();
HostFType = WasmEdge_FunctionTypeCreate(P, 3, R, 1);
HostFunc = WasmEdge_FunctionInstanceCreate(HostFType, ExternAdd, NULL, 0);
WasmEdge_FunctionTypeDelete(HostFType);
Expand Down Expand Up @@ -311,11 +314,11 @@ WasmEdge_ModuleInstanceContext *HostMod =
WasmEdge_StringDelete(HostName);
/* Create a function instance and add to the module instance. */
enum WasmEdge_ValType P[3], R[1];
P[0] = WasmEdge_ValType_ExternRef;
P[1] = WasmEdge_ValType_I32;
P[2] = WasmEdge_ValType_I32;
R[0] = WasmEdge_ValType_I32;
WasmEdge_ValType P[3], R[1];
P[0] = WasmEdge_ValTypeGenExternRef();
P[1] = WasmEdge_ValTypeGenI32();
P[2] = WasmEdge_ValTypeGenI32();
R[0] = WasmEdge_ValTypeGenI32();
WasmEdge_FunctionTypeContext *HostFType =
WasmEdge_FunctionTypeCreate(P, 3, R, 1);
WasmEdge_FunctionInstanceContext *HostFunc =
Expand All @@ -330,7 +333,7 @@ WasmEdge_StringDelete(HostName);

### Execution

Take [the test WASM file](https://github.com/WasmEdge/WasmEdge/raw/master/test/externref/externrefTestData/funcs.wasm) ([this WAT](https://github.com/WasmEdge/WasmEdge/blob/master/test/externref/externrefTestData/funcs.wat) is the corresponding text format) for example. Assume the `funcs.wasm` is copied into the current directory. The following is an example of executing WASM with `externref` through the WasmEdge C API.
Take [the test WASM file in text format](https://github.com/WasmEdge/WasmEdge/raw/master/test/externref/externrefTestData/funcs.wat) for example. Assume the `funcs.wasm` is copied into the current directory. The following is an example of executing WASM with `externref` through the WasmEdge C API.

```c
/* Create the VM context. */
Expand Down Expand Up @@ -481,7 +484,7 @@ WasmEdge_Result ExternSquare(void *, const WasmEdge_CallingFrameContext *,
### Passing STL Objects
The [example WASM binary](https://github.com/WasmEdge/WasmEdge/raw/master/test/externref/externrefTestData/stl.wasm) ([this WAT](https://github.com/WasmEdge/WasmEdge/blob/master/test/externref/externrefTestData/stl.wat) is the corresponding text format) provides functions to interact with host functions which can access C++ STL objects. Assume that the WASM file `stl.wasm` is copied into the current directory.
The [example WASM in text format](https://github.com/WasmEdge/WasmEdge/raw/master/test/externref/externrefTestData/stl.wat) provides functions to interact with host functions which can access C++ STL objects. Assume that the WASM file `stl.wasm` is copied into the current directory.
Take the `std::ostream` and `std::string` objects for example. Assume that there's a host function that accesses to a `std::ostream` and a `std::string` through `externref`s:
Expand Down
9 changes: 4 additions & 5 deletions docs/embed/c/host_function.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ WasmEdge_Result Add(void *, const WasmEdge_CallingFrameContext *,
For adding the host function into a host module instance, developers should first create the function instance with the function type context.

```c
enum WasmEdge_ValType ParamList[2] = {WasmEdge_ValType_I32,
WasmEdge_ValType_I32};
enum WasmEdge_ValType ReturnList[1] = {WasmEdge_ValType_I32};
WasmEdge_ValType ParamList[2] = {WasmEdge_ValTypeGenI32(), WasmEdge_ValTypeGenI32()};
WasmEdge_ValType ReturnList[1] = {WasmEdge_ValTypeGenI32()};
/* Create a function type: {i32, i32} -> {i32}. */
WasmEdge_FunctionTypeContext *HostFType =
WasmEdge_FunctionTypeCreate(ParamList, 2, ReturnList, 1);
Expand All @@ -76,7 +75,7 @@ To create a `host table`, `memory`, and `global` instance, developers can use si
WasmEdge_Limit TabLimit = {
.HasMax = true, .Shared = false, .Min = 10, .Max = 20};
WasmEdge_TableTypeContext *HostTType =
WasmEdge_TableTypeCreate(WasmEdge_RefType_FuncRef, TabLimit);
WasmEdge_TableTypeCreate(WasmEdge_ValTypeGenFuncRef(), TabLimit);
WasmEdge_TableInstanceContext *HostTable =
WasmEdge_TableInstanceCreate(HostTType);
WasmEdge_TableTypeDelete(HostTType);
Expand All @@ -90,7 +89,7 @@ WasmEdge_MemoryTypeDelete(HostMType);
/* Create a host global exported as "global_i32" and initialized as `666`. */
WasmEdge_GlobalTypeContext *HostGType =
WasmEdge_GlobalTypeCreate(WasmEdge_ValType_I32, WasmEdge_Mutability_Const);
WasmEdge_GlobalTypeCreate(WasmEdge_ValTypeGenI32(), WasmEdge_Mutability_Const);
WasmEdge_GlobalInstanceContext *HostGlobal =
WasmEdge_GlobalInstanceCreate(HostGType, WasmEdge_ValueGenI32(666));
WasmEdge_GlobalTypeDelete(HostGType);
Expand Down
5 changes: 5 additions & 0 deletions docs/embed/c/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ The WasmEdge C API denotes an interface to embed the WasmEdge runtime into a C p

The WasmEdge C API is also the fundamental API for other languages' SDK.

<!-- prettier-ignore -->
:::note
For all WASM example codes used in this chapter, users can convert `wat` to `wasm` through [wat2wasm](https://webassembly.github.io/wabt/demo/wat2wasm/) live tool.
:::

## Quick Start Guide for the WasmEdge Runner

The following is an example of running a WASM file. Assume that the WASM file [fibonacci.wasm](https://github.com/WasmEdge/WasmEdge/raw/master/examples/wasm/fibonacci.wat) is copied into the current directory, and the C file `test_wasmedge.c` is as follows:
Expand Down
7 changes: 3 additions & 4 deletions docs/embed/c/library.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ int main() {
WasmEdge_String ExportName = WasmEdge_StringCreateByCString("extern");
WasmEdge_ModuleInstanceContext *HostModCxt =
WasmEdge_ModuleInstanceCreate(ExportName);
enum WasmEdge_ValType ParamList[2] = {WasmEdge_ValType_I32,
WasmEdge_ValType_I32};
enum WasmEdge_ValType ReturnList[1] = {WasmEdge_ValType_I32};
WasmEdge_ValType ParamList[2] = {WasmEdge_ValTypeGenI32(), WasmEdge_ValTypeGenI32()};
WasmEdge_ValType ReturnList[1] = {WasmEdge_ValTypeGenI32()};
WasmEdge_FunctionTypeContext *HostFType =
WasmEdge_FunctionTypeCreate(ParamList, 2, ReturnList, 1);
WasmEdge_FunctionInstanceContext *HostFunc =
Expand All @@ -79,7 +78,7 @@ int main() {
WasmEdge_Value Returns[1];
/* Function name. */
WasmEdge_String FuncName = WasmEdge_StringCreateByCString("addTwo");
/* Run the WASM function from file. */
/* Run the WASM function from buffer. */
WasmEdge_Result Res = WasmEdge_VMRunWasmFromBuffer(
VMCxt, WASM, sizeof(WASM), FuncName, Params, 2, Returns, 1);

Expand Down
Loading

0 comments on commit 8ad1b5b

Please sign in to comment.