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

build: add builders for static linking #24

Merged
merged 1 commit into from
Oct 14, 2021
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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 29 additions & 0 deletions builders/Dockerfile.static
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions builders/scripts/build-static.sh
Original file line number Diff line number Diff line change
@@ -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}"