-
Notifications
You must be signed in to change notification settings - Fork 272
Expand file tree
/
Copy pathbuild.mk
More file actions
132 lines (109 loc) · 3.69 KB
/
build.mk
File metadata and controls
132 lines (109 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/make -f
ifeq ($(VERSION),)
VERSION := $(shell git describe --tags --always --match "v*")
endif
COMMIT = $(shell git log -1 --format='%H')
CURRENT_DIR = $(shell pwd)
OUT_DIR ?= $(CURDIR)/build/bin
TESTNAME = beacon
TESTAPP = beacond
TESTAPP_FILES_DIR = testing/files
TESTAPP_CMD_DIR = cmd/$(TESTAPP)
PROJECT_NAME = $(shell git remote get-url origin | xargs basename -s .git)
# process build tags
build_tags = netgo
ifeq (legacy,$(findstring legacy,$(COSMOS_BUILD_OPTIONS)))
build_tags += app_v1
endif
# DB backend selection
ifeq (cleveldb,$(findstring cleveldb,$(COSMOS_BUILD_OPTIONS)))
build_tags += gcc
endif
ifeq (badgerdb,$(findstring badgerdb,$(COSMOS_BUILD_OPTIONS)))
build_tags += badgerdb
endif
# handle rocksdb
ifeq (rocksdb,$(findstring rocksdb,$(COSMOS_BUILD_OPTIONS)))
CGO_ENABLED=1
build_tags += rocksdb grocksdb_clean_link
endif
# handle boltdb
ifeq (boltdb,$(findstring boltdb,$(COSMOS_BUILD_OPTIONS)))
build_tags += boltdb
endif
# always include pebble
build_tags += pebbledb
# always include blst
build_tags += blst
build_tags += bls12381
# always include cgo
build_tags += cgo
whitespace :=
whitespace += $(whitespace)
comma := ,
build_tags_comma_sep := $(subst $(whitespace),$(comma),$(build_tags))
# process linker flags
ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=$(TESTNAME) \
-X github.com/cosmos/cosmos-sdk/version.AppName=$(TESTAPP) \
-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)"
ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS)))
ldflags += -w -s
endif
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))
build_tags += $(BUILD_TAGS)
BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'
# check for nostrip option
ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS)))
BUILD_FLAGS += -trimpath
endif
# Check for debug option
ifeq (debug,$(findstring debug,$(COSMOS_BUILD_OPTIONS)))
BUILD_FLAGS += -gcflags "all=-N -l"
endif
# This allows us to reuse the build target steps for both go build and go install
BUILD_TARGETS := build install
## Build:
build: BUILD_ARGS=-o $(OUT_DIR)/$(TESTAPP) ## build `beacond`
$(BUILD_TARGETS): $(OUT_DIR)/
@echo "Building ${TESTAPP_CMD_DIR}"
@go $@ -mod=readonly $(BUILD_FLAGS) $(BUILD_ARGS) $(TESTAPP_CMD_DIR)/*.go
$(OUT_DIR)/:
mkdir -p $(OUT_DIR)/
# Variables
ARCH ?= $(shell uname -m)
ifeq ($(ARCH),)
ARCH = arm64
endif
IMAGE_NAME ?= $(TESTAPP)
# Docker Paths
DOCKERFILE = ./Dockerfile
# Create buildx builder if it doesn't exist
.PHONY: docker-builder-setup
docker-builder-setup:
@docker buildx inspect beaconkit-builder 2>/dev/null || \
docker buildx create --name beaconkit-builder --driver docker-container
@docker buildx use beaconkit-builder
build-docker: docker-builder-setup ## build a docker image containing `beacond`
@echo "Build a release docker image for the Cosmos SDK chain..."
docker buildx build \
--load \
--platform linux/$(ARCH) \
--build-arg GIT_COMMIT=$(shell git rev-parse HEAD) \
--build-arg GIT_VERSION=$(VERSION) \
--build-arg GIT_BRANCH=$(shell git rev-parse --abbrev-ref HEAD) \
--build-arg GOOS=linux \
--build-arg GOARCH=$(ARCH) \
-f ${DOCKERFILE} \
-t $(IMAGE_NAME):$(VERSION) \
.
push-docker-github: ## push the docker image to the ghcr registry
@echo "Push the release docker image to the ghcr registry..."
docker tag $(IMAGE_NAME):$(VERSION) ghcr.io/berachain/beacon-kit:$(VERSION)
docker push ghcr.io/berachain/beacon-kit:$(VERSION)
clean-docker: ## clean up docker builder and cache
@echo "Removing beaconkit-builder and clearing cache..."
@docker buildx rm beaconkit-builder || true
@echo "Docker builder cleanup complete"