Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
build: fix static building (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
Woosang Son authored Nov 23, 2021
1 parent f360883 commit 84b6a7f
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 599 deletions.
523 changes: 0 additions & 523 deletions .circleci/config.yml

This file was deleted.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (sdk) Use fastcache for inter block cache and iavl cache
* (sdk) Enable signature verification cache
* (ostracon) Apply asynchronous receiving reactor
* (sdk) [\#29](https://github.com/line/lfb/pull/29) Use lbm-sdk v0.43.1

### Bug Fixes

Expand Down
14 changes: 11 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,24 @@ COPY ./go.sum /lfb-build/lfb/go.sum
RUN go mod download

# Build cosmwasm
ENV RUSTUP_HOME=/usr/local/rustup
ENV CARGO_HOME=/usr/local/cargo
ENV PATH=$CARGO_HOME/bin:$PATH

RUN wget "https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-musl/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
RUN cd $(go list -f "{{ .Dir }}" -m github.com/line/wasmvm) && \
RUSTFLAGS='-C target-feature=-crt-static' cargo build --release --example muslc && \
mv target/release/examples/libmuslc.a /usr/lib/libwasmvm_muslc.a && \
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

# Add source files
COPY . .

# Make install
RUN BUILD_TAGS=muslc make install CGO_ENABLED=1 LFB_BUILD_OPTIONS="$LFB_BUILD_OPTIONS"
RUN BUILD_TAGS=static make install CGO_ENABLED=1 LFB_BUILD_OPTIONS="$LFB_BUILD_OPTIONS"

# Final image
FROM alpine:edge
Expand Down
11 changes: 6 additions & 5 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)/
docker build -t line/lfb-builder:static -f builders/Dockerfile.static .
docker run -it --rm -v $(shell pwd):/code -e LFB_BUILD_OPTIONS="$(LFB_BUILD_OPTIONS)" line/lfb-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/lfb

Expand Down Expand Up @@ -184,9 +188,6 @@ build-reproducible: go.sum
--name latest-build cosmossdk/rbuilder:latest
$(DOCKER) cp -a latest-build:/home/builder/artifacts/ $(CURDIR)/

build-linux: go.sum
LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build

build-docker:
docker build --build-arg LFB_BUILD_OPTIONS="$(LFB_BUILD_OPTIONS)" -t line/lfb .

Expand Down Expand Up @@ -291,7 +292,7 @@ build-docker-lfbnode:
$(MAKE) -C networks/local

# Run a 4-node testnet locally
localnet-start: build-linux localnet-stop
localnet-start: build-docker-lfbnode build-static localnet-stop
@if ! [ -f build/node0/lfb/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/lfb:Z line/lfbnode testnet --v 4 -o . --starting-ip-address 192.168.10.2 --keyring-backend=test ; fi
docker-compose up -d

Expand All @@ -309,7 +310,7 @@ test-docker-push: test-docker
@docker push ${TEST_DOCKER_REPO}:$(shell git rev-parse --abbrev-ref HEAD | sed 's#/#_#g')
@docker push ${TEST_DOCKER_REPO}:latest

.PHONY: all build-linux install format lint \
.PHONY: all install format lint \
go-mod-cache draw-deps clean build \
setup-transactions setup-contract-tests-data start-link run-lcd-contract-tests contract-tests \
test test-all test-build test-cover test-unit test-race \
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/lfb-builder:static -f builders/Dockerfile.static .
#
# run build
# > docker run -it --rm -v $(pwd):/code line/lfb-builder:static
#
# make image and run build
# > docker run -it --rm -v $(pwd):/code -e LFB_BUILD_OPTIONS=rocksdb $(docker build -f builders/Dockerfile.static -q .)

FROM rust:1.53

ENV LFB_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 lfb
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 lfb
BUILD_TAGS=static make build LFB_BUILD_OPTIONS="${LFB_BUILD_OPTIONS}"
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ go 1.15

require (
github.com/gorilla/mux v1.8.0
github.com/line/lbm-sdk v1.0.0-init.1.0.20210910074019-a18b7c8c01a7
github.com/line/ostracon v0.34.9-0.20210906083237-658e85d9b160
github.com/line/lbm-sdk v0.43.1
github.com/line/ostracon v1.0.2
github.com/line/tm-db/v2 v2.0.0-init.1.0.20210824011847-fcfa67dd3c70
github.com/prometheus/client_golang v1.11.0
github.com/rakyll/statik v0.1.7
github.com/spf13/cast v1.3.1
github.com/spf13/cast v1.4.1
github.com/spf13/cobra v1.1.3
github.com/spf13/viper v1.7.1
github.com/spf13/viper v1.9.0
github.com/stretchr/testify v1.7.0
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect
)
Expand Down
Loading

0 comments on commit 84b6a7f

Please sign in to comment.