Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: change tag name for static build #49

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ lib*.a
# artifacts from compile tests
artifacts/
muslc.exe
static.exe
tmp
a.out
18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it right that 'dlls' to windows dlls? It seems unfamiliar Windows terminology in the linux environment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I will fix the comment in another PR.

docker run --rm --read-only -v $(shell pwd):/code -w /code centos ./static.exe ./api/testdata/hackatom.wasm
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about choice a more specific the centos version?
used 7 when building, so I think it would be good to specify 7 in the test as well.

# run static binary locally if you are on Linux
# ./static.exe ./api/testdata/hackatom.wasm
7 changes: 0 additions & 7 deletions api/link_muslc.go

This file was deleted.

4 changes: 2 additions & 2 deletions api/link_static.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build linux && !muslc && static
// +build linux,!muslc,static
//go:build linux && static
// +build linux,static

package api

Expand Down
4 changes: 2 additions & 2 deletions api/link_std.go
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion builders/Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
23 changes: 20 additions & 3 deletions builders/Dockerfile.static
Original file line number Diff line number Diff line change
@@ -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/
Expand All @@ -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"]
28 changes: 16 additions & 12 deletions builders/Makefile
Original file line number Diff line number Diff line change
@@ -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
4 changes: 1 addition & 3 deletions builders/guest/build_linux_static.sh
Original file line number Diff line number Diff line change
@@ -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"