Go-owasm, is a repository designed as a Go wrapper for the owasm-vm, enabling seamless compilation and execution of Oracle scripts within Go. This project primarily caters to the x/oracle module in BandChain.
This repository contains code written in both Rust and Go. The Rust code is compiled to produce a library (.dylib
, .so
, .a
). This library is then linked via cgo and encapsulated within Go. The build process involves compiling the Rust code into a C library and subsequently linking that library with the Go code. Additionally, pre-compiled libraries are included, facilitating users to import the package and directly utilize the library.
The ./libgo_owasm
directory contains Rust code, which is compiled into a library compatible with cgo, thereby enabling its usage within Golang. Please refer to the instructions for compiling it here.
The ./api
directory, section comprises Go code that interfaces with the library from libgo_owasm. It also incorporates the pre-compiled libraries within the folder.
The ./build
directory contains scripts and docker files for building the library from Rust code.
The ./github
directory, section contains GitHub Action code that aids in testing, building libraries, and releasing packages.
If you make updates to owasm-vm or the Rust code, it's essential to generate bindings.sh and compile libraries to update the compiled library within the project, thereby ensuring the go-owasm package incorporates the latest version of the Owasm-vm library.
cd libgo_owasm && cargo build --release
Currently, the libraries can only be built on Linux and OS X using x86_64 architecture. If you are operating on an unsupported platform, you can push the code to GitHub to trigger a suite of GitHub Actions which will test and compile the library for you.
You can use the commands below to build the libraries on Linux (x86_64) and OS X (x86_64).
# Run test
cd libgo_owasm && cargo test
# Build docker images used to compile the Rust code
make docker-images
# Run the docker images to build the libraries
make releases