From e6664e9a1890fe9ed641a7c58cb5aff52b85e4b9 Mon Sep 17 00:00:00 2001 From: Yongwoo Lee Date: Fri, 1 Oct 2021 13:30:14 +0900 Subject: [PATCH 1/2] feat: change tag name for static build - change tag name: muslc -> static - unify link_muslc.go and link_static.go -> link_static.go - update build files: Dockerfile, Makefile --- Makefile | 10 +++++++--- api/link_muslc.go | 7 ------- api/link_static.go | 4 ++-- api/link_std.go | 4 ++-- builders/Dockerfile.alpine | 2 +- builders/Dockerfile.static | 23 ++++++++++++++++++++--- builders/Makefile | 28 ++++++++++++++++------------ builders/guest/build_linux_static.sh | 4 +--- 8 files changed, 49 insertions(+), 33 deletions(-) delete mode 100644 api/link_muslc.go diff --git a/Makefile b/Makefile index e3712fb4..b03915c8 100644 --- a/Makefile +++ b/Makefile @@ -61,13 +61,17 @@ release-build-alpine: # build the muslc *.a file docker run --rm -v $(shell pwd):/code $(BUILDERS_PREFIX):alpine # try running go tests using this lib with muslc - docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code -w /code $(BUILDERS_PREFIX):alpine go build -tags muslc . - docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code -w /code $(BUILDERS_PREFIX):alpine go test -tags='muslc mocks' ./api ./types + docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code -w /code $(BUILDERS_PREFIX):alpine go build -tags static . + docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code -w /code $(BUILDERS_PREFIX):alpine go test -tags='static mocks' ./api ./types # Creates a release build in a containerized build environment of the static library for glibc Linux (.a) release-build-linux-static: rm -rf target/release + # build the glibc *.a file docker run --rm -v $(shell pwd):/code $(BUILDERS_PREFIX):static + # try running go tests using this lib with glibc + docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code -w /code $(BUILDERS_PREFIX):static go build -tags static . + docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code -w /code $(BUILDERS_PREFIX):static go test -tags='static mocks' ./api ./types # Creates a release build in a containerized build environment of the shared library for glibc Linux (.so) release-build-linux: @@ -88,7 +92,7 @@ release-build: test-alpine: release-build-alpine # build a go binary - docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code -w /code $(BUILDERS_PREFIX)-alpine go build -tags='muslc mocks' -o muslc.exe ./cmd + docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code -w /code $(BUILDERS_PREFIX):alpine go build -tags='static mocks' -o muslc.exe ./cmd # run static binary in an alpine machines (not dlls) docker run --rm --read-only -v $(shell pwd):/code -w /code alpine:3.12 ./muslc.exe ./api/testdata/hackatom.wasm docker run --rm --read-only -v $(shell pwd):/code -w /code alpine:3.11 ./muslc.exe ./api/testdata/hackatom.wasm diff --git a/api/link_muslc.go b/api/link_muslc.go deleted file mode 100644 index dfcb28f9..00000000 --- a/api/link_muslc.go +++ /dev/null @@ -1,7 +0,0 @@ -//go:build linux && muslc && !static -// +build linux,muslc,!static - -package api - -// #cgo LDFLAGS: -Wl,-rpath,${SRCDIR} -L${SRCDIR} -lwasmvm_muslc -import "C" diff --git a/api/link_static.go b/api/link_static.go index 874c3672..08f3f718 100644 --- a/api/link_static.go +++ b/api/link_static.go @@ -1,5 +1,5 @@ -//go:build linux && !muslc && static -// +build linux,!muslc,static +//go:build linux && static +// +build linux,static package api diff --git a/api/link_std.go b/api/link_std.go index 6c8ade27..a530ec0f 100644 --- a/api/link_std.go +++ b/api/link_std.go @@ -1,5 +1,5 @@ -//go:build (linux && !muslc && !static) || darwin -// +build linux,!muslc,!static darwin +//go:build (linux && !static) || darwin +// +build linux,!static darwin package api diff --git a/builders/Dockerfile.alpine b/builders/Dockerfile.alpine index dd8af2ce..1617e12b 100644 --- a/builders/Dockerfile.alpine +++ b/builders/Dockerfile.alpine @@ -41,4 +41,4 @@ RUN mkdir /.cargo RUN chmod +rx /.cargo COPY guest/cargo-config /.cargo/config -CMD ["/opt/build_linux_static.sh", "muslc"] +CMD ["/opt/build_linux_static.sh"] diff --git a/builders/Dockerfile.static b/builders/Dockerfile.static index e4e52cdb..53bd4f49 100644 --- a/builders/Dockerfile.static +++ b/builders/Dockerfile.static @@ -1,8 +1,25 @@ # > docker build -t line/wasmvm-builder:static -f Dockerfile.static . -FROM rust:1.53 +FROM golang:1.15 -COPY . /code +ENV RUSTUP_HOME=/usr/local/rustup \ + CARGO_HOME=/usr/local/cargo \ + PATH=/usr/local/cargo/bin:$PATH + +WORKDIR /tmp +RUN wget "https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init" +RUN chmod +x rustup-init +RUN ./rustup-init -y --no-modify-path --default-toolchain 1.53.0; rm rustup-init +RUN chmod -R a+w $RUSTUP_HOME $CARGO_HOME + +# prepare go cache dirs +RUN mkdir -p /.cache/go-build +RUN chmod -R 777 /.cache + +# allow non-root user to download more deps later +RUN chmod -R 777 /usr/local/cargo + +## COPY BUILD SCRIPTS WORKDIR /code COPY guest/*.sh /opt/ @@ -12,4 +29,4 @@ RUN mkdir /.cargo RUN chmod +rx /.cargo COPY guest/cargo-config /.cargo/config -ENTRYPOINT ["/opt/build_linux_static.sh"] +CMD ["/opt/build_linux_static.sh"] diff --git a/builders/Makefile b/builders/Makefile index 4e4e5830..427c09ef 100644 --- a/builders/Makefile +++ b/builders/Makefile @@ -1,24 +1,28 @@ -# Versioned by a simple counter that is not bound to a specific CosmWasm version -# See builders/README.md -BUILDERS_PREFIX := cosmwasm/go-ext-builder:0006 +BUILDERS_PREFIX := line/wasmvm-builder .PHONY: docker-image-centos7 docker-image-centos7: - docker build . -t $(BUILDERS_PREFIX)-centos7 -f ./Dockerfile.centos7 + docker build . -t $(BUILDERS_PREFIX):centos7 -f ./Dockerfile.centos7 .PHONY: docker-image-cross docker-image-cross: - docker build . -t $(BUILDERS_PREFIX)-cross -f ./Dockerfile.cross + docker build . -t $(BUILDERS_PREFIX):cross -f ./Dockerfile.cross .PHONY: docker-image-alpine docker-image-alpine: - docker build . -t $(BUILDERS_PREFIX)-alpine -f ./Dockerfile.alpine + docker build . -t $(BUILDERS_PREFIX):alpine -f ./Dockerfile.alpine + +.PHONY: docker-image-static +docker-image-static: + docker build . -t $(BUILDERS_PREFIX):static -f ./Dockerfile.static .PHONY: docker-images -docker-images: docker-image-centos7 docker-image-cross docker-image-alpine +docker-images: docker-image-centos7 docker-image-cross docker-image-alpine docker-image-static -.PHONY: docker-publish -docker-publish: docker-images - docker push $(BUILDERS_PREFIX)-cross - docker push $(BUILDERS_PREFIX)-centos7 - docker push $(BUILDERS_PREFIX)-alpine +# TODO publish images to registry +# .PHONY: docker-publish +# docker-publish: docker-images +# docker push $(BUILDERS_PREFIX):cross +# docker push $(BUILDERS_PREFIX):centos7 +# docker push $(BUILDERS_PREFIX):alpine +# docker push $(BUILDERS_PREFIX):static diff --git a/builders/guest/build_linux_static.sh b/builders/guest/build_linux_static.sh index a84f4517..0e74750e 100755 --- a/builders/guest/build_linux_static.sh +++ b/builders/guest/build_linux_static.sh @@ -1,6 +1,4 @@ #!/bin/sh -TARGET_NAME="${1:-static}" - cargo build --release --example staticlib -cp /code/target/release/examples/libstaticlib.a "/code/api/libwasmvm_$TARGET_NAME.a" +cp /code/target/release/examples/libstaticlib.a "/code/api/libwasmvm_static.a" From 1ac574f1f5f81ad043d93a47f74d76a0c88c4b5b Mon Sep 17 00:00:00 2001 From: Yongwoo Lee Date: Fri, 1 Oct 2021 15:23:56 +0900 Subject: [PATCH 2/2] add linux static test --- .gitignore | 1 + Makefile | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/.gitignore b/.gitignore index 1335c639..36fd8141 100644 --- a/.gitignore +++ b/.gitignore @@ -9,5 +9,6 @@ lib*.a # artifacts from compile tests artifacts/ muslc.exe +static.exe tmp a.out diff --git a/Makefile b/Makefile index b03915c8..30238fe5 100644 --- a/Makefile +++ b/Makefile @@ -99,3 +99,11 @@ test-alpine: release-build-alpine docker run --rm --read-only -v $(shell pwd):/code -w /code alpine:3.10 ./muslc.exe ./api/testdata/hackatom.wasm # run static binary locally if you are on Linux # ./muslc.exe ./api/testdata/hackatom.wasm + +test-static: release-build-linux-static + # build a go binary + docker run --rm -u $(USER_ID):$(USER_GROUP) -v $(shell pwd):/code -w /code $(BUILDERS_PREFIX):static go build -tags='static mocks' -o static.exe ./cmd + # run static binary in an alpine machines (not dlls) + docker run --rm --read-only -v $(shell pwd):/code -w /code centos ./static.exe ./api/testdata/hackatom.wasm + # run static binary locally if you are on Linux + # ./static.exe ./api/testdata/hackatom.wasm