diff --git a/docs/contribute/plugin/intro.md b/docs/contribute/plugin/intro.md index 08cf4a09a..515c64e1c 100644 --- a/docs/contribute/plugin/intro.md +++ b/docs/contribute/plugin/intro.md @@ -14,9 +14,48 @@ 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). +### Creating Loadable Plug-in + +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. By following the provided examples and leveraging the SDK's APIs, developers can easily build custom plugins tailored to their specific needs. + +### Loading plug-in from paths + +To make use of the loadable plugins, developers need to load them from specific paths into the WasmEdge runtime environment. The loading process involves the following steps: + +- Loadable plugins can be loaded from default paths by calling the `WasmEdge_PluginLoadWithDefaultPaths()` API. The default paths include: + + - The path specified in the environment variable `WASMEDGE_PLUGIN_PATH`. + - The `../plugin/` directory relative to the WasmEdge installation path. + - The `./wasmedge/` directory located under the library path if WasmEdge is installed in a system directory such as `/usr` and `/usr/local`. + +- If the plugins are located in a specific path or directory, developers can use the `WasmEdge_PluginLoadFromPath("PATH_TO_PLUGIN/plugin.so")` API to load the plugins from that particular location. + +The WasmEdge runtime environment will search for the loadable plugins in the specified paths and load them if found. + +### Plugin Loading Flowchart + +The following flowchart depicts the process of loading loadable plugins into the WasmEdge runtime environment from specific paths: + +```mermaid +graph LR + A((Start)) --> B(Loadable Plugins) + B --> C{Load Plugins} + C --> D[Load from Default Paths] + C --> E[Load from Specific Path] + C --> F[Load from Specific Directory] + D --> G{Is Plugin Found?} + E --> G + F --> G + G -- Yes --> H(Load Plugin) + H --> I(End) + G -- No --> I +``` + +The flowchart shows the process of loading loadable plugins into the WasmEdge runtime environment. The process involves searching for plugins in default paths, a specific path, or a specific directory. If a plugin is found in any of these locations, it is loaded into the runtime environment. The flowchart enables developers to easily load plugins and extend the capabilities of the WasmEdge runtime. + +By following this flowchart, developers can effectively load loadable plugins into the WasmEdge runtime environment from specific paths, expanding the runtime's functionality according to their requirements. ## WasmEdge Currently Released Plug-ins