-
Notifications
You must be signed in to change notification settings - Fork 17
/
Makefile
162 lines (130 loc) · 6.78 KB
/
Makefile
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
BUILD_CHANNEL?=local
BUILD_DIR = build/$(shell uname -s)-$(shell uname -m)
BIN_OUTPUT_PATH = bin/$(shell uname -s)-$(shell uname -m)
TOOL_BIN := $(shell pwd)/bin/tools/$(shell uname -s)-$(shell uname -m)
GIT_REVISION := $(shell git rev-parse HEAD | tr -d '\n')
TAG_VERSION ?= $(shell git tag --points-at | sort -Vr | head -n1)
GO_BUILD_LDFLAGS := -ldflags "-X 'main.Version=${TAG_VERSION}' -X 'main.GitRevision=${GIT_REVISION}'"
CGO_BUILD_LDFLAGS := -L$(shell pwd)/viam-cartographer/$(BUILD_DIR) -L$(shell pwd)/viam-cartographer/$(BUILD_DIR)/cartographer
SHELL := /usr/bin/env bash
export PATH := $(TOOL_BIN):$(PATH)
export GOBIN := $(TOOL_BIN)
ifneq (, $(shell which brew))
EXTRA_CMAKE_FLAGS := -DCMAKE_PREFIX_PATH=$(shell brew --prefix) -DQt5_DIR=$(shell brew --prefix qt5)/lib/cmake/Qt5
export PKG_CONFIG_PATH := $(shell brew --prefix openssl@3)/lib/pkgconfig
endif
default: build
artifact-pull: $(TOOL_BIN)/artifact
artifact pull
$(TOOL_BIN)/artifact:
go install go.viam.com/utils/artifact/cmd/artifact
$(TOOL_BIN)/buf:
go install github.com/bufbuild/buf/cmd/[email protected]
$(TOOL_BIN)/protoc-gen-grpc-cpp:
mkdir -p "$(TOOL_BIN)"
which grpc_cpp_plugin && ln -sf `which grpc_cpp_plugin` $(TOOL_BIN)/protoc-gen-grpc-cpp
grpc/buf: $(TOOL_BIN)/buf $(TOOL_BIN)/protoc-gen-grpc-cpp
buf generate --template ./buf/buf.gen.yaml buf.build/viamrobotics/api
buf generate --template ./buf/buf.grpc.gen.yaml buf.build/viamrobotics/api
buf generate --template ./buf/buf.gen.yaml buf.build/googleapis/googleapis
# Touch this file so that we don't regenerate the buf compiled C++ files
# every time we build
@touch grpc/buf
grpc/buf_clean:
rm -rf grpc
clean:
rm -rf grpc $(BIN_OUTPUT_PATH) viam-cartographer/$(BUILD_DIR)
clean-all:
git clean -fxd
cd viam-cartographer/cartographer && git checkout . && git clean -fxd
ensure-submodule-initialized:
@if [ ! -d "viam-cartographer/cartographer/cartographer" ]; then \
echo "Submodule was not found. Initializing..."; \
git submodule update --init; \
else \
echo "Submodule found successfully"; \
fi
grep -q viam-patched viam-cartographer/cartographer/CMakeLists.txt || \
(cd viam-cartographer/cartographer && git checkout . && git apply ../cartographer_patches/carto.patch)
lint-cpp:
find . -type f -not -path \
-and ! -path '*viam-cartographer/cartographer*' \
-and ! -path '*viam-cartographer/build*' \
-and ! -path '*api*' \
-and ! -path '*grpc*' \
-and \( -iname '*.h' -o -iname '*.cpp' -o -iname '*.cc' \) \
| xargs clang-format -i --style="{BasedOnStyle: Google, IndentWidth: 4}"
lint-go: $(TOOL_BIN)/combined $(TOOL_BIN)/golangci-lint $(TOOL_BIN)/actionlint
go vet -vettool=$(TOOL_BIN)/combined ./...
GOGC=50 golangci-lint run -v --fix --config=./etc/golangci.yaml
actionlint
$(TOOL_BIN)/combined $(TOOL_BIN)/golangci-lint $(TOOL_BIN)/actionlint:
go install \
github.com/edaniels/golinters/cmd/combined \
github.com/golangci/golangci-lint/cmd/golangci-lint \
github.com/rhysd/actionlint/cmd/actionlint
lint: ensure-submodule-initialized lint-cpp lint-go
setup: install-dependencies ensure-submodule-initialized artifact-pull
install-dependencies:
ifneq (, $(shell which brew))
brew update
brew install abseil boost viamrobotics/brews/[email protected] viamrobotics/brews/[email protected] protobuf ninja cairo googletest [email protected] pkg-config cmake [email protected] grpc clang-format
brew link [email protected]
brew install openssl@3 eigen gflags glog sphinx-doc pcl viamrobotics/brews/nlopt-static
else ifneq (, $(shell which apt-get))
$(warning "Installing cartographer external dependencies via APT.")
$(warning "Packages may be too old to work with this project.")
sudo apt-get update
sudo apt-get install -y cmake ninja-build libgmock-dev libboost-iostreams-dev liblua5.3-dev libcairo2-dev python3-sphinx libnlopt-dev \
libabsl-dev libceres-dev libprotobuf-dev protobuf-compiler protobuf-compiler-grpc libpcl-dev libgrpc-dev libgrpc++-dev clang-format
else
$(error "Unsupported system. Only apt and brew currently supported.")
endif
build: cartographer-module
viam-cartographer/build/unit_tests: ensure-submodule-initialized
cd viam-cartographer && cmake -B$(BUILD_DIR) -G Ninja ${EXTRA_CMAKE_FLAGS} && cmake --build $(BUILD_DIR)
cartographer-module: viam-cartographer/build/unit_tests
rm -f $(BIN_OUTPUT_PATH)/cartographer-module && mkdir -p bin
# Newer versions of abseil require extra ld flags in our module, so this ugly thing.
# It's expected that if NOT using brew, a prebuilt environment (like canon) is in use with the older abseil installed.
absl_version=$$(brew list --versions abseil 2>/dev/null | head -n1 | grep -oE '[0-9]{8}' || echo 20010101); \
export CGO_LDFLAGS="$$CGO_LDFLAGS $(CGO_BUILD_LDFLAGS)"; \
test "$$absl_version" -gt "20230801" && export CGO_LDFLAGS="$$CGO_LDFLAGS -labsl_log_internal_message -labsl_log_internal_check_op" || true; \
go build $(GO_BUILD_LDFLAGS) -tags osusergo,netgo -o $(BIN_OUTPUT_PATH)/cartographer-module module/main.go
# Ideally build-asan would be added to build-debug, but can't yet
# as these options they fail on arm64 linux. This is b/c that
# platform currently uses gcc as opposed to clang & gcc doesn't
# support using asan in this way (more work would be needed to get it to work there).
# Ticket: https://viam.atlassian.net/browse/RSDK-3538 is the ticket to
# add full asan support
build-asan: EXTRA_CMAKE_FLAGS += -DCMAKE_CXXFLAGS="-fno-omit-frame-pointer -fsanitize=address -fsanitize-address-use-after-scope -O1" -DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address"
build-asan: export ASAN_OPTIONS= detect_leaks=1 detect_stack_use_after_return=true
build-asan: build-debug
build-debug: EXTRA_CMAKE_FLAGS += -DCMAKE_BUILD_TYPE=Debug -DFORCE_DEBUG_BUILD=True
build-debug: build
# Linux only
setup-cpp-debug:
sudo apt install -y valgrind gdb
test-cpp:
viam-cartographer/$(BUILD_DIR)/unit_tests -p -l all
# Linux only
test-cpp-valgrind: build-debug
valgrind --error-exitcode=1 --leak-check=full -s viam-cartographer/$(BUILD_DIR)/unit_tests -p -l all
# Linux only
test-cpp-gdb: build-debug
gdb --batch --ex run --ex bt --ex q --args viam-cartographer/$(BUILD_DIR)/unit_tests -p -l all
test-cpp-asan: build-asan
viam-cartographer/$(BUILD_DIR)/unit_tests -p -l all
test-go:
absl_version=$$(brew list --versions abseil 2>/dev/null | head -n1 | grep -oE '[0-9]{8}' || echo 20010101); \
export CGO_LDFLAGS="$$CGO_LDFLAGS $(CGO_BUILD_LDFLAGS)"; \
test "$$absl_version" -gt "20230801" && export CGO_LDFLAGS="$$CGO_LDFLAGS -labsl_log_internal_message -labsl_log_internal_check_op" || true; \
go test -race ./...
test: test-cpp test-go
install-lua-files:
sudo mkdir -p /usr/local/share/cartographer/lua_files/
sudo cp viam-cartographer/lua_files/* /usr/local/share/cartographer/lua_files/
install: install-lua-files
sudo rm -f /usr/local/bin/cartographer-module
sudo cp $(BIN_OUTPUT_PATH)/cartographer-module /usr/local/bin/cartographer-module
include *.make