Skip to content

Commit

Permalink
ci: update make build commands
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yang committed Feb 9, 2024
1 parent c739cd0 commit 38b26f9
Showing 1 changed file with 58 additions and 29 deletions.
87 changes: 58 additions & 29 deletions contrib/make/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,29 @@
### Build Flags ###
###############################################################################

# BRANCH: Current git branch
# COMMIT: Current commit hash
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
COMMIT := $(shell git log -1 --format='%H')

# don't override user values
ifeq (,$(VERSION))
VERSION := $(shell git describe --exact-match 2>/dev/null)
# if VERSION is empty, then populate it with branch's name and raw commit hash
ifeq (,$(VERSION))
VERSION := $(BRANCH)-$(COMMIT)
endif
VERSION := $(shell git describe --exact-match 2>/dev/null)
# if VERSION is empty, then populate it with branch's name and raw commit hash
ifeq (,$(VERSION))
VERSION := $(BRANCH)-$(COMMIT)
endif
endif


OS_NAME := $(shell uname -s | tr A-Z a-z)
ifeq ($(shell uname -m),x86_64)
ARCH_NAME := amd64
else
ARCH_NAME := arm64
endif
SUDO := $(shell if [ "$(shell id -u)" != "0" ]; then echo "sudo"; fi)

# SDK_PACK: Cosmos-SDK version
SDK_PACK := $(shell go list -m github.com/cosmos/cosmos-sdk | sed 's/ /\@/g')
# TM_VERSION: Tendermint Core version (CometBFT)
# grab everything after the space in "github.com/tendermint/tendermint v0.34.7"
Expand All @@ -36,7 +39,12 @@ TEMPDIR ?= $(CURDIR)/temp
export GO111MODULE = on

# process build tags
build_tags = netgo osusergo rocksdb grocksdb_no_link static_wasm muslc ledger
build_tags = netgo osusergo ledger static rocksdb
ifeq ($(OS_NAME),darwin)
build_tags += static_wasm grocksdb_no_link
else
build_tags += muslc
endif
build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))

Expand All @@ -61,11 +69,11 @@ ldflags := $(strip $(ldflags))

BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'
CGO_CFLAGS := -I$(TEMPDIR)/include
CGO_LDFLAGS := -L$(TEMPDIR)/lib -lrocksdb -lstdc++ -lm -ldl
CGO_LDFLAGS := -L$(TEMPDIR)/lib
ifeq ($(OS_NAME),darwin)
CGO_LDFLAGS += -lz -lbz2
CGO_LDFLAGS += -lrocksdb -lstdc++ -lz -lbz2
else
CGO_LDFLAGS += -static -lwasmvm_muslc
CGO_LDFLAGS += -static -lm -lbz2
endif

###############################################################################
Expand All @@ -79,30 +87,51 @@ $(TEMPDIR)/:
rocksdblib: $(TEMPDIR)/
@mkdir -p $(TEMPDIR)/include
@mkdir -p $(TEMPDIR)/lib
ifeq (",$(wildcard $(TEMPDIR)/include/rocksdb)")
wget https://github.com/NibiruChain/gorocksdb/releases/download/v$(ROCKSDB_VERSION)/include.$(ROCKSDB_VERSION).tar.gz -O - | tar -xz -C $(TEMPDIR)/include/
endif
ifeq (",$(wildcard $(TEMPDIR)/lib/librocksdb.a)")
wget https://github.com/NibiruChain/gorocksdb/releases/download/v$(ROCKSDB_VERSION)/librocksdb_$(ROCKSDB_VERSION)_$(OS_NAME)_$(ARCH_NAME).tar.gz -O - | tar -xz -C $(TEMPDIR)/lib/
endif
@if [ ! -d $(TEMPDIR)/include/rocksdb ] ; \
then \
wget https://github.com/NibiruChain/gorocksdb/releases/download/v$(ROCKSDB_VERSION)/include.$(ROCKSDB_VERSION).tar.gz -O - | tar -xz -C $(TEMPDIR)/include/; \
fi
@if [ ! -f $(TEMPDIR)/lib/librocksdb.a ] ; \
then \
wget https://github.com/NibiruChain/gorocksdb/releases/download/v$(ROCKSDB_VERSION)/librocksdb_$(ROCKSDB_VERSION)_$(OS_NAME)_$(ARCH_NAME).tar.gz -O - | tar -xz -C $(TEMPDIR)/lib/; \
fi

