This is a XuperChain WASM Virtual Machine based on WAVM/WAVM, most of the changes compared to the original repo are that we add gas metering to the wasm code and provide a golang wrapper. All the changes are not invasive to the original WAVM.
C/C++ code compiled with emscripten can run on WAVM without any other resolvers. For other languages it doesn't support yet.
Requirements:
- GCC 5.x
- LLVM 8.0.0 (recommended)
- XuperUnion v3.1
If you try to test the new fetures like gas metering, just do as the original repository tells you : Building WAVM
we also provide a more unix-like way to build:
- install llvm and clang by here, assume your installation directory is ${llvm_install_dir}
- build
cd ${source-to-wavm}
CXX=${llvm_install_dir}/bin/clang++ CC=${llvm_install_dir}/bin/clang LLVMDIR=${llvm_install_dir}/lib/cmake/llvm make
Then run this command, you will get the gas used as the debug output.
./output/wavm-run -d ../Example/hello.wast
XuperChain is pluggable cause almost all the component included is pluggable, so is smart contract virtual machine. There are three steps to make it work.
- Compile WAVM.
cd ${source-to-wavm}
CXX=${llvm_install_dir}/bin/clang++ CC=${llvm_install_dir}/bin/clang LLVMDIR=${llvm_install_dir}/lib/cmake/llvm make
- cd ${source-to-wavm}, run
make
to build the plugin, copy it to the plugins directory, then add or updateplugins.conf
with
"wasm":[{
"subtype":"wavm",
"path": "plugins/vm/wavm.so",
"version": "1.0.0",
"ondemand": false
}]
- Add the configure to xchain.yaml:
wasm:
driver: wavm
external: true
external
means it should be loaded as a plugin.
Be careful that shim
depends on xuperunion
(which should be compiled by enabling GO111MODULE=on without -mod=vendor,
remove the export GOFLAGS=-mod=vendor
from xuperchain's Makefile),
so make sure that shim
requires the same version of xuperunion
who load this plugin,
or an error as below maybe occur:
Warn: plugin open failed!" module=pluginmgr pluginname=wasm
err="plugin.Open(\"plugins/wavm\"): plugin was built with a different version of package github.com/xuperchain/xuperunion/..."
- libWAVM.so: cannot open shared object file: No such file or directory"
libWAVM.so is in the ${source-to-wavm}/WAVM/output by default. so if you intend to deploy wavm.so to other server, you can copy the
libWAVM.so to any directory and set environment LD_LIBRARY_PATH
to this directory.