Skip to content

Commit

Permalink
Update owasm version, rust version, optimize build image time (#26)
Browse files Browse the repository at this point in the history
* update rust version, optimize build image time

* parallel build

* Built shared lib - linux

* add git pull

* add git pull

* Built shared lib - linux

* use artifact

* use artifact

* change source

* Built shared lib - osx

* use pre-built image

* use pre-built image

* use image from docker hub

* Built shared libs

* update version

* change docker image

* Adjust read me (#25)

* adjust read me

* adjust wording

* fix

* Update README.md

Co-authored-by: warittornc <69615455+warittornc@users.noreply.github.com>

* Update README.md

Co-authored-by: warittornc <69615455+warittornc@users.noreply.github.com>

* fix

* Update README.md

Co-authored-by: warittornc <69615455+warittornc@users.noreply.github.com>

* Update README.md

Co-authored-by: warittornc <69615455+warittornc@users.noreply.github.com>

* remove extra space

---------

Co-authored-by: warittornc <69615455+warittornc@users.noreply.github.com>

* use stable version

* update owasm to v0.3.1 (#23)

* update owasm to v0.3.1

* Empty-Commit

* Built shared libs

---------

Co-authored-by: Kitipong Sirirueangsakul <kitipong.sirir@gmail.com>
Co-authored-by: Builder <go-owasm@users.noreply.github.com>

---------

Co-authored-by: Builder <go-owasm@users.noreply.github.com>
Co-authored-by: warittornc <69615455+warittornc@users.noreply.github.com>
Co-authored-by: Ongart Pisansathienwong <ongart.pisan@gmail.com>
  • Loading branch information
4 people authored Apr 30, 2024
1 parent 16d3f80 commit b70f190
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 65 deletions.
49 changes: 44 additions & 5 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,61 @@ on:
- 'Makefile'

jobs:
build_shared_libs:
build_shared_lib_linux:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Build docker images
- name: Build shared libs
run: |
make docker-image-linux
make docker-image-osx
make release-linux
- name: Push artifact
uses: actions/upload-artifact@v3
with:
name: libgo_owasm.so
path: api/libgo_owasm.so
retention-days: 1

build_shared_lib_osx:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Build shared libs
run: |
make release-linux
make release-osx
- name: Push artifact
uses: actions/upload-artifact@v3
with:
name: libgo_owasm.dylib
path: api/libgo_owasm.dylib
retention-days: 1

push:
needs:
- build_shared_lib_linux
- build_shared_lib_osx
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Download libgo_owasm.so
uses: actions/download-artifact@v3
with:
name: libgo_owasm.so
path: api

- name: Download libgo_owasm.dylib
uses: actions/download-artifact@v3
with:
name: libgo_owasm.dylib
path: api

- name: Check if there is any change
id: check-diff
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ jobs:
- name: Install Rust and rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
toolchain: stable
override: true

- name: Install Go
uses: actions/setup-go@v3
with:
go-version: '^1.18.3'
go-version: '^1.20.10'

- name: Install Wabt (wat2wasm)
run: |
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Build docker images
run: |
make docker-image-alpine
- name: Build static libs
run: |
make release-alpine
Expand Down
27 changes: 19 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@
.PHONY: docker-images docker-image-linux docker-image-osx

DOCKER_IMAGE := bandprotocol/go-owasm-ext-builder
DOCKER_TAG := 0.0.1
USER_ID := $(shell id -u)
USER_GROUP = $(shell id -g)
USER_GROUP := $(shell id -g)

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

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

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

docker-images: docker-image-osx docker-image-linux docker-image-alpine
docker-images:
make docker-image-osx
make docker-image-linux
make docker-image-alpine

docker-publish:
docker push $(DOCKER_IMAGE):$(DOCKER_TAG)-alpine
docker push $(DOCKER_IMAGE):$(DOCKER_TAG)-linux
docker push $(DOCKER_IMAGE):$(DOCKER_TAG)-osx

# Creates a release build in a containerized build environment of the static library for Alpine Linux (.a)
release-alpine:
rm -rf libgo_owasm/target/release
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code/go-owasm owasm/go-ext-builder:$(DOCKER_TAG)-alpine
rm -rf libgo_owasm/target/x86_64-unknown-linux-musl/release
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code/go-owasm $(DOCKER_IMAGE):$(DOCKER_TAG)-alpine build_alpine.sh

# Creates a release build in a containerized build environment of the shared library for glibc Linux (.so)
release-linux:
rm -rf libgo_owasm/target/release
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code/go-owasm owasm/go-ext-builder:$(DOCKER_TAG)-linux
rm -rf libgo_owasm/target/x86_64-unknown-linux-gnu/release
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code/go-owasm $(DOCKER_IMAGE):$(DOCKER_TAG)-linux build_linux.sh

# Creates a release build in a containerized build environment of the shared library for macOS (.dylib)
release-osx:
rm -rf libgo_owasm/target/release
rm -rf libgo_owasm/target/x86_64-apple-darwin/release
rm -rf libgo_owasm/target/aarch64-apple-darwin/release
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code/go-owasm owasm/go-ext-builder:$(DOCKER_TAG)-osx
docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code/go-owasm $(DOCKER_IMAGE):$(DOCKER_TAG)-osx build_osx.sh

releases:
make release-alpine
Expand Down
Binary file modified api/libgo_owasm.dylib
100755 → 100644
Binary file not shown.
Binary file modified api/libgo_owasm.so
100755 → 100644
Binary file not shown.
19 changes: 6 additions & 13 deletions build/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.18.8-alpine
FROM golang:1.20.10-alpine

ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
Expand All @@ -9,36 +9,29 @@ RUN set -eux \

RUN wget "https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-musl/rustup-init"; \
chmod +x rustup-init; \
./rustup-init -y --no-modify-path --default-toolchain 1.60.0; \
./rustup-init -y --no-modify-path --default-toolchain 1.73.0; \
rm rustup-init; \
chmod -R a+w $RUSTUP_HOME $CARGO_HOME;

# prepare go cache dirs
RUN mkdir -p /.cache/go-build
RUN chmod -R 777 /.cache

# pre-fetch many deps
WORKDIR /scratch
COPY go-owasm /scratch/go-owasm
RUN cd go-owasm/libgo_owasm && cargo fetch

# allow non-root user to download more deps later
RUN chmod -R 777 /usr/local/cargo

# cleanup
WORKDIR /code
RUN rm -rf /scratch

# add musl Rust targets
RUN rustup target add x86_64-unknown-linux-musl

# copy build scripts
COPY go-owasm/build/build_alpine.sh /opt
RUN chmod +x /opt/build*
COPY build/*.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/*.sh

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

CMD ["/opt/build_alpine.sh"]
CMD ["bash", "-c", "echo 'Argument missing. Pass one build script (e.g. build_alpine.sh) to docker run' && exit 1"]
19 changes: 6 additions & 13 deletions build/Dockerfile.linux
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,25 @@ ENV RUSTUP_HOME=/usr/local/rustup \
RUN url="https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init"; \
wget "$url"; \
chmod +x rustup-init; \
./rustup-init -y --no-modify-path --default-toolchain 1.60.0; \
./rustup-init -y --no-modify-path --default-toolchain 1.73.0; \
rm rustup-init; \
chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \
rustup --version; \
cargo --version; \
rustc --version;

# pre-fetch many deps
WORKDIR /scratch
COPY go-owasm /scratch/go-owasm
RUN cd go-owasm/libgo_owasm && cargo fetch

# allow non-root user to download more deps later
RUN chmod -R 777 /usr/local/cargo

# cleanup
# setup workdir
WORKDIR /code
RUN rm -rf /scratch

# copy build scripts
COPY go-owasm/build/build_linux.sh /opt
RUN chmod +x /opt/build*
COPY build/*.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/*.sh

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

CMD ["/opt/build_linux.sh"]
CMD ["bash", "-c", "echo 'Argument missing. Pass one build script (e.g. build_linux.sh) to docker run' && exit 1"]
20 changes: 7 additions & 13 deletions build/Dockerfile.osx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.60.0-bullseye
FROM rust:1.73.0-bullseye

ENV PATH=/opt/osxcross/target/bin:$PATH

Expand All @@ -21,7 +21,7 @@ RUN git clone https://github.com/tpoechtrager/osxcross \
&& mv MacOSX11.3.sdk.tar.xz tarballs/ \
&& UNATTENDED=yes OSX_VERSION_MIN=10.10 ./build.sh \
# install gmp
&& echo "1" | MACOSX_DEPLOYMENT_TARGET=11.3 ./tools/osxcross-macports install gmp \
&& echo "2" | MACOSX_DEPLOYMENT_TARGET=11.3 ./tools/osxcross-macports install gmp \
# cleanups before Docker layer is finalized
&& rm -r tarballs/
RUN chmod +rx /opt/osxcross
Expand All @@ -30,26 +30,20 @@ RUN chmod -R +rx /opt/osxcross/target/bin
RUN /opt/osxcross/target/bin/x86_64-apple-darwin20.4-clang --version
RUN /opt/osxcross/target/bin/aarch64-apple-darwin20.4-clang --version

# pre-fetch many deps
WORKDIR /scratch
COPY go-owasm /scratch/go-owasm
RUN cd go-owasm/libgo_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

# cleanup
# setup workdir
WORKDIR /code
RUN rm -rf /scratch

# copy build scripts
COPY go-owasm/build/*.sh /opt/
RUN chmod +x /opt/*.sh
COPY build/*.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/*.sh

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

CMD ["/opt/build_osx.sh"]
CMD ["bash", "-c", "echo 'Argument missing. Pass one build script (e.g. build_osx.sh) to docker run' && exit 1"]
12 changes: 6 additions & 6 deletions libgo_owasm/Cargo.lock

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

2 changes: 1 addition & 1 deletion libgo_owasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ path = "src/lib.rs"
crate-type = ["staticlib"]

[dependencies]
owasm-vm = "0.2.2"
owasm-vm = "0.3.1"
failure = "0.1.6"

[build-dependencies]
Expand Down

0 comments on commit b70f190

Please sign in to comment.