diff --git a/Makefile b/Makefile index 7a61f68c..0188102c 100644 --- a/Makefile +++ b/Makefile @@ -131,6 +131,10 @@ build: BUILD_ARGS=-o $(BUILDDIR)/ build: go.sum $(BUILDDIR)/ dbbackend CGO_CFLAGS=$(CGO_CFLAGS) CGO_LDFLAGS=$(CGO_LDFLAGS) CGO_ENABLED=$(CGO_ENABLED) go build -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) ./... +build-static: go.sum $(BUILDDIR)/ dbbackend + docker build -t line/lbm-builder:static -f builders/Dockerfile.static . + docker run -it --rm -v $(shell pwd):/code -e LBM_BUILD_OPTIONS="$(LBM_BUILD_OPTIONS)" line/lbm-builder:static + install: go.sum $(BUILDDIR)/ dbbackend CGO_CFLAGS=$(CGO_CFLAGS) CGO_LDFLAGS=$(CGO_LDFLAGS) CGO_ENABLED=$(CGO_ENABLED) go install $(BUILD_FLAGS) $(BUILD_ARGS) ./cmd/lbm diff --git a/builders/Dockerfile.static b/builders/Dockerfile.static new file mode 100644 index 00000000..02b9b380 --- /dev/null +++ b/builders/Dockerfile.static @@ -0,0 +1,29 @@ +# make image +# > docker build -t line/lbm-builder:static -f builders/Dockerfile.static . +# +# run build +# > docker run -it --rm -v $(pwd):/code line/lbm-builder:static +# +# make image and run build +# > docker run -it --rm -v $(pwd):/code -e LBM_BUILD_OPTIONS=rocksdb $(docker build -f builders/Dockerfile.static -q .) + +FROM rust:1.53 + +ENV LBM_BUILD_OPTIONS="goleveldb" + +# install tools +RUN apt update && apt install -y cmake + +# install go +WORKDIR /tmp +ADD https://golang.org/dl/go1.15.15.linux-amd64.tar.gz . +RUN tar -C /usr/local -xzf go1.15.15.linux-amd64.tar.gz +ENV PATH=/usr/local/go/bin:$PATH + +WORKDIR /code + +# copy build script +COPY builders/scripts/build-static.sh builders/scripts/build-static.sh + +# build lbm +ENTRYPOINT builders/scripts/build-static.sh diff --git a/builders/scripts/build-static.sh b/builders/scripts/build-static.sh new file mode 100755 index 00000000..56c5179c --- /dev/null +++ b/builders/scripts/build-static.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env sh + +PROJECT_ROOT=$(realpath "$(dirname "$0")/../..") + +# install dependencies +go mod download + +# build wasmvm static +cd "$(go list -f "{{ .Dir }}" -m github.com/line/wasmvm)" || exit 1 +RUSTFLAGS='-C target-feature=-crt-static' cargo build --release --example staticlib +mv -f target/release/examples/libstaticlib.a /usr/lib/libwasmvm_static.a +rm -rf target + +cd "${PROJECT_ROOT}" || exit 1 + +# build lbm +BUILD_TAGS=static make build LBM_BUILD_OPTIONS="${LBM_BUILD_OPTIONS}"