Skip to content

Update Loadable Plug-in section #86

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

Closed
wants to merge 5 commits into from
Closed
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
35 changes: 33 additions & 2 deletions docs/contribute/plugin/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,40 @@ In current, developers can follow the guides to implement the plug-ins in [C API

## Loadable Plug-in

Loadable plugin is a standalone `.so`/`.dylib`/`.dll` file that WasmEdge can load during runtime environment, and provide modules to be imported.
Loadable plugins are standalone shared libraries (`.so`/`.dylib`/`.dll` files) that can be loaded by the WasmEdge runtime environment at runtime. These plugins can provide additional functionality to the WasmEdge runtime environment, such as new modules that can be imported by WebAssembly modules.

Please [refer to the plugin example code](https://github.com/WasmEdge/WasmEdge/tree/master/examples/plugin/get-string).
To create a loadable plugin for WasmEdge, developers can use the WasmEdge Plugin SDK, which provides a set of Rust, C and C++ APIs for creating and registering plugins. The SDK also includes [example code](https://github.com/WasmEdge/WasmEdge/tree/master/examples/plugin/get-string) that demonstrates how to create a simple plugin that returns a string.

Once a loadable plugin has been created, it can be loaded by the WasmEdge runtime environment using the WasmEdge_LoadWasmFromFile or WasmEdge_LoadWasmFromBuffer API. The plugin can then be used to provide functionality to WebAssembly modules, such as access to system resources or specialized hardware.

Here's a flowchart that shows the basic steps involved in creating and using a loadable plugin in WasmEdge:

<div style="text-align: center;">
<div class="mermaid">
graph TD
A[Create Plugin]
B[Compile Plugin]
C[Load Plugin]
D[Register Plugin]
E[Load WebAssembly Module]
F[Import Plugin Module]
G[Execute WebAssembly Module]
A --> B
B --> C
C --> D
D --> E
E --> F
F --> G
</div>
</div>

This flowchart shows the basic steps involved in creating and using a loadable plugin in WasmEdge. The first step is to create the plugin, which involves writing the code for the plugin functions and compiling the code into a shared library.

Once the plugin has been compiled, it can be loaded by the WasmEdge runtime environment using the `WasmEdge_LoadWasmFromFile` or `WasmEdge_LoadWasmFromBuffer` API. The plugin can then be registered with the runtime environment using the `WasmEdge_RegisterImport` API.

After the plugin has been registered, a WebAssembly module can be loaded using the `WasmEdge_LoadWasmFromFile` or `WasmEdge_LoadWasmFromBuffer` API. The module can then import the plugin module using the `WasmEdge_VMRegisterModule` API.

Finally, the WebAssembly module can execute its functions, which may call the functions provided by the plugin module. The plugin functions can then perform their specific tasks, such as accessing system resources or specialized hardware.

## WasmEdge Currently Released Plug-ins

Expand Down