Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #2339 from bandprotocol/owasm-refactor
Browse files Browse the repository at this point in the history
owasm: Refactor runtime code into owasm package
  • Loading branch information
sorawit authored Jul 31, 2020
2 parents ca88d5e + 3d72234 commit 5d38d43
Show file tree
Hide file tree
Showing 24 changed files with 781 additions and 609 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/owasm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ jobs:
with:
toolchain: stable

- name: Install Wabt (wat2wasm)
run: |
wget https://github.com/WebAssembly/wabt/releases/download/1.0.17/wabt-1.0.17-ubuntu.tar.gz
tar -zxf wabt-1.0.17-ubuntu.tar.gz
sudo cp wabt-1.0.17/bin/wat2wasm /usr/local/bin
- name: Check cargo cache
uses: actions/cache@v2
with:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG_UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@

### Owasm

- (chore) [\#2339](https://github.com/bandprotocol/bandchain/pull/2339) Refactor runtime code into owasm package.

### Oracle Binary Encoding (OBI)

### Helpers
Expand Down
105 changes: 98 additions & 7 deletions go-owasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 2 additions & 8 deletions go-owasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ edition = "2018"
crate-type = ["cdylib"]

[dependencies]
parity-wasm = "0.41"
pwasm-utils = "0.12"
wasmer-runtime = "0.17"
wasmer-runtime-core = "0.17"
assert_matches = "1.3.0"
hex = "0.4"
tempfile = "3.1.0"
owasm = { path = "../owasm" }

[profile.release]
opt-level = 3
Expand All @@ -23,6 +17,6 @@ rpath = true
lto = false
debug-assertions = false
codegen-units = 16
panic = 'unwind'
panic = "unwind"
incremental = true
overflow-checks = true
13 changes: 6 additions & 7 deletions go-owasm/Dockerfile.linux
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM centos:centos7

RUN yum -y update
RUN yum -y update
RUN yum -y install clang gcc gcc-c++ make wget

# GET FROM https://github.com/rust-lang/docker-rust-nightly
Expand All @@ -21,10 +21,9 @@ RUN url="https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustu

# PRE-FETCH MANY DEPS
WORKDIR /scratch
COPY Cargo.toml /scratch/
COPY Cargo.lock /scratch/
COPY src /scratch/src
RUN cargo fetch
COPY owasm /scratch/owasm
COPY go-owasm /scratch/go-owasm
RUN cd go-owasm && cargo fetch
# allow non-root user to download more deps later
RUN chmod -R 777 /usr/local/cargo

Expand All @@ -34,11 +33,11 @@ RUN chmod -R 777 /usr/local/cargo
WORKDIR /code
RUN rm -rf /scratch

COPY build/build_linux.sh /opt
COPY go-owasm/build/build_linux.sh /opt
RUN chmod +x /opt/build*

RUN mkdir /.cargo
RUN chmod +rx /.cargo
COPY build/cargo-config /.cargo/config
COPY go-owasm/build/cargo-config /.cargo/config

CMD ["/opt/build_linux.sh"]
10 changes: 10 additions & 0 deletions go-owasm/Dockerfile.linux.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Ignore everything
**

# Allow owasm and go-owasm
!/owasm/**
!/go-owasm/**

# Ignore target folders
/owasm/target
/go-owasm/target
12 changes: 6 additions & 6 deletions go-owasm/Dockerfile.osx
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ RUN chmod -R +rx /opt/osxcross/target/bin

# PRE-FETCH MANY DEPS
WORKDIR /scratch
COPY Cargo.toml /scratch/
COPY Cargo.lock /scratch/
COPY src /scratch/src
RUN cargo fetch
COPY owasm /scratch/owasm
COPY go-owasm /scratch/go-owasm
RUN cd go-owasm && cargo fetch
# allow non-root user to download more deps later
RUN chmod -R 777 /usr/local/cargo
RUN chmod -R 777 /usr/local/rustup

## COPY BUILD SCRIPTS

WORKDIR /code
RUN rm -rf /scratch

COPY build/*.sh /opt/
COPY go-owasm/build/*.sh /opt/
RUN chmod +x /opt/*.sh

RUN mkdir /.cargo
RUN chmod +rx /.cargo
COPY build/cargo-config /.cargo/config
COPY go-owasm/build/cargo-config /.cargo/config

CMD ["/opt/build_osx.sh"]
10 changes: 10 additions & 0 deletions go-owasm/Dockerfile.osx.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Ignore everything
**

# Allow owasm and go-owasm
!/owasm/**
!/go-owasm/**

# Ignore target folders
/owasm/target
/go-owasm/target
8 changes: 4 additions & 4 deletions go-owasm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ USER_ID := $(shell id -u)
USER_GROUP = $(shell id -g)

docker-image-linux:
docker build . -t owasm/go-ext-builder:$(DOCKER_TAG)-linux -f ./Dockerfile.linux
DOCKER_BUILDKIT=1 docker build .. -t owasm/go-ext-builder:$(DOCKER_TAG)-linux -f Dockerfile.linux

docker-image-osx:
docker build . -t owasm/go-ext-builder:$(DOCKER_TAG)-osx -f ./Dockerfile.osx
DOCKER_BUILDKIT=1 docker build .. -t owasm/go-ext-builder:$(DOCKER_TAG)-osx -f Dockerfile.osx

docker-images: docker-image-linux docker-image-osx

# and use them to compile release builds
release:
rm -rf target/release
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code owasm/go-ext-builder:$(DOCKER_TAG)-osx
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd)/..:/code owasm/go-ext-builder:$(DOCKER_TAG)-osx
rm -rf target/release
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code owasm/go-ext-builder:$(DOCKER_TAG)-linux
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd)/..:/code owasm/go-ext-builder:$(DOCKER_TAG)-linux
Binary file modified go-owasm/api/libgo_owasm.dylib
Binary file not shown.
Binary file modified go-owasm/api/libgo_owasm.so
Binary file not shown.
1 change: 1 addition & 0 deletions go-owasm/build/build_linux.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash

cd go-owasm
cargo build --release
cp target/release/deps/libgo_owasm.so api
1 change: 1 addition & 0 deletions go-owasm/build/build_osx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export LIBZ_SYS_STATIC=1
export CC=o64-clang
export CXX=o64-clang++

cd go-owasm
rustup target add x86_64-apple-darwin
cargo build --release --target x86_64-apple-darwin
cp target/x86_64-apple-darwin/release/deps/libgo_owasm.dylib api
4 changes: 2 additions & 2 deletions go-owasm/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ bitflags = false
############## Options for How Your Rust library Should Be Parsed ##############

[parse]
parse_deps = false
# include = []
parse_deps = true
include = ["owasm"]
exclude = []
clean = false
extra_bindings = []
Expand Down
2 changes: 1 addition & 1 deletion go-owasm/src/env.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::error::Error;
use crate::span::Span;
use owasm::core::error::Error;

#[repr(C)]
pub struct env_t {
Expand Down
32 changes: 0 additions & 32 deletions go-owasm/src/error.rs

This file was deleted.

Loading

0 comments on commit 5d38d43

Please sign in to comment.