-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMakefile
More file actions
331 lines (265 loc) · 10.9 KB
/
Makefile
File metadata and controls
331 lines (265 loc) · 10.9 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# -------------------------------------------------------------------
# Configuration
# -------------------------------------------------------------------
VERSION ?= $(shell perl -ne 'print $$1 if /^version\s*=\s*"(.+)"/' Cargo.toml)
IMAGE ?= praxis
V ?=
UNAME_S := $(shell uname -s | tr A-Z a-z)
UNAME_M := $(shell uname -m)
ifneq ($(V),)
_NOCAPTURE := -- --nocapture
endif
.PHONY: all build release check clean \
test test-unit \
test-schema test-integration test-conformance \
test-security test-security-suite test-resilience test-smoke \
bench \
lint fmt doc audit coverage coverage-check \
fuzz fuzz-build \
container container-run \
test-container test-container-run \
run-echo run-debug \
tools clean-tools \
help
# -------------------------------------------------------------------
# All
# -------------------------------------------------------------------
all: build fmt lint test audit container
# -------------------------------------------------------------------
# Build
# -------------------------------------------------------------------
build:
cargo build --workspace
cargo build --workspace --benches
cargo build --manifest-path tests/fuzz/Cargo.toml
release:
cargo build --workspace --release
check:
cargo check --workspace
clean:
cargo clean
# -------------------------------------------------------------------
# Container
# -------------------------------------------------------------------
container:
podman build -t $(IMAGE):$(VERSION) -f Containerfile . || \
docker build -t $(IMAGE):$(VERSION) -f Containerfile .
container-run:
podman run --rm --network=host $(IMAGE):$(VERSION) 2>&1 || \
docker run --rm --network=host $(IMAGE):$(VERSION) 2>&1
# -------------------------------------------------------------------
# Test Container
# -------------------------------------------------------------------
test-container:
podman build --ignorefile Containerfile.test.dockerignore \
-t $(IMAGE)-test:$(VERSION) -f Containerfile.test . || \
docker build -t $(IMAGE)-test:$(VERSION) -f Containerfile.test .
test-container-run: test-container
podman run --rm -v $(CURDIR):/src -v praxis-test-cache:/cache \
$(IMAGE)-test:$(VERSION) 2>&1 || \
docker run --rm -v $(CURDIR):/src -v praxis-test-cache:/cache \
$(IMAGE)-test:$(VERSION) 2>&1
# -------------------------------------------------------------------
# Test
# -------------------------------------------------------------------
test: $(H2SPEC)
PATH="$(BINUTILS_PATH):$(PATH)" cargo test --workspace $(_NOCAPTURE)
test-unit:
cargo test -p praxis-proxy-core $(_NOCAPTURE)
cargo test -p praxis-proxy-filter $(_NOCAPTURE)
cargo test -p praxis-proxy-protocol $(_NOCAPTURE)
cargo test -p praxis $(_NOCAPTURE)
test-schema:
cargo test -p praxis-tests-schema $(_NOCAPTURE)
test-integration:
cargo test -p praxis-tests-integration $(_NOCAPTURE)
test-conformance: $(H2SPEC)
PATH="$(BINUTILS_PATH):$(PATH)" cargo test -p praxis-tests-conformance $(_NOCAPTURE)
test-security: test-security-suite
test-security-suite:
cargo test -p praxis-tests-security $(_NOCAPTURE)
test-resilience:
cargo test -p praxis-tests-resilience $(_NOCAPTURE)
test-config-validation: test-schema
test-config: test-schema
test-smoke:
cargo test -p praxis-tests-smoke $(_NOCAPTURE)
# -------------------------------------------------------------------
# Bench
# -------------------------------------------------------------------
# Fortio builds are not available on GitHub for Darwin (Mac OSX)
# To install Fortio on the Mac, use `brew install fortio`.
ifeq ($(UNAME_S),darwin)
FORTIO_DEP :=
ifeq (, $(shell which fortio))
$(error "No fortio in $(PATH), consider doing 'brew install fortio'")
endif
else
FORTIO_DEP := $(FORTIO)
endif
bench: $(VEGETA) $(FORTIO_DEP)
PATH="$(BINUTILS_PATH):$(PATH)" cargo bench -p benchmarks
# -------------------------------------------------------------------
# Fuzz
# -------------------------------------------------------------------
FUZZ_DURATION ?= 120
fuzz:
cargo +nightly fuzz run --fuzz-dir tests/fuzz fuzz_sni -- -max_total_time=$(FUZZ_DURATION)
cargo +nightly fuzz run --fuzz-dir tests/fuzz fuzz_path_sanitize -- -max_total_time=$(FUZZ_DURATION)
cargo +nightly fuzz run --fuzz-dir tests/fuzz fuzz_config_parse -- -max_total_time=$(FUZZ_DURATION)
cargo +nightly fuzz run --fuzz-dir tests/fuzz fuzz_filter_pipeline -- -max_total_time=$(FUZZ_DURATION)
fuzz-build:
cargo +nightly fuzz build --fuzz-dir tests/fuzz
# -------------------------------------------------------------------
# Quality
# -------------------------------------------------------------------
lint:
cargo clippy --workspace --all-targets -- -D warnings
cargo +nightly fmt --all -- --check
fmt:
cargo +nightly fmt --all
doc:
RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --document-private-items
audit:
cargo audit
cargo deny check
coverage:
cargo llvm-cov --workspace --html --output-dir target/coverage \
--exclude praxis-tests-conformance \
--ignore-filename-regex '(target/|tests/|xtask/|benchmarks/)' \
--fail-under-lines 90
coverage-check:
cargo llvm-cov --workspace \
--exclude praxis-tests-conformance \
--ignore-filename-regex '(target/|tests/|xtask/|benchmarks/)' \
--fail-under-lines 90
# -------------------------------------------------------------------
# Dev tools
# -------------------------------------------------------------------
run-echo:
cargo xtask echo
run-debug:
cargo xtask debug
# -------------------------------------------------------------------
# Binutils
# -------------------------------------------------------------------
BINUTILS_DIR ?= target/praxis-binutils
BINUTILS_PATH := $(abspath $(BINUTILS_DIR))
H2SPEC_VERSION := 2.6.0
VEGETA_VERSION := 12.13.0
FORTIO_VERSION := 1.75.1
H2SPEC := $(BINUTILS_DIR)/h2spec
VEGETA := $(BINUTILS_DIR)/vegeta
FORTIO := $(BINUTILS_DIR)/fortio
# The MacOS / OSX sha256 command does not support the needed options.
# On the Mac, do `brew install coreutils` to install gsha256sum, a GNU-compatible sha256sum
SHA256SUM := sha256sum
ifeq ($(UNAME_S),darwin)
SHA256SUM := gsha256sum
ifeq (, $(shell which gsha256sum))
$(error "No gsha256sum in $(PATH), consider doing 'brew install coreutils'")
endif
endif
# Map architecture names
ifeq ($(UNAME_M),x86_64)
ARCH_GO := amd64
else ifeq ($(UNAME_M),aarch64)
ARCH_GO := arm64
else
ARCH_GO := $(UNAME_M)
endif
$(BINUTILS_DIR):
mkdir -p $(BINUTILS_DIR)
H2SPEC_SHA256_linux_amd64 := 157ee0de702e01ad40e752dbf074b366027e550c8e7504f9450da2809e279318
H2SPEC_SHA256_darwin_amd64 := 981cb9f90a6f5e36300063022bd4eb7438d3dcf66d63a146a8541359697d1601
# h2spec has no arm64 builds; fall back to amd64.
ifeq ($(ARCH_GO),arm64)
H2SPEC_ARCH := amd64
else
H2SPEC_ARCH := $(ARCH_GO)
endif
H2SPEC_SHA256 := $(H2SPEC_SHA256_$(UNAME_S)_$(H2SPEC_ARCH))
$(H2SPEC): | $(BINUTILS_DIR)
curl -sSfL -o $(BINUTILS_DIR)/h2spec.tar.gz \
https://github.com/summerwind/h2spec/releases/download/v$(H2SPEC_VERSION)/h2spec_$(UNAME_S)_$(H2SPEC_ARCH).tar.gz
$(if $(H2SPEC_SHA256),echo "$(H2SPEC_SHA256) $(BINUTILS_DIR)/h2spec.tar.gz" | $(SHA256SUM) -c,)
tar xz -C $(BINUTILS_DIR) -f $(BINUTILS_DIR)/h2spec.tar.gz h2spec
rm -f $(BINUTILS_DIR)/h2spec.tar.gz
VEGETA_SHA256_linux_amd64 := e8759ce45c14e18374bdccd3ba6068197bc3a9f9b7e484db3837f701b9d12e61
VEGETA_SHA256_linux_arm64 := 950381173a5575e25e8e086f36fc03bf65d61a2433329b48e41e1cb5e4133bba
VEGETA_SHA256_darwin_amd64 := 4e912c83ce07db4e1e394e1cbb657f2396dff2f7ed90f03869a184cc17d0f994
VEGETA_SHA256 := $(VEGETA_SHA256_$(UNAME_S)_$(ARCH_GO))
$(VEGETA): | $(BINUTILS_DIR)
curl -sSfL -o $(BINUTILS_DIR)/vegeta.tar.gz \
https://github.com/tsenart/vegeta/releases/download/v$(VEGETA_VERSION)/vegeta_$(VEGETA_VERSION)_$(UNAME_S)_$(ARCH_GO).tar.gz
$(if $(VEGETA_SHA256),echo "$(VEGETA_SHA256) $(BINUTILS_DIR)/vegeta.tar.gz" | $(SHA256SUM) -c,)
tar xz -C $(BINUTILS_DIR) -f $(BINUTILS_DIR)/vegeta.tar.gz vegeta
rm -f $(BINUTILS_DIR)/vegeta.tar.gz
FORTIO_SHA256_linux_amd64 := 92da34238dee258191a9dc6691c8bc75305b308951e934e2c3b4e658db0d77d1
FORTIO_SHA256_linux_arm64 := f66275a56ef41e9a5afb2ea8181eb53ca36b34c6d19a201b58aec17dbe95a853
FORTIO_SHA256 := $(FORTIO_SHA256_$(UNAME_S)_$(ARCH_GO))
$(FORTIO): | $(BINUTILS_DIR)
curl -sSfL -o $(BINUTILS_DIR)/fortio.tgz \
https://github.com/fortio/fortio/releases/download/v$(FORTIO_VERSION)/fortio-$(UNAME_S)_$(ARCH_GO)-$(FORTIO_VERSION).tgz
$(if $(FORTIO_SHA256),echo "$(FORTIO_SHA256) $(BINUTILS_DIR)/fortio.tgz" | $(SHA256SUM) -c,)
tar xz -C $(BINUTILS_DIR) -f $(BINUTILS_DIR)/fortio.tgz usr/bin/fortio --strip-components=2
rm -f $(BINUTILS_DIR)/fortio.tgz
tools: $(H2SPEC) $(VEGETA) $(FORTIO_DEP)
clean-tools:
rm -rf $(BINUTILS_DIR)
# -------------------------------------------------------------------
# Help
# -------------------------------------------------------------------
help:
@echo "Variables:"
@echo " V=1 show test output (--nocapture)"
@echo ""
@echo "Top-level:"
@echo " all build + lint + test + audit"
@echo ""
@echo "Build:"
@echo " build cargo build --workspace"
@echo " release cargo build --workspace --release"
@echo " check cargo check --workspace"
@echo " clean cargo clean"
@echo ""
@echo "Test:"
@echo " test run all tests"
@echo " test-unit unit tests (core, filter, protocol, praxis)"
@echo " test-schema config validation + example tests"
@echo " test-integration integration tests only"
@echo " test-conformance conformance tests only"
@echo " test-security security test suite"
@echo " test-security-suite security tests only"
@echo " test-resilience resilience tests only"
@echo " test-config-validation alias for test-schema"
@echo " test-config alias for test-schema"
@echo " test-smoke smoke tests only"
@echo ""
@echo "Bench:"
@echo " bench Criterion micro-benchmarks"
@echo ""
@echo "Fuzz (requires cargo-fuzz + nightly):"
@echo " fuzz run all fuzz targets (FUZZ_DURATION=60)"
@echo " fuzz-build build fuzz targets without running"
@echo ""
@echo "Quality:"
@echo " lint clippy + rustfmt check"
@echo " fmt format with nightly rustfmt"
@echo " audit cargo audit + cargo deny"
@echo " coverage HTML coverage report"
@echo " coverage-check fail if line coverage < 90%%"
@echo ""
@echo "Container:"
@echo " container build container image"
@echo " container-run run container in foreground (host network)"
@echo " test-container build test container image"
@echo " test-container-run build and run test suite in container"
@echo ""
@echo "Binutils (target/praxis-binutils/):"
@echo " tools download all external CLI tools"
@echo " clean-tools remove downloaded tools"
@echo ""
@echo "Dev tools:"
@echo " run-echo start echo server (xtask)"
@echo " run-debug start debug server (xtask)"