-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathMakefile
More file actions
179 lines (147 loc) · 4.87 KB
/
Makefile
File metadata and controls
179 lines (147 loc) · 4.87 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# Copyright 2025 Buf Technologies, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# See https://tech.davis-hansson.com/p/make/
SHELL := bash
.DELETE_ON_ERROR:
.SHELLFLAGS := -eu -o pipefail -c
.DEFAULT_GOAL := all
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-print-directory
BIN := .tmp/bin
TESTS := .tmp/tests
export PATH := $(abspath $(BIN)):$(PATH)
export GOBIN := $(abspath $(BIN))
COPYRIGHT_YEARS := 2025
LICENSE_IGNORE := testdata/
GO_VERSION := go1.25.0
BUF_VERSION := v1.56.0 # Keep in sync w/ .github/workflows/buf.yaml.
LINT_VERSION := v2.4.0 # Keep in sync w/ .github/workflows/ci.yaml.
GOOS_HOST := $(shell go env GOOS)
GOARCH_HOST := $(shell go env GOARCH)
GOOS ?=
GOARCH ?=
GOAMD64 ?=
GOARM64 ?=
HOST_ENV ?= GOTOOLCHAIN=local
EXEC_ENV ?= GOOS=$(GOOS) GOARCH=$(GOARCH) GOAMD64=$(GOAMD64) GOARM64=$(GOARM64) GOTOOLCHAIN=local
# Go will carelessly pick these up on host-side builds if we don't unexport them.
unexport GOOS
unexport GOARCH
HYPERTESTFLAGS ?=
TESTFLAGS ?=
BENCHFLAGS ?= -test.benchmem
GO ?= go
HOST_TARGET ?=
GO_HOST := $(HOST_TARGET) $(GO)
GO := $(EXEC_ENV) $(GO)
TEST := $(EXEC_ENV) $(BIN)/hypertest -o $(TESTS) $(HYPERTESTFLAGS)
TAGS ?= ""
REMOTE ?= ""
ASM_FILTER ?= ^buf.build/go/hyperpb
ASM_INFO ?= fileline
BENCHMARK ?= .
PKG ?=
ifeq ($(PKG),)
PKGS := ./...
else
PKGS := $(PKG)
endif
PKG ?= .
.PHONY: help
help: ## Describe useful make targets
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| sort \
| awk 'BEGIN {FS = ":.*?## "}; {printf "%-30s %s\n", $$1, $$2}'
.PHONY: all
all: ## Build, test, and lint (default)
$(MAKE) test
$(MAKE) lint
.PHONY: clean
clean: ## Delete intermediate build artifacts
@# -X only removes untracked files, -d recurses into directories, -f actually removes files/dirs
git clean -Xdf
.PHONY: test
test: build $(BIN)/hypertest ## Run unit tests
$(TEST) -remote=$(REMOTE) -tags=$(TAGS) -checkptr -p $(PKGS) -- \
$(TESTFLAGS)
.PHONY: bench
bench: build $(BIN)/hypertest ## Run benchmarks
$(TEST) -remote=$(REMOTE) -tags=$(TAGS) -p $(PKGS) \
-csv hyperpb.csv -table - -- \
-test.bench '$(BENCHMARK)' $(BENCHFLAGS)
.PHONY: profile
profile: build $(BIN)/hypertest ## Profile benchmarks and open them in pprof
$(TEST) -remote=$(REMOTE) -tags=$(TAGS) -p $(PKG) -profile -- \
-test.run '^B' -test.bench '$(BENCHMARK)' \
-test.benchtime 5s $(BENCHFLAGS)
@$(GO_HOST) tool pprof -http localhost:8000 $(TESTS)/*.test $(TESTS)/*.prof
.PHONY: asm
asm: build ## Generate assembly output for manual inspection
$(GO) test -tags=$(TAGS) -c -o hyperpb.test $(PKG) $(TESTFLAGS)
$(GO_HOST) run ./internal/tools/hyperdump \
-s '$(ASM_FILTER)' \
-info $(ASM_INFO) \
-prefix 'buf.build/go/hyperpb' \
-nops \
-o hyperpb.s \
hyperpb.test
.PHONY: build
build: generate ## Build all packages
$(GO) build -tags=$(TAGS) $(PKGS)
.PHONY: lint
lint: $(BIN)/golangci-lint ## Lint
$(GO_HOST) vet -unsafeptr=false ./...
$(BIN)/golangci-lint -v run \
--timeout 3m0s \
--modules-download-mode=readonly
.PHONY: lintfix
lintfix: $(BIN)/golangci-lint ## Automatically fix some lint errors
$(BIN)/golangci-lint run \
--timeout 3m0s \
--modules-download-mode=readonly \
--fix
.PHONY: generate
generate: internal/gen/*/*.pb.go $(BIN)/license-header ## Regenerate code and licenses
$(GO_HOST) generate ./...
$(BIN)/license-header \
--license-type apache \
--copyright-holder "Buf Technologies, Inc." \
--year-range "$(COPYRIGHT_YEARS)" \
--ignore $(LICENSE_IGNORE)
.PHONY: upgrade
upgrade: ## Upgrade dependencies
go get toolchain@none
go get -u -t ./...
go mod tidy -v
.PHONY: checkgenerate
checkgenerate:
@# Used in CI to verify that `make generate` doesn't produce a diff.
git --no-pager diff --exit-code >&2
internal/gen/*/*.pb.go: $(BIN)/buf internal/proto/*/*/*.proto internal/proto/*/*/*/*.proto
$(BIN)/buf generate --clean
$(BIN)/buf generate --template buf.vt.gen.yaml
.PHONY: $(BIN)/hypertest
$(BIN)/hypertest: generate
@mkdir -p $(@D)
$(GO_HOST) build -o $(BIN)/hypertest ./internal/tools/hypertest
$(BIN)/buf: Makefile
@mkdir -p $(@D)
$(GO_HOST) install github.com/bufbuild/buf/cmd/buf@$(BUF_VERSION)
$(BIN)/license-header: Makefile
@mkdir -p $(@D)
$(GO_HOST) install github.com/bufbuild/buf/private/pkg/licenseheader/cmd/license-header@$(BUF_VERSION)
$(BIN)/golangci-lint: Makefile
@mkdir -p $(@D)
$(GO_HOST) install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(LINT_VERSION)