Coder Social home page Coder Social logo

wasmedge-rustsdk-examples's Introduction

Examples of WasmEdge Rust SDK

All examples have been verified on Ubuntu-20.04/22.04.

Wasm App

This example demonstrates how to create a WebAssembly application and run it as a wasm module over WasmEdge Runtime.

Wasm Library

This example demonstrates how to define a wasm library and call the APIs exported from the wasm library in WasmEdge Runtime.

This example demonstrates how to use external functions in a wasm library, and how to call such a wasm library with WasmEdge Rust SDK.

This example demonstrates how a wasm function defined in one wasm library can be imported and called by another wasm library.

Host Functions

This example demonstrates how to define a native function as a host function with #[host_function] macro, and register it into a WasmEdge Vm and run it over WasmEdge Runtime.

This example demonstrates how to define a native function as a host function with #[host_function] macro. A host context data is used in the host function.

This example demonstrates how to define a host function that takes two arguments of Rust built-in String or string slice type.

This example demonstrates how to define wasm functions, of which the arguments are of Rust built-in types instead of WebAssembly types.

Memory and Table

This example demonstrates how to manipulate linear memory.

This example demonstrates how to use WebAssembly Table and FuncRef together to invoke host functions.

AOT

This example demonstrates how to generate a AOT file with WasmEdge AOT compiler, and then load the file and run the wasm function in AOT mode.

WASI

This example demonstrates how to set environment variables and arguments via WasmEdge wasi interface.

This example demonstrates how to call a wasm function in asynchronous way. Also, it presents the usage of async-wasi interface.

This example presents how to retrieve the socket address information asynchronously.

WASI-NN

This example demonstrates how to perform an object detection task over WasmEdge Runtime.

This example demonstrates how to chat with Llama2 model driven by WasmEdge wasi-nn-ggml backend.

Plugin Development

This example demonstrates how to create a simple plugin with WasmEdge Rust SDK.

This example demonstrates how to create a simple plugin with WasmEdge Rust SDK, and run it with WasmEdge Executor.

Multi-threading

This example demonstrates how to use WasmEdge Rust SDK to create multiple threads to help us render Mandelbrot set in parallel, which is a compute-intensive workload. This example also present sharing the image memory between threads while rendering the image parallelly.

Async\await

This example demonstrates how to define a native async function as an async host function with #[async_host_function] macro, and register it into a WasmEdge Vm and run it over WasmEdge Runtime.

This example demonstrates how to define a native async function as an async host function with #[async_host_function] macro. A host context data is used in the host function.

This example demonstrates how to call a wasm function in asynchronous way.

wasmedge-rustsdk-examples's People

Contributors

apepkuss avatar samaddotdev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

wasmedge-rustsdk-examples's Issues

[QUESTION] How to pass `&[u8]` from Rust to Go?

For example, I've written some Go codes and compiled as WASM:

//export md5
func Md5(input []byte) string {
    // return md5 crypto...
}

// compile and got md5.wasm

In the rust wasmedge sdk:

// init vm and load md5.wasm above....

let mut b = Vec::from(&b"foobar"[..]);


let result = vm.run_func(
        Some("extern"),
        "md5",
        params // <------- How to pass `b` ???
    )?;

Cannot run examples

Hi there,

I am attempting to run a simple Rust SDK example, but getting the error:

error[E0425]: cannot find function, tuple struct or tuple variant WasmEdge_PluginLoadFromPath in module ffi
--> /home/neliusdelange/.cargo/registry/src/github.com-1ecc6299db9ec823/wasmedge-sys-0.13.0/src/plugin.rs:40:23
|
40 | unsafe { ffi::WasmEdge_PluginLoadFromPath(c_path.as_ptr()) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in ffi

Please assist.

Thank you
Nelius

Can't access host function in wasm lib

first I registered the host function

let import = ImportObjectBuilder::new()
                .with_func::<(ExternRef, ExternRef), (), NeverType>("kv_set", kv_set, None)
                .unwrap()
                .build::<NeverType>("extern", None)
                .unwrap();
            (
                VmBuilder::new()
                    .with_config(config)
                    .build()
                    .expect("failed to create vm")
                    .register_import_module(import)
                    .unwrap()
                    .register_module(Some(container_name), module)
                    .unwrap(),

in wasm lib I try to access the kv_set function

#[allow(unused_imports)]
use wasmedge_bindgen::*;
use wasmedge_bindgen_macro::*;

extern "C" {
    fn kv_set(x: Vec<u8>) -> Vec<u8>;
}

pub fn kv_set_wrapper(x: Vec<u8>) -> Vec<u8> {
    unsafe { kv_set(x) }
}

#[wasmedge_bindgen]
pub fn fn2() {
    kv_set_wrapper(Vec::new());
    println!("helloworld");
}

However I get
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.