Giter Site home page Giter Site logo

startime-h / wasmedge Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wasmedge/wasmedge

0.0 0.0 0.0 4.08 MB

WasmEdge Runtime is a high-performance, extensible, and hardware optimized WebAssembly Virtual Machine for cloud, AI, and blockchain applications.

Home Page: https://WasmEdge.org

License: Apache License 2.0

CMake 1.61% C++ 70.01% WebAssembly 27.27% Shell 0.10% C 0.36% Rust 0.65%

wasmedge's Introduction

Introduction

WasmEdge (formerly SSVM) is a high performance and enterprise-ready WebAssembly (WASM) Virtual Machine for cloud, AI, and Blockchain applications. Its use cases include the following.

WasmEdge is hosted by the Cloud Native Computing Foundation (CNCF) as a sandbox project. For the information on related tools and the WasmEdge ecosystem, please refer to the WasmEdge ecosystem documentation.

build Total alerts Language grade: C/C++ codecov

Getting Started

Get Source Code

$ git clone [email protected]:WasmEdge/WasmEdge.git
$ cd WasmEdge
$ git checkout 0.8.0

Prepare the environment

Use our docker image

Our docker image use ubuntu 20.04 as the base.

$ docker pull wasmedge/wasmedge

Or setup the environment manually

# Tools and libraries
$ sudo apt install -y \
	software-properties-common \
	cmake \
	libboost-all-dev

# And you will need to install llvm for wasmedgec tool
$ sudo apt install -y \
	llvm-dev \
	liblld-10-dev

# WasmEdge supports both clang++ and g++ compilers
# You can choose one of them for building this project
$ sudo apt install -y gcc g++
$ sudo apt install -y clang

Support for legacy operating systems

Our development environment requires libLLVM-10 and >=GLIBCXX_3.4.26.

If users are using the older operating system than Ubuntu 20.04, please use our special docker image to build WasmEdge. If you are looking for the pre-built binaries for the older operatoring system, we also provide several pre-built binaries based on manylinux* distribution.

Portable Linux Built Distributions Tags Base Image Provided Requirements Docker Image
manylinux1 CentOS 5.11 GLIBC <= 2.5
CXXABI <= 3.4.8
GLIBCXX <= 3.4.9
GCC <= 4.2.0
wasmedge/wasmedge:manylinux1_x86_64
manylinux2010 CentOS 6 GLIBC <= 2.12
CXXABI <= 1.3.3
GLIBCXX <= 3.4.13
GCC <= 4.5.0
wasmedge/wasmedge:manylinux2010_x86_64
manylinux2014 CentOS 7 GLIBC <= 2.17
CXXABI <= 1.3.7
GLIBCXX <= 3.4.19
GCC <= 4.8.0
wasmedge/wasmedge:manylinux2014_x86_64

If you don't want to build Ahead-of-Time runtime/compiler

If users don't need Ahead-of-Time runtime/compiler support, they can set the CMake option BUILD_AOT_RUNTIME to OFF.

$ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_AOT_RUNTIME=OFF ..

Build WasmEdge

WasmEdge provides various tools for enabling different runtime environments for optimal performance. After the build is finished, you can find there are several wasmedge related tools:

  1. wasmedge is for general wasm runtime.
    • wasmedge executes a WASM file in interpreter mode or a compiled WASM so file in ahead-of-time compilation mode.
    • To disable building all tools, you can set the CMake option BUILD_TOOLS to OFF.
  2. wasmedgec is for ahead-of-time WASM compiler.
    • wasmedgec compiles a general WASM file into a so file.
    • To disable building the ahead-of-time compiler only, you can set the CMake option BUILD_AOT_RUNTIME to OFF.
    • To disable building all tools, you can set the CMake option BUILD_TOOLS to OFF.
  3. libwasmedge_c.so is the WasmEdge C API shared library.
    • libwasmedge_c.so provides C API for the ahead-of-time compiler and the WASM runtime.
    • The APIs about the ahead-of-time compiler will always return failed if the CMake option BUILD_AOT_RUNTIME is set as OFF.
    • To disable building the shared library only, you can set the CMake option BUILD_SHARED_LIB to OFF.
  4. ssvm-qitc is for AI application, supporting ONNC runtime for AI model in ONNX format.
# After pulling our wasmedge docker image
$ docker run -it --rm \
    -v <path/to/your/wasmedge/source/folder>:/root/wasmedge \
    wasmedge/wasmedge:latest
(docker)$ cd /root/wasmedge
(docker)$ mkdir -p build && cd build
(docker)$ cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=ON .. && make -j