wasmvmlib: $(TEMPDIR)/
@mkdir -p $(TEMPDIR)/lib
ifeq (",$(wildcard $(TEMPDIR)/lib/libwasmvm*.a)")
ifeq ($(OS_NAME),darwin)
wget https://github.com/CosmWasm/wasmvm/releases/download/v$(WASMVM_VERSION)/libwasmvmstatic_darwin.a -O $(TEMPDIR)/lib/libwasmvmstatic_darwin.a
else
ifeq ($(ARCH_NAME),amd64)
wget https://github.com/CosmWasm/wasmvm/releases/download/v$(WASMVM_VERSION)/libwasmvm_muslc.x86_64.a -O $(TEMPDIR)/lib/libwasmvm_muslc.a
else
wget https://github.com/CosmWasm/wasmvm/releases/download/v$(WASMVM_VERSION)/libwasmvm_muslc.aarch64.a -O $(TEMPDIR)/lib/libwasmvm_muslc.a
endif
endif
endif
@if [ ! -f $(TEMPDIR)/lib/libwasmvm*.a ] ; \
then \
if [ "$(OS_NAME)" = "darwin" ] ; \
then \
wget https://github.com/CosmWasm/wasmvm/releases/download/v$(WASMVM_VERSION)/libwasmvmstatic_darwin.a -O $(TEMPDIR)/lib/libwasmvmstatic_darwin.a; \
else \
if [ "$(ARCH_NAME)" = "amd64" ] ; \
then \
wget https://github.com/CosmWasm/wasmvm/releases/download/v$(WASMVM_VERSION)/libwasmvm_muslc.x86_64.a -O $(TEMPDIR)/lib/libwasmvm_muslc.a; \
else \
wget https://github.com/CosmWasm/wasmvm/releases/download/v$(WASMVM_VERSION)/libwasmvm_muslc.aarch64.a -O $(TEMPDIR)/lib/libwasmvm_muslc.a; \
fi; \
fi; \
fi

packages:
@if [ "$(OS_NAME)" = "linux" ] ; \
then \
if [ -f /etc/debian_version ] ; \
then \
$(SUDO) apt-get update; \
dpkg -s liblz4-dev > /dev/null 2>&1 || $(SUDO) apt-get install --no-install-recommends -y liblz4-dev; \
dpkg -s libsnappy-dev > /dev/null 2>&1 || $(SUDO) apt-get install --no-install-recommends -y libsnappy-dev; \
dpkg -s zlib1g-dev > /dev/null 2>&1 || $(SUDO) apt-get install --no-install-recommends -y zlib1g-dev; \
dpkg -s libbz2-dev > /dev/null 2>&1 || $(SUDO) apt-get install --no-install-recommends -y libbz2-dev; \
dpkg -s libzstd-dev > /dev/null 2>&1 || $(SUDO) apt-get install --no-install-recommends -y libzstd-dev; \
else \
echo "Please make sure you have installed the following libraries: lz4, snappy, z, bz2, zstd"; \
fi; \
fi

# command for make build and make install
build: BUILDARGS=-o $(BUILDDIR)/
build install: go.sum $(BUILDDIR)/ rocksdblib wasmvmlib
build install: go.sum $(BUILDDIR)/ rocksdblib wasmvmlib packages
CGO_ENABLED=1 CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" go $@ -mod=readonly $(BUILD_FLAGS) $(BUILDARGS) ./...

# ensure build directory exists
Expand All @@ -113,4 +142,4 @@ go.sum: go.mod
@echo "--> Ensure dependencies have not been modified"
@go mod verify

.PHONY: build install
.PHONY: build install

0 comments on commit 38b26f9

Please sign in to comment.