-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMakefile
More file actions
247 lines (222 loc) · 6.43 KB
/
Copy pathMakefile
File metadata and controls
247 lines (222 loc) · 6.43 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
.DEFAULT_GOAL := help
BLUE := $(shell tput -Txterm setaf 4)
YELLOW := $(shell tput -Txterm setaf 3)
GREEN := $(shell tput -Txterm setaf 2)
RESET := $(shell tput -Txterm sgr0)
.PHONY: help
help:
@echo ""
@echo "${YELLOW}Usage:${RESET} make ${GREEN}<target>${RESET}"
@echo ""
@awk ' \
/^##@@/ { gsub(/^##@@ */, ""); printf "\n${BLUE}%s${RESET}\n", toupper($$0); next } \
/^##@/ { gsub(/^##@ */, ""); printf " ${YELLOW}%s:${RESET}\n", $$0; next } \
/^## / { gsub(/^## */, ""); msg = $$0; next } \
/^[a-zA-Z0-9_-]+:/ { \
target = $$1; gsub(/:.*/, "", target); \
if (match($$0, /## */)) { \
msg = substr($$0, RSTART + RLENGTH); \
} \
if (msg != "") { \
printf " ${GREEN}%-18s${RESET} %s\n", target, msg; \
msg = ""; \
} \
} \
' $(MAKEFILE_LIST)
@echo ""
##@ Housekeeping
## Nukes the zig-out dir
clean-zig-out:
rm -rf zig-out
## Nukes the local zig cache dir if its > 16gb
clean-zig-cache:
@if [ -d .zig-cache ]; then \
size_kb=$$(du -s .zig-cache | cut -f1); \
limit_kb=$$((16 * 1024 * 1024)); \
if [ $$size_kb -gt $$limit_kb ]; then \
echo "removing .zig-cache (size: $$size_kb KB > $$limit_kb KB)"; \
rm -rf .zig-cache; \
fi; \
fi
##@ Development
## Format all zig files
fmt:
zig fmt ./
## Lint all zig files
lint:
zig build lint
##@ Testing
## Run unit tests
test: fmt
zig build test \
-Doptimize=Debug \
--summary all
## Run integration tests
test-integration: fmt
zig build test \
-Doptimize=Debug \
-Dintegration-tests=true \
--summary all
## Run functional tests
test-functional: fmt
zig build test \
-Doptimize=Debug \
-Dfunctional-tests=true \
--summary all
## Run functional tests (w/ limited ci platforms);
## ensures TERM set, since this is normally unset in GH actions
test-functional-ci: fmt
TERM=screen-256color zig build test \
-Doptimize=Debug \
-Dfunctional-tests=true \
-Dci-functional-tests=true \
--summary all
##@ Testing Coverage
## Run integration tests plus coverage (goes to zig-out/cover)
test-coverage: fmt
rm -rf zig-out/cover || true
zig build test \
-Dintegration-tests=true \
-Dtest-coverage=true \
--summary all
## Open the generated coverage report
open-coverage:
open zig-out/cover/index.html
##@ Test Environment
## Runs the clab functional testing topo; uses the clab launcher to run nicely on darwin
run-clab:
rm -r .clab/* || true
docker network rm clab || true
docker network create \
--driver bridge \
--subnet=172.20.20.0/24 \
--gateway=172.20.20.1 \
--ipv6 \
--subnet=2001:172:20:20::/64 \
--gateway=2001:172:20:20::1 \
--opt com.docker.network.driver.mtu=65535 \
--label containerlab \
clab
docker run \
-d \
--rm \
--name clab-launcher \
--platform=linux/arm64 \
--privileged \
--pid=host \
--stop-signal=SIGINT \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /run/netns:/run/netns \
-v "$$(pwd):$$(pwd)" \
-e "WORKDIR=$$(pwd)/.clab" \
-e "HOST_ARCH=$$(uname -m)" \
ghcr.io/scrapli/scrapli_clab/launcher:0.0.7
## Runs the clab functional testing topo with the ci specific topology - omits ceos
run-clab-ci:
mkdir .clab || true
rm -r .clab/* || true
docker network rm clab || true
docker network create \
--driver bridge \
--subnet=172.20.20.0/24 \
--gateway=172.20.20.1 \
--ipv6 \
--subnet=2001:172:20:20::/64 \
--gateway=2001:172:20:20::1 \
--opt com.docker.network.driver.mtu=65535 \
--label containerlab \
clab
docker run \
-d \
--rm \
--name clab-launcher \
--privileged \
--pid=host \
--stop-signal=SIGINT \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /run/netns:/run/netns \
-v "$$(pwd):$$(pwd)" \
-e "WORKDIR=$$(pwd)/.clab" \
-e "HOST_ARCH=$$(uname -m)" \
-e "CLAB_TOPO=topo.ci.$$(uname -m).yaml" \
ghcr.io/scrapli/scrapli_clab/launcher:0.0.7
##@ Build
## Build the shared object for the local system w/ release optimization
build: fmt clean-zig-cache
zig build ffi \
-Doptimize=ReleaseSafe \
-freference-trace=4 \
-Ddependency-linkage=static \
--summary all
## Build all the shared objects w/ release optimization and static deps
build-release: fmt clean-zig-out clean-zig-cache
zig build ffi \
-Doptimize=ReleaseSafe \
-freference-trace=4 \
-Ddependency-linkage=static \
-Dall-targets=true \
--summary all
find zig-out -type f \
\( -name 'libscrapli.*.dylib' -o -name 'libscrapli.so.*' \) \
-exec sha256sum {} + \
> zig-out/checksums.txt
## Build the shared object for the local system w/ release optimization and dynamic deps
build-release-dynamic: fmt clean-zig-cache
zig build ffi \
-Doptimize=ReleaseSafe \
-freference-trace=4 \
-Ddependency-linkage=dynamic \
--summary all
find zig-out -type f \
\( -name 'libscrapli.*.dylib' -o -name 'libscrapli.so.*' \) \
-exec sha256sum {} + \
> zig-out/checksums.txt
## Build the macOS release artifact with static deps
release-macos-static: clean-zig-cache
zig build ffi \
-Doptimize=ReleaseSafe \
-freference-trace=4 \
-Ddependency-linkage=static \
-Dtarget=aarch64-macos \
--summary all
## Build the macOS release artifact with dynamic deps
release-macos-dynamic: clean-zig-cache
zig build ffi \
-Doptimize=ReleaseSafe \
-freference-trace=4 \
-Ddependency-linkage=dynamic \
-Dtarget=aarch64-macos \
--summary all
## Build a linux release artifact with static deps
release-linux-static: clean-zig-cache
zig build ffi \
-Doptimize=ReleaseSafe \
-freference-trace=4 \
-Ddependency-linkage=static \
-Dtarget=$(TARGET) \
--summary all
## Build a linux release artifact with dynamic deps
release-linux-dynamic: clean-zig-cache
zig build ffi \
-Doptimize=ReleaseSafe \
-freference-trace=4 \
-Ddependency-linkage=dynamic \
-Dtarget=$(TARGET) \
--summary all
## Build the example binaries, uses Debug build so you get leak checking
build-examples: fmt clean-zig-cache
zig build examples \
-Doptimize=ReleaseSafe \
-freference-trace=4 \
-Ddependency-linkage=static \
--summary all
## Build the "main" binary in repo root, uses Debug build so you get leak checking
build-main: fmt clean-zig-cache
zig build main \
-Doptimize=ReleaseSafe \
-freference-trace=4 \
-Ddependency-linkage=static \
--summary all
## Build and run the "main" binary in repo root
run-main: fmt build-main
./zig-out/bin/scrapli