-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from bandprotocol/alpine-build-static
Support static libs, osxcross aarch64, GitHub action to build libs automatically
- Loading branch information
Showing
16 changed files
with
225 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Build workflow | ||
|
||
on: | ||
push: | ||
branches-ignore: | ||
- 'master' | ||
tags-ignore: | ||
- '**' | ||
paths: | ||
- '.github/workflows/build.yaml' | ||
- 'api/binding.h' | ||
- 'api/libgo_owasm.dylib' | ||
- 'api/libgo_owasm.so' | ||
- 'libgo_owasm/**' | ||
- 'build/**' | ||
- 'Makefile' | ||
|
||
jobs: | ||
build_shared_libs: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Build docker images | ||
run: | | ||
make docker-image-linux | ||
make docker-image-osx | ||
- name: Build shared libs | ||
run: | | ||
make release-linux | ||
make release-osx | ||
- name: Check if there is any change | ||
id: check-diff | ||
run: | | ||
git add -A | ||
git diff HEAD --quiet || echo "diff=true" >> $GITHUB_OUTPUT | ||
- name: Commit and Push libs | ||
if: steps.check-diff.outputs.diff == 'true' | ||
run: | | ||
git config --global user.name 'Builder' | ||
git config --global user.email '[email protected]' | ||
git commit -am "Built shared libs" | ||
git push |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Release workflow | ||
|
||
on: | ||
push: | ||
tags: | ||
- v[0-9]+.* | ||
|
||
jobs: | ||
build_static_libs: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Build docker images | ||
run: | | ||
make docker-image-alpine | ||
- name: Build static libs | ||
run: | | ||
make release-alpine | ||
- name: Collect artifacts | ||
run: | | ||
mkdir artifacts | ||
cp api/libgo_owasm_muslc.x86_64.a artifacts/libgo_owasm_muslc.x86_64.a | ||
- name: Create checksums | ||
working-directory: artifacts | ||
run: sha256sum * > checksums.txt && cat checksums.txt | ||
|
||
- name: Release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
files: | | ||
artifacts/checksums.txt | ||
artifacts/libgo_owasm_muslc.x86_64.a | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,6 @@ | |
|
||
libgo_owasm/target | ||
.DS_Store | ||
|
||
# no static libraries (35MB+) | ||
lib*.a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
//go:build linux && muslc | ||
|
||
package api | ||
|
||
// #cgo LDFLAGS: -Wl,-rpath,${SRCDIR} -L${SRCDIR} -lgo_owasm_muslc -lgmp | ||
import "C" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
//go:build !linux || !muslc | ||
|
||
package api | ||
|
||
// #cgo LDFLAGS: -Wl,-rpath,${SRCDIR} -L${SRCDIR} -lgo_owasm | ||
import "C" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
FROM golang:1.18.8-alpine | ||
|
||
ENV RUSTUP_HOME=/usr/local/rustup \ | ||
CARGO_HOME=/usr/local/cargo \ | ||
PATH=/usr/local/cargo/bin:$PATH | ||
|
||
RUN set -eux \ | ||
&& apk add --no-cache ca-certificates build-base linux-headers gmp-dev gmp git | ||
|
||
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; \ | ||
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* | ||
|
||
# add config cargo | ||
RUN mkdir /.cargo | ||
RUN chmod +rx /.cargo | ||
COPY go-owasm/build/cargo-config /.cargo/config | ||
|
||
CMD ["/opt/build_alpine.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/sh | ||
|
||
cd go-owasm/libgo_owasm | ||
cargo build --release --target x86_64-unknown-linux-musl --example muslc | ||
cp target/x86_64-unknown-linux-musl/release/examples/libmuslc.a ./../api/libgo_owasm_muslc.x86_64.a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,24 @@ | ||
#!/bin/bash | ||
|
||
# ref: https://wapl.es/rust/2019/02/17/rust-cross-compile-linux-to-macos.html | ||
# ref from | ||
## https://wapl.es/rust/2019/02/17/rust-cross-compile-linux-to-macos.html | ||
## https://github.com/CosmWasm/wasmvm/blob/v1.1.1/builders/Dockerfile.cross | ||
export OSXCROSS_MP_INC=1 | ||
export LIBZ_SYS_STATIC=1 | ||
export CC=o64-clang | ||
export CXX=o64-clang++ | ||
|
||
cd go-owasm/libgo_owasm | ||
rustup target add x86_64-apple-darwin | ||
|
||
echo "Starting aarch64-apple-darwin build" | ||
export CC=aarch64-apple-darwin20.4-clang | ||
export CXX=aarch64-apple-darwin20.4-clang++ | ||
cargo build --release --target aarch64-apple-darwin | ||
|
||
echo "Starting x86_64-apple-darwin build" | ||
export CC=o64-clang | ||
export CXX=o64-clang++ | ||
cargo build --release --target x86_64-apple-darwin | ||
cp target/x86_64-apple-darwin/release/deps/libgo_owasm.dylib ./../api | ||
|
||
# Create a universal library with both archs | ||
lipo -output ./../api/libgo_owasm.dylib -create \ | ||
target/x86_64-apple-darwin/release/deps/libgo_owasm.dylib \ | ||
target/aarch64-apple-darwin/release/deps/libgo_owasm.dylib |
Oops, something went wrong.