Skip to content

Commit

Permalink
Merge pull request #220 from icon-project/fix/static-build
Browse files Browse the repository at this point in the history
Downgrade CosmWasm version for static build issue
  • Loading branch information
debendraoli authored May 20, 2024
2 parents 15341f9 + 1a98d91 commit 445c838
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 142 deletions.
10 changes: 5 additions & 5 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
project_name: centralised-relay
project_name: centralized-relay
env:
- CGO_ENABLED=1
builds:
- id: darwin-amd64
main: ./main.go
hooks:
pre:
- wget https://github.com/CosmWasm/wasmvm/releases/download/v2.0.1/libwasmvmstatic_darwin.a -O /lib/libwasmvmstatic_darwin.a
- wget https://github.com/CosmWasm/wasmvm/releases/download/{{ .Env.LIBWASM_VERSION }}/libwasmvmstatic_darwin.a -O /lib/libwasmvmstatic_darwin.a
goos:
- darwin
goarch:
Expand All @@ -26,7 +26,7 @@ builds:
main: ./main.go
hooks:
pre:
- wget https://github.com/CosmWasm/wasmvm/releases/download/v2.0.1/libwasmvmstatic_darwin.a -O /lib/libwasmvmstatic_darwin.a
- wget https://github.com/CosmWasm/wasmvm/releases/download/{{ .Env.LIBWASM_VERSION }}/libwasmvmstatic_darwin.a -O /lib/libwasmvmstatic_darwin.a
goos:
- darwin
goarch:
Expand All @@ -46,7 +46,7 @@ builds:
main: ./main.go
hooks:
pre:
- wget https://github.com/CosmWasm/wasmvm/releases/download/v2.0.1/libwasmvm_muslc.x86_64.a -O /usr/lib/x86_64-linux-gnu/libwasmvm_muslc.a
- wget https://github.com/CosmWasm/wasmvm/releases/download/{{ .Env.LIBWASM_VERSION }}/libwasmvm_muslc.x86_64.a -O /usr/lib/x86_64-linux-gnu/libwasmvm_muslc.a
goos:
- linux
goarch:
Expand All @@ -68,7 +68,7 @@ builds:
main: ./main.go
hooks:
pre:
- wget https://github.com/CosmWasm/wasmvm/releases/download/v2.0.1/libwasmvm_muslc.aarch64.a -O /usr/lib/aarch64-linux-gnu/libwasmvm_muslc.a
- wget https://github.com/CosmWasm/wasmvm/releases/download/{{ .Env.LIBWASM_VERSION }}/libwasmvm_muslc.aarch64.a -O /usr/lib/aarch64-linux-gnu/libwasmvm_muslc.a
goos:
- linux
goarch:
Expand Down
94 changes: 14 additions & 80 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,113 +5,45 @@ DIRTY := $(shell git status --porcelain | wc -l | xargs)
GOPATH := $(shell go env GOPATH)
GOBIN := $(GOPATH)/bin

GOOS := $(shell go env GOOS)
GOARCH := $(shell go env GOARCH)

# Define the URLs for the library files
COSMWASM_VERSION ?= v2.0.1
LIBWASMMV_URL := https://github.com/CosmWasm/wasmvm/releases/download/$(COSMWASM_VERSION)



all: lint install

###############################################################################
# Build / Install
###############################################################################

ldflags := -s -w -X github.com/icon-project/centralized-relay/cmd.Version=$(VERSION) \
ldflags = -X github.com/icon-project/centralized-relay/cmd.Version=$(VERSION) \
-X github.com/icon-project/centralized-relay.Commit=$(COMMIT) \
-X github.com/icon-project/centralized-relay.Dirty=$(DIRTY) \
-linkmode=external
-X github.com/icon-project/centralized-relay.Dirty=$(DIRTY)

ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))

# Default build flags for each OS
ifeq ($(GOOS),linux)
BUILD_TAGS := -tags muslc,netgo
ifeq ($(GOARCH),amd64)
BUILD_FLAGS := -ldflags '$(ldflags) -extldflags "-Wl,-z,muldefs -lm"'
BUILD_ENV := CGO_ENABLED=1 CC=x86_64-linux-gnu-gcc CXX=x86_64-linux-gnu-g++
else ifeq ($(GOARCH),arm64)
BUILD_FLAGS := -ldflags '$(ldflags) -extldflags "-static"'
BUILD_ENV := CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc
endif
else ifeq ($(GOOS),darwin)
BUILD_TAGS := -tags static_wasm
ifeq ($(GOARCH),amd64)
BUILD_FLAGS := -ldflags '$(ldflags) -extldflags "-Wl,-z,muldefs -lm"'
BUILD_ENV := CGO_ENABLED=1 CC=o64-clang CGO_LDFLAGS=-L/lib

else ifeq ($(GOARCH),arm64)
BUILD_FLAGS := -ldflags '$(ldflags) -extldflags "-static"'
BUILD_ENV := CGO_ENABLED=1 CC=o64-clang CGO_LDFLAGS=-L/lib
endif
else
BUILD_FLAGS := -ldflags '$(ldflags)'
BUILD_ENV := CGO_ENABLED=1
endif
BUILD_FLAGS := -ldflags '$(ldflags)'