Run built-in tests

The following built-in tests are only available when the build flag BUILD_TESTS sets to ON.

Users can use these tests to verify the correctness of WasmEdge binaries.

$ cd <path/to/wasmedge/build_folder>
$ LD_LIBRARY_PATH=$(pwd)/lib/api ctest

Run wasmedge (WasmEdge with general wasm runtime)

To run WasmEdge with general wasm runtime, users will need to provide the following parameters:

  1. (Optional) Reactor mode: use --reactor to enable reactor mode.
    • WasmEdge will execute the function which name should be given in ARG[0].
    • If there's exported function which names _initialize, the function will be executed with the empty parameter at first.
  2. (Optional) Binding directories into WASI virtual filesystem.
    • Each directory can be specified as --dir host_path:guest_path.
  3. (Optional) Environ variables.
    • Each variable can be specified as --env NAME=VALUE.
  4. Wasm file(/path/to/wasm/file).
  5. (Optional) Arguments.
    • In reactor mode, the first argument will be the function name, and the arguments after ARG[0] will be parameters of wasm function ARG[0].
    • In command mode, the arguments will be parameters of function _start.

Example: Fibonacci

# cd <path/to/wasmedge/build_folder>
$ cd tools/wasmedge
# ./wasmedge [-h|--help] [-v|--version] [--reactor] [--dir PREOPEN_DIRS ...] [--env ENVS ...] [--enable-bulk-memory] [--enable-reference-types] [--enable-simd] [--enable-all] [--allow-command COMMANDS ...] [--allow-command-all] [--] WASM_OR_SO [ARG ...]
$ ./wasmedge --reactor examples/fibonacci.wasm fib 10
89

When wrong number of parameter given, the following error message is printed.

$ ./wasmedge --reactor examples/fibonacci.wasm fib 10 10
2020-08-21 06:30:37,304 ERROR [default] execution failed: function signature mismatch, Code: 0x83
2020-08-21 06:30:37,304 ERROR [default]     Mismatched function type. Expected: params{i32} returns{i32} , Got: params{i32 , i32} returns{i32}
2020-08-21 06:30:37,304 ERROR [default]     When executing function name: "fib"

When calling unknown exported function, the following error message is printed.

$ ./wasmedge --reactor examples/fibonacci.wasm fib2 10
2020-08-21 06:30:56,981 ERROR [default] wasmedge runtime failed: wasm function not found, Code: 0x04
2020-08-21 06:30:56,981 ERROR [default]     When executing function name: "fib2"

Example: Factorial

# ./wasmedge [-h|--help] [-v|--version] [--reactor] [--dir PREOPEN_DIRS ...] [--env ENVS ...] [--enable-bulk-memory] [--enable-reference-types] [--enable-simd] [--enable-all] [--allow-command COMMANDS ...] [--allow-command-all] [--] WASM_OR_SO [ARG ...]
$ ./wasmedge --reactor examples/factorial.wasm fac 5
120

Related tools

Note: Some of those tools are stilling using WasmEdge's old name "SSVM". We are renaming those repos, artifacts, and docs when we make new releases on those projects.

rustwasmc

The rustwasmc is a one-stop tool for building Rust functions into WebAssembly for deployment on the WasmEdge Runtime.

SSVM-EVMC

SSVM-EVMC provides support for Ewasm runtime which is compatible with EVMC.

This project provides a shared library that can initialize and execute by the EVMC interface.

SSVM nodejs addon

SSVM-napi provides support for accessing WasmEdge as a Node.js addon.

It allows Node.js applications to call WebAssembly functions written in Rust or other high-performance languages.

Why do you want to run WebAssembly on the server-side?

The WasmEdge addon could interact with the wasm files generated by the rustwasmc compiler tool.

SSVM-TensorFlow

SSVM-TensorFlow provides support for accessing with TensorFlow C library.

This project provides a tool that can execute WASM with TensorFlow extension compiled from Rust ssvm_tensorflow_interface.

DevChain

The Second State DevChain features a powerful and easy-to-use virtual machine that can quickly get you started with the smart contract and DApp development.

SSVM-evmc is integrated into our DevChain. Click here to learn how to run an ewasm smart contract on a real blockchain.

Customized Host Functions

Design document shows how to register customized host functions into WasmEdge and execute with wasm files.

wasmedge's People

Contributors

q82419 avatar ibmibmibm avatar hydai avatar lfswang avatar dm4 avatar 0yi0 avatar luishsu avatar alabulei1 avatar juntao avatar tpmccallum avatar

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.