From 466d7292b205f0d3d2b3eae10a913d97065c920e Mon Sep 17 00:00:00 2001 From: DimitrisJim Date: Tue, 11 Jul 2023 23:44:24 +0300 Subject: [PATCH] Use alpine for building simd in docker. Link statically. --- Dockerfile | 23 +++++++++++++++-------- Makefile | 5 ++++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 087d001ee9e..b02982ea017 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,22 @@ -FROM golang:1.20 as builder - +FROM golang:1.20-alpine3.18 as builder ARG IBC_GO_VERSION +RUN set -eux; apk add --no-cache git libusb-dev linux-headers gcc musl-dev make; + ENV GOPATH="" ENV GOMODULE="on" # ensure the ibc go version is being specified for this image. RUN test -n "${IBC_GO_VERSION}" -COPY go.mod . -COPY go.sum . - -RUN go mod download +# Grab the static library and copy it to location that will be found by the linker flag `-lwasmvm_muslc`. +# TODO: nice to have: a script to download version matching the wasmvm version in go.mod. +ADD https://github.com/CosmWasm/wasmvm/releases/download/v1.2.1/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.x86_64.a +RUN sha256sum /lib/libwasmvm_muslc.x86_64.a | grep a00700aa19f5bfe0f46290ddf69bf51eb03a6dfcd88b905e1081af2e42dbbafc +RUN cp /lib/libwasmvm_muslc.x86_64.a /lib/libwasmvm_muslc.a +# Copy relevant files before go mod download. Replace directives to local paths break if local +# files are not copied before go mod download. ADD internal internal ADD testing testing ADD modules modules @@ -21,11 +25,14 @@ ADD LICENSE LICENSE COPY contrib/devtools/Makefile contrib/devtools/Makefile COPY Makefile . +COPY go.mod . +COPY go.sum . -RUN make build +RUN go mod download -FROM ubuntu:22.04 +RUN BUILD_TAGS=muslc LINK_STATICALLY=true make build +FROM alpine:3.18 ARG IBC_GO_VERSION LABEL "org.cosmos.ibc-go" "${IBC_GO_VERSION}" diff --git a/Makefile b/Makefile index 3bc5487abd6..479d085bc04 100644 --- a/Makefile +++ b/Makefile @@ -84,9 +84,12 @@ endif ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS))) ldflags += -w -s endif +# Direct linker to statically link. +ifeq ($(LINK_STATICALLY),true) + ldflags += -linkmode=external -extldflags "-Wl,-z,muldefs -static" +endif ldflags += $(LDFLAGS) ldflags := $(strip $(ldflags)) - BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)' # check for nostrip option ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS)))