Skip to content

Commit

Permalink
chore(build): add build tags and missing flags/variables (#2202)
Browse files Browse the repository at this point in the history
Co-authored-by: Unique-Divine <[email protected]>
Co-authored-by: Unique Divine <[email protected]>
  • Loading branch information
3 people authored Feb 13, 2025
1 parent 28dd919 commit b3c8d07
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
12 changes: 9 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ project_name: nibid

env:
- CGO_ENABLED=1
- GO111MODULE=on
- DEFAULT_DB_BACKEND=pebbledb

builds:
- id: darwin
Expand Down Expand Up @@ -31,9 +33,11 @@ builds:
- -X github.com/cosmos/cosmos-sdk/version.AppName=nibid
- -X github.com/cosmos/cosmos-sdk/version.Version={{ .Version }}
- -X github.com/cosmos/cosmos-sdk/version.Commit={{ .Commit }}
- -X github.com/cosmos/cosmos-sdk/types.DBBackend=rocksdb
- -X github.com/cosmos/cosmos-sdk/version.BuildTags={{ .Env.DARWIN_TAGS }}
- -X github.com/cometbft/cometbft/version.CMTSemVer={{ .Env.CMT_VERSION }}
- -X github.com/cosmos/cosmos-sdk/types.DBBackend={{ .Env.DEFAULT_DB_BACKEND }}
- -linkmode=external
- -extldflags '-lrocksdb -lstdc++ -ldl -lz -lbz2'
- -extldflags '-lrocksdb -lstdc++ -lz -lbz2'
tags:
- netgo
- osusergo
Expand Down Expand Up @@ -71,7 +75,9 @@ builds:
- -X github.com/cosmos/cosmos-sdk/version.AppName=nibid
- -X github.com/cosmos/cosmos-sdk/version.Version={{ .Version }}
- -X github.com/cosmos/cosmos-sdk/version.Commit={{ .Commit }}
- -X github.com/cosmos/cosmos-sdk/types.DBBackend=rocksdb
- -X github.com/cosmos/cosmos-sdk/version.BuildTags={{ .Env.LINUX_TAGS }}
- -X github.com/cometbft/cometbft/version.CMTSemVer={{ .Env.CMT_VERSION }}
- -X github.com/cosmos/cosmos-sdk/types.DBBackend={{ .Env.DEFAULT_DB_BACKEND }}
- -linkmode=external
- -extldflags '-static -lm -lbz2'
tags:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

- [#2104](https://github.com/NibiruChain/nibiru/pull/2104) - chore: update chain IDs
- [#2202](https://github.com/NibiruChain/nibiru/pull/2202) - chore(build): add build tags and missing flags/variables
- [#2206](https://github.com/NibiruChain/nibiru/pull/2206) - ci(chaosnet): fix docker image build
- [#2207](https://github.com/NibiruChain/nibiru/pull/2207) - chore(ci): add cache for chaosnet builds
- [#2209](https://github.com/NibiruChain/nibiru/pull/2209) - refator(ci):
Expand Down
15 changes: 4 additions & 11 deletions contrib/make/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,9 @@ else
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"
TM_VERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::')
CMT_VERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::')
ROCKSDB_VERSION := 8.9.1
WASMVM_VERSION := $(shell go list -m github.com/CosmWasm/wasmvm | awk '{sub(/^v/, "", $$2); print $$2}')
DOCKER := $(shell which docker)
BUILDDIR ?= $(CURDIR)/build
TEMPDIR ?= $(CURDIR)/temp

Expand All @@ -45,7 +40,6 @@ ifeq ($(OS_NAME),darwin)
else
build_tags += muslc
endif
build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))

whitespace :=
Expand All @@ -59,12 +53,11 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=nibiru \
-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(build_tags_comma_sep)" \
-X github.com/tendermint/tendermint/version.TMCoreSemVer=$(TM_VERSION) \
-X github.com/cosmos/cosmos-sdk/types.DBBackend=rocksdb \
-X github.com/cometbft/cometbft/version.CMTSemVer=$(CMT_VERSION) \
-X github.com/cosmos/cosmos-sdk/types.DBBackend=pebbledb \
-linkmode=external \
-w -s

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

BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'
Expand Down Expand Up @@ -132,7 +125,7 @@ packages:
# command for make build and make install
build: BUILDARGS=-o $(BUILDDIR)/
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) ./...
CGO_ENABLED=1 CGO_CFLAGS="$(CGO_CFLAGS)" CGO_LDFLAGS="$(CGO_LDFLAGS)" go $@ -mod=readonly -trimpath $(BUILD_FLAGS) $(BUILDARGS) ./...

# ensure build directory exists
$(BUILDDIR)/:
Expand Down
27 changes: 23 additions & 4 deletions contrib/make/release.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,48 @@

PACKAGE_NAME := github.com/NibiruChain/nibiru
GOLANG_CROSS_VERSION ?= v1.21.5
CMT_VERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::')

# The `make release` command is running a Docker container with the image
DOCKER_YQ = docker run --rm -v $(PWD):/work -w /work mikefarah/yq:4

DARWIN_TAGS := $(shell $(DOCKER_YQ) e \
'.builds | map(select(.id == "darwin")) | .[0].tags | join(",")' \
.goreleaser.yml)

LINUX_TAGS := $(shell $(DOCKER_YQ) e \
'.builds | map(select(.id == "linux")) | .[0].tags | join(",")' \
.goreleaser.yml)

# The `make release` command is running a Docker container with the image
# `gorelease/goreleaser-cross:${GOLANG_CROSS_VERSION}`. This command:
# `-v "$(CURDIR)":/go/src/$(PACKAGE_NAME)`: mounts the current directory
# `-v "$(CURDIR)":/go/src/$(PACKAGE_NAME)`: mounts the current directory
# `release --clean`: executes the release inside the directory
release:
@echo "Darwin Tags: $(DARWIN_TAGS)"
@echo "Linux Tags: $(LINUX_TAGS)"
docker run \
--rm \
--platform linux/amd64 \
-v "$(CURDIR)":/go/src/$(PACKAGE_NAME) \
-w /go/src/$(PACKAGE_NAME) \
-e CGO_ENABLED=1 \
-e GITHUB_TOKEN=${GITHUB_TOKEN} \
-e CMT_VERSION=$(CMT_VERSION) \
-e DARWIN_TAGS="$(DARWIN_TAGS)" \
-e LINUX_TAGS="$(LINUX_TAGS)" \
goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
release --clean

release-snapshot:
@echo "Darwin Tags: $(DARWIN_TAGS)"
@echo "Linux Tags: $(LINUX_TAGS)"
docker run \
--rm \
--platform linux/amd64 \
-v /tmp:/tmp \
-v "$(CURDIR)":/go/src/$(PACKAGE_NAME) \
-w /go/src/$(PACKAGE_NAME) \
-e CGO_ENABLED=1 \
-e CMT_VERSION=$(CMT_VERSION) \
-e DARWIN_TAGS="$(DARWIN_TAGS)" \
-e LINUX_TAGS="$(LINUX_TAGS)" \
goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
release --clean --snapshot

0 comments on commit b3c8d07

Please sign in to comment.