Skip to content

Commit ec07b69

Browse files
authored
Streamline CMake and build system, move to newer protobuf (#150)
1 parent 953ae03 commit ec07b69

File tree

17 files changed

+454
-860
lines changed

17 files changed

+454
-860
lines changed

.github/workflows/appimage.yml

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,13 @@ jobs:
3131
uses: actions/checkout@v3
3232
with:
3333
submodules: recursive
34-
path: viam-cartographer
3534

3635
- name: Check out PR branch code
3736
if: github.event_name == 'pull_request_target'
3837
uses: actions/checkout@v3
3938
with:
4039
ref: ${{ github.event.pull_request.head.sha }}
4140
submodules: recursive
42-
path: viam-cartographer
4341

4442
- name: apt update
4543
run: |
@@ -48,31 +46,20 @@ jobs:
4846
- name: make clean
4947
run: |
5048
chown -R testbot:testbot .
51-
sudo -u testbot bash -lc 'cd viam-cartographer && make clean'
49+
sudo -u testbot bash -lc 'make clean'
5250
53-
- name: make bufinstall buf setup
54-
uses: nick-fields/retry@v2
55-
with:
56-
timeout_minutes: 5
57-
max_attempts: 3
58-
retry_on: timeout
59-
shell: bash
60-
command: |
61-
chown -R testbot:testbot .
62-
sudo -u testbot bash -lc 'cd viam-cartographer && make bufinstall buf setup'
63-
64-
- name: make build
51+
- name: make setup
6552
run: |
66-
sudo -u testbot bash -lc 'cd viam-cartographer && make build'
53+
sudo -u testbot bash -lc 'make setup'
6754
68-
- name: make install-lua-files
55+
- name: make build
6956
run: |
70-
sudo -u testbot bash -lc 'cd viam-cartographer && make install-lua-files'
57+
sudo -u testbot bash -lc 'make build'
7158
7259
- name: Build AppImage (PR)
7360
if: contains(github.event.pull_request.labels.*.name, 'appimage') || contains(github.event.pull_request.labels.*.name, 'appimage-ignore-tests')
7461
run: |
75-
sudo -u testbot bash -lc 'cd viam-cartographer && make BUILD_CHANNEL="pr-${{ github.event.pull_request.number }}" appimage'
62+
sudo -u testbot bash -lc 'make BUILD_CHANNEL="pr-${{ github.event.pull_request.number }}" appimage'
7663
7764
- name: Authorize GCP Upload
7865
uses: google-github-actions/auth@v1
@@ -84,22 +71,22 @@ jobs:
8471
uses: google-github-actions/upload-cloud-storage@v0.10.4
8572
with:
8673
headers: "cache-control: no-cache"
87-
path: 'viam-cartographer/etc/packaging/appimages/deploy/'
74+
path: 'etc/packaging/appimages/deploy/'
8875
destination: 'packages.viam.com/apps/slam-servers/'
8976
glob: '*'
9077
parent: false
9178
gzip: false
9279

9380
- name: Build AppImage (Latest)
9481
if: github.event_name == 'workflow_dispatch' || github.event_name == 'push'
95-
run: sudo -u testbot bash -lc 'cd viam-cartographer && make appimage-ci'
82+
run: sudo -u testbot bash -lc 'make appimage-ci'
9683

9784
- name: Deploy Files (Latest)
9885
if: github.event_name == 'workflow_dispatch' || github.event_name == 'push'
9986
uses: google-github-actions/upload-cloud-storage@v0.10.4
10087
with:
10188
headers: "cache-control: no-cache"
102-
path: 'viam-cartographer/etc/packaging/appimages/deploy/'
89+
path: 'etc/packaging/appimages/deploy/'
10390
destination: 'packages.viam.com/apps/slam-servers/'
10491
glob: '*'
10592
parent: false

.github/workflows/test.yml

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,59 +57,47 @@ jobs:
5757

5858
- name: apt update
5959
run: |
60-
sudo apt update
60+
apt-get update
6161
6262
- name: Verify no uncommitted changes from make lint
6363
run: |
6464
git init
6565
git add .
6666
chown -R testbot:testbot .
67-
sudo -u testbot bash -lc 'make lint-setup lint'
68-
GEN_DIFF=$(git status -s)
67+
sudo -u testbot bash -lc 'sudo apt-get install -y clang-format && make lint'
68+
GEN_DIFF=$(git status -s --ignore-submodules)
6969
7070
if [ -n "$GEN_DIFF" ]; then
7171
echo '"make lint" resulted in changes not in git' 1>&2
7272
git status
7373
exit 1
7474
fi
7575
76-
- name: make bufinstall buf setup setup-cpp-full-mod
77-
uses: nick-fields/retry@v2
78-
with:
79-
timeout_minutes: 5
80-
max_attempts: 3
81-
retry_on: timeout
82-
shell: bash
83-
command: |
84-
chown -R testbot:testbot .
85-
sudo -u testbot bash -lc 'make bufinstall buf setup setup-cpp-full-mod'
76+
- name: make setup
77+
run: |
78+
sudo -u testbot bash -lc 'make setup'
8679
8780
- name: make build
8881
run: |
8982
sudo -u testbot bash -lc 'make build'
9083
91-
- name: make install-lua-files
84+
- name: make install
9285
run: |
93-
sudo -u testbot bash -lc 'make install-lua-files'
86+
sudo -u testbot bash -lc 'make install'
9487
9588
- name: make test
9689
run: |
9790
sudo -u testbot bash -lc 'make test'
9891
99-
- name: Copy carto_grpc_server binary
100-
if: matrix.platform == 'linux/amd64'
101-
run: |
102-
sudo cp viam-cartographer/build/carto_grpc_server /usr/local/bin/carto_grpc_server
103-
10492
- name: Run viam-cartographer cartographer integration tests
10593
if: matrix.platform == 'linux/amd64'
10694
run: |
107-
sudo -u testbot bash -lc 'sudo go test -v -race -run TestCartographerIntegration'
95+
sudo -u testbot bash -lc 'go test -v -race -run TestCartographerIntegration'
10896
109-
- name: make test-cpp-full-mod-valgrind
97+
- name: make setup-cpp-full-mod test-cpp-full-mod-valgrind
11098
# Currently we only run valgrind on arm64 as x86
11199
# doesn't valgrind clean due to what appears to be a bug in GLOG
112100
# https://github.com/viamrobotics/viam-cartographer/actions/runs/5156238014/jobs/9287413446
113101
if: matrix.platform != 'linux/amd64'
114102
run: |
115-
sudo -u testbot bash -lc 'make test-cpp-full-mod-valgrind'
103+
sudo -u testbot bash -lc 'make setup-cpp-full-mod test-cpp-full-mod-valgrind'

Makefile

Lines changed: 65 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,43 @@
11
BUILD_CHANNEL?=local
2-
TOOL_BIN = bin/gotools/$(shell uname -s)-$(shell uname -m)
3-
PATH_WITH_TOOLS="`pwd`/$(TOOL_BIN):$(HOME)/go/bin/:${PATH}"
4-
GIT_REVISION = $(shell git rev-parse HEAD | tr -d '\n')
5-
TAG_VERSION?=$(shell git tag --points-at | sort -Vr | head -n1)
6-
GO_BUILD_LDFLAGS = -ldflags "-X 'main.Version=${TAG_VERSION}' -X 'main.GitRevision=${GIT_REVISION}'"
2+
TOOL_BIN := $(shell pwd)/bin/tools/$(shell uname -s)-$(shell uname -m)
3+
GIT_REVISION := $(shell git rev-parse HEAD | tr -d '\n')
4+
TAG_VERSION ?= $(shell git tag --points-at | sort -Vr | head -n1)
5+
GO_BUILD_LDFLAGS := -ldflags "-X 'main.Version=${TAG_VERSION}' -X 'main.GitRevision=${GIT_REVISION}'"
6+
SHELL := /usr/bin/env bash
7+
export PATH := $(TOOL_BIN):$(PATH)
8+
export GOBIN := $(TOOL_BIN)
9+
10+
ifneq (, $(shell which brew))
11+
EXTRA_CMAKE_FLAGS := -DCMAKE_PREFIX_PATH=$(shell brew --prefix) -DQt5_DIR=$(shell brew --prefix qt5)/lib/cmake/Qt5
12+
export PKG_CONFIG_PATH := $(shell brew --prefix openssl@3)/lib/pkgconfig
13+
endif
14+
15+
default: build
716

8-
ARTIFACT="~/go/bin/artifact"
17+
artifact-pull: $(TOOL_BIN)/artifact
18+
artifact pull
919

10-
artifact-pull:
11-
PATH=${PATH_WITH_TOOLS} artifact pull
20+
$(TOOL_BIN)/artifact:
21+
go install go.viam.com/utils/artifact/cmd/artifact
1222

13-
bufinstall:
14-
sudo apt-get install -y protobuf-compiler-grpc libgrpc-dev libgrpc++-dev || brew install grpc openssl --quiet
23+
$(TOOL_BIN)/buf:
24+
go install github.com/bufbuild/buf/cmd/buf@v1.8.0
1525

16-
bufsetup:
17-
GOBIN=`pwd`/grpc/bin go install github.com/bufbuild/buf/cmd/buf@v1.8.0
18-
ln -sf `which grpc_cpp_plugin` grpc/bin/protoc-gen-grpc-cpp
26+
$(TOOL_BIN)/protoc-gen-grpc-cpp:
27+
mkdir -p "$(TOOL_BIN)"
28+
which grpc_cpp_plugin && ln -sf `which grpc_cpp_plugin` $(TOOL_BIN)/protoc-gen-grpc-cpp
1929

20-
buf: bufsetup
21-
PATH="${PATH}:`pwd`/grpc/bin" buf generate --template ./buf/buf.gen.yaml buf.build/viamrobotics/api
22-
PATH="${PATH}:`pwd`/grpc/bin" buf generate --template ./buf/buf.grpc.gen.yaml buf.build/viamrobotics/api
23-
PATH="${PATH}:`pwd`/grpc/bin" buf generate --template ./buf/buf.gen.yaml buf.build/googleapis/googleapis
30+
buf: $(TOOL_BIN)/buf $(TOOL_BIN)/protoc-gen-grpc-cpp
31+
buf generate --template ./buf/buf.gen.yaml buf.build/viamrobotics/api
32+
buf generate --template ./buf/buf.grpc.gen.yaml buf.build/viamrobotics/api
33+
buf generate --template ./buf/buf.gen.yaml buf.build/googleapis/googleapis
2434

2535
clean:
26-
rm -rf grpc
27-
rm -rf bin
28-
rm -rf viam-cartographer/build
29-
rm -rf viam-cartographer/cartographer/build
36+
rm -rf grpc bin viam-cartographer/build
3037

3138
clean-all:
3239
git clean -fxd
40+
cd viam-cartographer/cartographer && git checkout . && git clean -fxd
3341

3442
ensure-submodule-initialized:
3543
@if [ ! -d "viam-cartographer/cartographer/cartographer" ]; then \
@@ -38,21 +46,8 @@ ensure-submodule-initialized:
3846
else \
3947
echo "Submodule found successfully"; \
4048
fi
41-
42-
lint-setup-cpp:
43-
ifeq ("Darwin", "$(shell uname -s)")
44-
brew install clang-format
45-
else
46-
sudo apt-get install -y clang-format
47-
endif
48-
49-
lint-setup-go:
50-
GOBIN=`pwd`/$(TOOL_BIN) go install \
51-
github.com/edaniels/golinters/cmd/combined \
52-
github.com/golangci/golangci-lint/cmd/golangci-lint \
53-
github.com/rhysd/actionlint/cmd/actionlint
54-
55-
lint-setup: lint-setup-cpp lint-setup-go
49+
grep -q viam-patched viam-cartographer/cartographer/CMakeLists.txt || \
50+
(cd viam-cartographer/cartographer && git checkout . && git apply ../cartographer_patches/carto.patch)
5651

5752
lint-cpp:
5853
find . -type f -not -path \
@@ -63,42 +58,46 @@ lint-cpp:
6358
-and \( -iname '*.h' -o -iname '*.cpp' -o -iname '*.cc' \) \
6459
| xargs clang-format -i --style="{BasedOnStyle: Google, IndentWidth: 4}"
6560

66-
lint-go:
61+
lint-go: $(TOOL_BIN)/combined $(TOOL_BIN)/golangci-lint $(TOOL_BIN)/actionlint
6762
go vet -vettool=$(TOOL_BIN)/combined ./...
68-
GOGC=50 $(TOOL_BIN)/golangci-lint run -v --fix --config=./etc/golangci.yaml
69-
PATH=$(PATH_WITH_TOOLS) actionlint
63+
GOGC=50 golangci-lint run -v --fix --config=./etc/golangci.yaml
64+
actionlint
65+
66+
$(TOOL_BIN)/combined $(TOOL_BIN)/golangci-lint $(TOOL_BIN)/actionlint:
67+
go install \
68+
github.com/edaniels/golinters/cmd/combined \
69+
github.com/golangci/golangci-lint/cmd/golangci-lint \
70+
github.com/rhysd/actionlint/cmd/actionlint
7071

7172
lint: ensure-submodule-initialized lint-cpp lint-go
7273

73-
setup: ensure-submodule-initialized
74-
ifeq ("Darwin", "$(shell uname -s)")
75-
cd viam-cartographer/scripts && ./setup_cartographer_macos.sh
74+
setup: install-dependencies ensure-submodule-initialized artifact-pull
75+
76+
install-dependencies:
77+
ifneq (, $(shell which brew))
78+
brew update
79+
brew install abseil boost ceres-solver protobuf ninja cairo googletest lua@5.3 pkg-config cmake go@1.20 grpc clang-format
80+
brew link lua@5.3
81+
brew install openssl@3 eigen gflags glog suite-sparse sphinx-doc pcl nlopt-static
82+
else ifneq (, $(shell which apt-get))
83+
$(warning "Installing cartographer external dependencies via APT.")
84+
$(warning "Packages may be too old to work with this project.")
85+
sudo apt-get update
86+
sudo apt-get install -y cmake ninja-build libgmock-dev libboost-iostreams-dev liblua5.3-dev libcairo2-dev python3-sphinx libnlopt-dev \
87+
libabsl-dev libceres-dev libprotobuf-dev protobuf-compiler protobuf-compiler-grpc libpcl-dev libgrpc-dev libgrpc++-dev clang-format
7688
else
77-
cd viam-cartographer/scripts && ./setup_cartographer_linux.sh
78-
endif
79-
@make artifact-pull
80-
81-
build: build-module
82-
ifneq ($(wildcard viam-cartographer/cartographer/build/.),)
83-
cd viam-cartographer && ./scripts/build_viam_cartographer.sh
84-
else
85-
cd viam-cartographer && ./scripts/build_cartographer.sh && ./scripts/build_viam_cartographer.sh
89+
$(error "Unsupported system. Only apt and brew currently supported.")
8690
endif
8791

88-
build-debug: build-module
89-
ifneq ($(wildcard viam-cartographer/cartographer/build/.),)
90-
cd viam-cartographer && ./scripts/build_viam_cartographer_debug.sh
91-
else
92-
cd viam-cartographer && ./scripts/build_cartographer.sh && ./scripts/build_viam_cartographer_debug.sh
93-
endif
92+
build: ensure-submodule-initialized buf build-module
93+
cd viam-cartographer && cmake -Bbuild -G Ninja ${EXTRA_CMAKE_FLAGS} && cmake --build build
94+
95+
build-debug: EXTRA_CMAKE_FLAGS += -DCMAKE_BUILD_TYPE=Debug -DFORCE_DEBUG_BUILD=True
96+
build-debug: build
9497

9598
build-module:
9699
mkdir -p bin && go build $(GO_BUILD_LDFLAGS) -o bin/cartographer-module module/main.go
97100

98-
install-lua-files:
99-
sudo mkdir -p /usr/local/share/cartographer/lua_files/
100-
sudo cp viam-cartographer/lua_files/* /usr/local/share/cartographer/lua_files/
101-
102101
test-cpp:
103102
viam-cartographer/build/unit_tests -p -l all
104103

@@ -122,7 +121,11 @@ test-go:
122121

123122
test: test-cpp test-go
124123

125-
install:
124+
install-lua-files:
125+
sudo mkdir -p /usr/local/share/cartographer/lua_files/
126+
sudo cp viam-cartographer/lua_files/* /usr/local/share/cartographer/lua_files/
127+
128+
install: install-lua-files
126129
sudo rm -f /usr/local/bin/carto_grpc_server
127130
sudo rm -f /usr/local/bin/cartographer-module
128131
sudo cp viam-cartographer/build/carto_grpc_server /usr/local/bin/carto_grpc_server

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,11 @@ These containers are set to persist between sessions via the `persistent` parame
8484
#### Setup, build, and run the binary
8585
8686
```bash
87-
# Setup the gRPC files
88-
make bufinstall && make buf
89-
# Install dependencies
87+
# Install dependencies using brew (or apt-get)
9088
make setup
91-
# Build & install the binary
89+
# Build
9290
make build
93-
# Install lua files
94-
make install-lua-files
95-
# Install the cartographer-module binary
91+
# Install lua files and binaries to /usr/local
9692
make install
9793
# Run the binary
9894
cartographer-module

cartofacade/cgo_api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package cartofacade
88
#cgo CFLAGS: -I../viam-cartographer/src/carto_facade
99
1010
// the libraries that need to be linked can be derived from line 258 of the build.ninja file that is autogenerated during make build
11-
#cgo LDFLAGS: -L../viam-cartographer/build -L../viam-cartographer/cartographer/build -lviam-cartographer -lcartographer -ldl -lm -labsl_hash -labsl_city -labsl_bad_optional_access -labsl_strerror -labsl_str_format_internal -labsl_synchronization -labsl_strings -labsl_throw_delegate -lcairo -llua5.3 -lstdc++ -lceres -lprotobuf -lglog -lboost_filesystem -lboost_iostreams -lpcl_io -lpcl_common -labsl_raw_hash_set
11+
#cgo LDFLAGS: -L../viam-cartographer/build -L../viam-cartographer/build/cartographer -lviam-cartographer -lcartographer -ldl -lm -labsl_hash -labsl_city -labsl_bad_optional_access -labsl_strerror -labsl_str_format_internal -labsl_synchronization -labsl_strings -labsl_throw_delegate -lcairo -llua5.3 -lstdc++ -lceres -lprotobuf -lglog -lboost_filesystem -lboost_iostreams -lpcl_io -lpcl_common -labsl_raw_hash_set
1212
1313
#include "../viam-cartographer/src/carto_facade/carto_facade.h"
1414

etc/packaging/appimages/cartographer-module-aarch64.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ script:
77
- mkdir -p $TARGET_APPDIR/usr/share/cartographer/lua_files
88
- cp ../../../bin/cartographer-module $TARGET_APPDIR/usr/bin/
99
- cp ../../../viam-cartographer/build/carto_grpc_server $TARGET_APPDIR/usr/bin/
10-
- cp ../../../viam-cartographer/cartographer/build/libcartographer.a $TARGET_APPDIR/usr/lib/
11-
- cp ../../../viam-cartographer/build/libviam-cartographer.a $TARGET_APPDIR/usr/lib/
1210
- cp ../../../viam-cartographer/lua_files/* $TARGET_APPDIR/usr/share/cartographer/lua_files
1311
- mkdir -p $TARGET_APPDIR/usr/share/icons/viam/256x256/apps/
1412
- cp ./viam-server.png $TARGET_APPDIR/usr/share/icons/viam/256x256/apps/viam-server.png
15-
- go install github.com/Otterverse/aix@latest
16-
- cp `go env GOPATH`/bin/aix $TARGET_APPDIR/usr/bin/
13+
- GOBIN=$TARGET_APPDIR/usr/bin/ go install github.com/Otterverse/aix@latest
1714
- chmod 755 $TARGET_APPDIR/usr/bin/*
1815

1916
AppDir:

etc/packaging/appimages/cartographer-module-x86_64.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@ script:
77
- mkdir -p $TARGET_APPDIR/usr/share/cartographer/lua_files
88
- cp ../../../bin/cartographer-module $TARGET_APPDIR/usr/bin/
99
- cp ../../../viam-cartographer/build/carto_grpc_server $TARGET_APPDIR/usr/bin/
10-
- cp ../../../viam-cartographer/cartographer/build/libcartographer.a $TARGET_APPDIR/usr/lib/
11-
- cp ../../../viam-cartographer/build/libviam-cartographer.a $TARGET_APPDIR/usr/lib/
1210
- cp ../../../viam-cartographer/lua_files/* $TARGET_APPDIR/usr/share/cartographer/lua_files
1311
- mkdir -p $TARGET_APPDIR/usr/share/icons/viam/256x256/apps/
1412
- cp ./viam-server.png $TARGET_APPDIR/usr/share/icons/viam/256x256/apps/viam-server.png
15-
- go install github.com/Otterverse/aix@latest
16-
- cp `go env GOPATH`/bin/aix $TARGET_APPDIR/usr/bin/
13+
- GOBIN=$TARGET_APPDIR/usr/bin/ go install github.com/Otterverse/aix@latest
1714
- chmod 755 $TARGET_APPDIR/usr/bin/*
1815

1916
AppDir:

0 commit comments

Comments
 (0)