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 e3712fb4..30238fe5 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,10 +92,18 @@ 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 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 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"