forked from viamrobotics/rdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
204 lines (160 loc) · 7.84 KB
/
Copy pathMakefile
File metadata and controls
204 lines (160 loc) · 7.84 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# TESTBUILD_OUTPUT_PATH should only be defined during testing
ifdef TESTBUILD_OUTPUT_PATH
BIN_OUTPUT_PATH = $(TESTBUILD_OUTPUT_PATH)
else
BIN_OUTPUT_PATH = bin/$(shell uname -s)-$(shell uname -m)
endif
TOOL_BIN = bin/gotools/$(shell uname -s)-$(shell uname -m)
BUILD_CHANNEL ?= local
PATH_WITH_TOOLS="`pwd`/$(TOOL_BIN):`pwd`/node_modules/.bin:${PATH}"
GIT_REVISION = $(shell git rev-parse HEAD | tr -d '\n')
TAG_VERSION?=$(shell ./etc/dev-version.sh | sed 's/^v//')
# VERSION_SUFFIX (e.g. +focal) tags a build variant; appended only when a version exists.
FULL_VERSION = $(TAG_VERSION)$(if $(TAG_VERSION),$(VERSION_SUFFIX))
DATE_COMPILED?=$(shell date +'%Y-%m-%d')
COMMON_LDFLAGS = -X 'go.viam.com/rdk/config.Version=${FULL_VERSION}' -X 'go.viam.com/rdk/config.GitRevision=${GIT_REVISION}' -X 'go.viam.com/rdk/config.DateCompiled=${DATE_COMPILED}'
ifdef BUILD_DEBUG
GCFLAGS = -gcflags "-N -l"
else
COMMON_LDFLAGS += -s -w
endif
LDFLAGS = -ldflags "$(COMMON_LDFLAGS)"
LDFLAGS_WRAPPER = -ldflags "-extld=$(shell pwd)/etc/ld_wrapper.sh $(COMMON_LDFLAGS)"
default: build lint server
setup:
bash etc/setup.sh
build: build-go
build-go:
go build ./...
GO_FILES=$(shell find . -name "*.go")
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
bin/$(GOOS)-$(GOARCH)/viam-cli: $(GO_FILES) Makefile go.mod go.sum
# no_cgo necessary here because of motionplan -> nlopt dependency.
# can be removed if you can run CGO_ENABLED=0 go build ./cli/viam on your local machine.
# CGO_ENABLED=0 is necessary after bedf954b to prevent go from sneakily doing a cgo build
CGO_ENABLED=0 go build $(GCFLAGS) $(LDFLAGS) -tags no_cgo -o $@ ./cli/viam
.PHONY: cli
cli: bin/$(GOOS)-$(GOARCH)/viam-cli
.PHONY: cli-ci
cli-ci: bin/$(GOOS)-$(GOARCH)/viam-cli
if [ -n "$(CI_RELEASE)" ]; then \
mkdir -p bin/deploy-ci/; \
cp $< bin/deploy-ci/viam-cli-$(CI_RELEASE)-$(GOOS)-$(GOARCH)$(EXE_SUFFIX); \
fi
NFPM_VERSION = v2.47.0
GAR_PROJECT ?= static-file-server-310021
GAR_REPO ?= viam
GAR_LOCATION ?= us
# GOOS=linux GOARCH=amd64|arm64 make deb-cli; set TAG_VERSION on a dirty tree (nfpm rejects empty)
.PHONY: deb-cli
deb-cli: bin/linux-$(GOARCH)/viam-cli
mkdir -p bin/deb
sed -e 's/$${DEB_ARCH}/$(GOARCH)/g' -e 's/$${DEB_VERSION}/$(TAG_VERSION)/g' \
etc/packaging/nfpm/viam-cli.yaml > bin/deb/.nfpm-$(GOARCH).yaml
# GOTOOLCHAIN=auto: nfpm needs a newer Go than go.mod; CI's setup-go pins GOTOOLCHAIN=local
GOOS= GOARCH= GOTOOLCHAIN=auto go run github.com/goreleaser/nfpm/v2/cmd/nfpm@$(NFPM_VERSION) package \
--config bin/deb/.nfpm-$(GOARCH).yaml --packager deb --target bin/deb/
# needs gcloud auth with artifactregistry.writer; re-runs skip versions already in the repo
.PHONY: deb-cli-upload
deb-cli-upload:
for deb in bin/deb/*.deb; do \
out=$$(gcloud artifacts apt upload $(GAR_REPO) --project=$(GAR_PROJECT) --location=$(GAR_LOCATION) --source=$$deb 2>&1) \
|| { echo "$$out" | grep -qi "already exists" && echo "skipping $$deb: already in repo" || { echo "$$out"; exit 1; }; }; \
done
tool-install:
GOBIN=`pwd`/$(TOOL_BIN) go install \
github.com/AlekSi/gocov-xml \
github.com/axw/gocov/gocov \
gotest.tools/gotestsum \
github.com/rhysd/actionlint/cmd/actionlint \
golang.org/x/tools/cmd/stringer
lint: lint-go actionlint
actionlint:
PATH=$(PATH_WITH_TOOLS) actionlint
generate-go: tool-install
PATH=$(PATH_WITH_TOOLS) go generate ./...
# Yes this regex could be more specific but making it more specific in a way
# that works the same across GNU and BSD grep isn't currently worth the effort.
GOVERSION = $(shell grep '^go .\..' go.mod | head -n1 | cut -d' ' -f2)
lint-go:
go mod tidy
GOTOOLCHAIN=go$(GOVERSION) GOGC=50 go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2 run --config=./etc/.golangci.yaml || true
GOTOOLCHAIN=go$(GOVERSION) GOGC=50 go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2 run -v --fix --config=./etc/.golangci.yaml
./etc/lint_register_apis.sh
cover-only: tool-install
PATH=$(PATH_WITH_TOOLS) ./etc/test.sh cover
cover: test-go cover-only
test-go: tool-install
PATH=$(PATH_WITH_TOOLS) ./etc/test.sh race
test-go-no-race: tool-install
PATH=$(PATH_WITH_TOOLS) ./etc/test.sh
# CGO is only supported on amd64/arm64; elsewhere build pure-Go with the no_cgo tag.
# GO_BUILD_TAGS_EXTRA (comma-separated) lets callers inject additional build tags that augment --
# never replace -- the arch-derived tags below. The focal channel passes
# viam_rdk_cgo_have_cxx20_rt to opt into the trajex-backed build; empty by default.
GO_BUILD_TAGS_EXTRA ?=
comma := ,
empty :=
space := $(empty) $(empty)
# Arch tag (no_cgo off amd64/arm64) plus any injected extras, assembled into a single
# comma-separated -tags flag (or nothing when there are no tags at all). Commas in
# GO_BUILD_TAGS_EXTRA are normalized to spaces first, so the value works whether it is passed
# comma- or space-separated.
SERVER_TAG_WORDS := $(strip $(if $(filter amd64 arm64,$(GOARCH)),,no_cgo) $(subst $(comma),$(space),$(GO_BUILD_TAGS_EXTRA)))
SERVER_GO_TAGS := $(if $(SERVER_TAG_WORDS),-tags $(subst $(space),$(comma),$(SERVER_TAG_WORDS)),)
SERVER_TARGETS := $(BIN_OUTPUT_PATH)/viam-server $(BIN_OUTPUT_PATH)/viam-server-static
$(SERVER_TARGETS): CGO_ENABLED := $(if $(filter amd64 arm64,$(GOARCH)),1,0)
$(SERVER_TARGETS): CGO_TAGS := $(SERVER_GO_TAGS)
$(BIN_OUTPUT_PATH)/viam-server: $(GO_FILES) Makefile go.mod go.sum
CGO_ENABLED=$(CGO_ENABLED) go build $(CGO_TAGS) $(GCFLAGS) $(LDFLAGS_WRAPPER) -o $@ ./web/cmd/server
# NOTE: the `server` make target is referenced in file_utils.go
.PHONY: server
server: $(BIN_OUTPUT_PATH)/viam-server
$(BIN_OUTPUT_PATH)/viam-server-static: $(GO_FILES) Makefile go.mod go.sum
CGO_ENABLED=$(CGO_ENABLED) VIAM_STATIC_BUILD=1 GOFLAGS=$(GOFLAGS) go build $(CGO_TAGS) $(GCFLAGS) $(LDFLAGS_WRAPPER) -o $@ ./web/cmd/server
# NOTE: the `server-static` make target is referenced in file_utils.go
.PHONY: server-static
server-static: $(BIN_OUTPUT_PATH)/viam-server-static
bin/static/viam-server-$(GOARCH): $(GO_FILES) Makefile go.mod go.sum
mkdir -p $(dir $@)
CGO_ENABLED=0 go build -tags no_cgo $(GCFLAGS) $(LDFLAGS) -o $@ ./web/cmd/server
.PHONY: full-static
full-static: bin/static/viam-server-$(GOARCH)
# should be kept in sync with the windows build in the BuildViamServer helper in testutils/file_utils.go
bin/windows/viam-server-amd64.exe: $(GO_FILES) Makefile go.mod go.sum
mkdir -p $(dir $@)
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -tags no_cgo $(GCFLAGS) $(LDFLAGS) -o $@ ./web/cmd/server
.PHONY: windows
windows: bin/windows/viam-server-amd64.exe
cd bin/windows && zip viam.zip viam-server-amd64.exe
$(BIN_OUTPUT_PATH)/viam-server-static-compressed: $(BIN_OUTPUT_PATH)/viam-server-static
cp $< $@
upx --best --lzma $@
.PHONY: server-static-compressed
server-static-compressed: $(BIN_OUTPUT_PATH)/viam-server-static-compressed
clean-all:
git clean -fxd
license-check:
license_finder version
license_finder
FFMPEG_ROOT ?= etc/FFmpeg
$(FFMPEG_ROOT):
cd etc && git clone https://github.com/FFmpeg/FFmpeg.git --depth 1 --branch release/6.1
# For ARM64 builds, use the image ghcr.io/viamrobotics/antique:arm64 for backward compatibility
FFMPEG_PREFIX ?= $(shell realpath .)/gostream/ffmpeg/$(shell uname -s)-$(shell uname -m)
# See compilation guide here https://trac.ffmpeg.org/wiki/CompilationGuide
FFMPEG_OPTS = --disable-programs --disable-doc --disable-everything --prefix=$(FFMPEG_PREFIX) --disable-autodetect --disable-x86asm
ifeq ($(shell uname -m),aarch64)
# We only support hardware encoding on a Raspberry Pi.
FFMPEG_OPTS += --enable-encoder=h264_v4l2m2m
FFMPEG_OPTS += --enable-v4l2-m2m
endif
ffmpeg: $(FFMPEG_ROOT)
cd $(FFMPEG_ROOT) && ($(MAKE) distclean || true)
cd $(FFMPEG_ROOT) && ./configure $(FFMPEG_OPTS)
cd $(FFMPEG_ROOT) && $(MAKE)
cd $(FFMPEG_ROOT) && $(MAKE) install
# Only keep archive files. Different architectures can share the same source files.
find $(FFMPEG_PREFIX)/* -type d ! -wholename $(FFMPEG_PREFIX)/lib | xargs rm -rf
include *.make