install_libwasmvm:
@echo "Install libwasmvm static library..."
@if [ "$(GOOS)" = "linux" ] && [ "$(GOARCH)" = "amd64" ]; then \
sudo wget -q $(LIBWASMMV_URL)/libwasmvm_muslc.x86_64.a -O /usr/lib/x86_64-linux-gnu/libwasmvm_muslc.a; \
elif [ "$(GOOS)" = "darwin" ] && [ "$(GOARCH)" = "amd64" ]; then \
sudo wget -q $(LIBWASMMV_URL)/libwasmvm_muslc.darwin.a -O /usr/local/lib/libwasmvm_muslc.a; \
elif [ "$(GOOS)" = "linux" ] && [ "$(GOARCH)" = "arm64" ]; then \
sudo wget -q $(LIBWASMMV_URL)/libwasmvm_muslc.aarch64.a -O /usr/lib/aarch64-linux-gnu/libwasmvm_muslc.a; \
elif [ "$(GOOS)" = "darwin" ] && [ "$(GOARCH)" = "arm64" ]; then \
sudo wget -q $(LIBWASMMV_URL)/libwasmvmstatic_darwin.a -O /lib/libwasmvmstatic_darwin.a; \
else \
echo "Unsupported GOOS=$(GOOS) GOARCH=$(GOARCH) combination for libwasmvm installation."; \
exit 1; \
fi

build: go.sum install_libwasmvm
ifeq ($(GOOS),windows)
@echo "building centralized-relay binary for Windows..."
@$(BUILD_ENV) go build -mod=readonly -trimpath $(BUILD_FLAGS) $(BUILD_TAGS) -o build/centralized-relay.exe main.go
else ifeq ($(GOOS),linux)
@echo "building centralized-relay binary for Linux..."
@if [ "$(GOARCH)" = "amd64" ]; then \
$(BUILD_ENV) go build -mod=readonly -trimpath $(BUILD_FLAGS) $(BUILD_TAGS) -o build/centralized-relay main.go; \
elif [ "$(GOARCH)" = "arm64" ]; then \
$(BUILD_ENV) go build -mod=readonly -trimpath $(BUILD_FLAGS) $(BUILD_TAGS) -o build/centralized-relay main.go; \
else \
echo "Unsupported GOARCH=$(GOARCH) for $(GOOS)"; \
exit 1; \
fi
else ifeq ($(GOOS),darwin)
@echo "building centralized-relay binary for macOS..."
@if [ "$(GOARCH)" = "amd64" ]; then \
$(BUILD_ENV) go build -mod=readonly -trimpath $(BUILD_FLAGS) $(BUILD_TAGS) -o build/centralized-relay main.go; \
elif [ "$(GOARCH)" = "arm64" ]; then \
$(BUILD_ENV) go build -mod=readonly -trimpath $(BUILD_FLAGS) $(BUILD_TAGS) -o build/centralized-relay main.go; \
else \
echo "Unsupported GOARCH=$(GOARCH) for $(GOOS)"; \
exit 1; \
fi
build: go.sum
ifeq ($(OS),Windows_NT)
@echo "building centralized-relay binary..."
@go build -mod=readonly $(BUILD_FLAGS) -o build/centralized-relay main.go
else
@echo "Unsupported GOOS=$(GOOS)"
exit 1
@echo "building centralized-relay binary..."
@go build $(BUILD_FLAGS) -o build/centralized-relay main.go
endif

build-docker:
@echo "building centralized docker image..."
docker build . -t centralized-relay

install: go.sum install_libwasmvm build
install: go.sum
@echo "installing centralized-relay binary..."
@mv ./build/centralized-relay $(GOBIN)/centralized-relay
@rm -rf ./build
@go build -mod=readonly $(BUILD_FLAGS) -o $(GOBIN)/centralized-relay main.go


e2e-test:
@go test -v ./test/e2e -testify.m TestE2E_all

PACKAGE_NAME := github.com/icon-project/centralized-relay
GOLANG_CROSS_VERSION ?= v1.22.3
LIBWASM_VERSION ?= v2.0.0

SYSROOT_DIR ?= sysroots
SYSROOT_ARCHIVE ?= sysroots.tar.bz2
Expand All @@ -121,6 +53,7 @@ SYSROOT_ARCHIVE ?= sysroots.tar.bz2
release-dry-run:
@docker run \
--rm \
--env LIBWASM_VERSION=$(LIBWASM_VERSION) \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-w /go/src/$(PACKAGE_NAME) \
Expand All @@ -132,6 +65,7 @@ release:
docker run \
--rm \
--env GITHUB_TOKEN \
--env LIBWASM_VERSION=$(LIBWASM_VERSION) \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-w /go/src/$(PACKAGE_NAME) \
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/icon-project/centralized-relay
go 1.22

require (
github.com/CosmWasm/wasmd v0.51.0
github.com/CosmWasm/wasmd v0.50.0
github.com/cometbft/cometbft v0.38.7
github.com/cosmos/cosmos-sdk v0.50.6
github.com/cosmos/relayer/v2 v2.5.2
Expand All @@ -30,7 +30,7 @@ require (
cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect
contrib.go.opencensus.io/exporter/prometheus v0.4.2 // indirect
cosmossdk.io/x/upgrade v0.1.1 // indirect
github.com/CosmWasm/wasmvm/v2 v2.0.0 // indirect
github.com/CosmWasm/wasmvm v1.5.0 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.17.9 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
Expand Down Expand Up @@ -101,7 +101,6 @@ require (

require (
cloud.google.com/go v0.113.0 // indirect
cloud.google.com/go/compute v1.26.0 // indirect
cloud.google.com/go/compute/metadata v0.3.0 // indirect
cloud.google.com/go/iam v1.1.8 // indirect
cloud.google.com/go/storage v1.41.0 // indirect
Expand Down
Loading

0 comments on commit 445c838

Please sign in to comment.