Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
204 lines (170 loc) · 7.79 KB
/
Copy pathMakefile
File metadata and controls
204 lines (170 loc) · 7.79 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
# Leba — production reverse proxy built with Mako.
#
# Requires Mako ≥ 0.5.1 (ownership drops, --release, MAKO_ALLOCATOR, SAFE model)
# with multi-module native IR compile support (mako#29, main ≥ 24f36a6).
# Install: https://github.com/loreste/mako (main or a release that includes #29).
#
# Backend: default remains **c** for CI/tests. Native compiles (mako#29) but
# still SIGSEGVs at runtime on Mako 0.5.2 (doctor_world string clone /
# struct-slice clone — mako#32, see docs/MAKO.md). Use `make build-native`
# only to re-validate native after a Mako upgrade.
#
# After upgrading Mako: `make clean-cache` then rebuild (object cache is not
# versioned across compiler revisions).
#
# Production build (default): --release (-O3 -flto) + mimalloc when available.
# Debug / ASan: make build-debug MAKO_RELEASE=0
MAKO ?= $(shell command -v mako)
MAKO_BACKEND ?= c
# Release by default so “make build” is the binary you ship.
MAKO_RELEASE ?= 1
ifeq ($(MAKO_RELEASE),1)
MAKO_RELEASE_FLAG := --release
else
MAKO_RELEASE_FLAG :=
endif
# Optional production allocator (Mako 0.4.11+). Auto-detect Homebrew mimalloc.
# Override: MAKO_ALLOCATOR=system | jemalloc | /path/to/libmimalloc.a
# Disable: MAKO_ALLOCATOR=system make build
MIMALLOC_PREFIX ?= $(shell brew --prefix mimalloc 2>/dev/null)
ifeq ($(origin MAKO_ALLOCATOR),undefined)
ifneq ($(wildcard $(MIMALLOC_PREFIX)/lib/libmimalloc.a),)
export MAKO_ALLOCATOR := $(MIMALLOC_PREFIX)/lib/libmimalloc.a
else ifneq ($(wildcard $(MIMALLOC_PREFIX)/lib/libmimalloc.dylib),)
export MAKO_ALLOCATOR := mimalloc
export MAKO_LDFLAGS := -L$(MIMALLOC_PREFIX)/lib
endif
endif
# Prefer in-tree quiche so HTTP/3 links when the third_party FFI build exists.
export MAKO_QUICHE_ROOT ?= $(shell if [ -f /Users/loreste/mako/runtime/third_party/quiche/target/release/libquiche.a ]; then echo /Users/loreste/mako/runtime/third_party/quiche; elif [ -f "$$HOME/mako/runtime/third_party/quiche/target/release/libquiche.a" ]; then echo "$$HOME/mako/runtime/third_party/quiche"; fi)
.PHONY: all build build-debug build-release build-c build-native check-mako test check \
doctor doctor-linux explain smoke run clean clean-cache \
test-linux-assets test-ha-assets test-docs test-haproxy-compare \
test-soak test-ha-peers test-concurrent test-adversarial \
test-full test-ci test-all bench-nginx bench-proxy-matrix
all: build
# Fail closed if Mako is missing or too old for Leba’s production path.
check-mako:
@command -v "$(MAKO)" >/dev/null 2>&1 || { echo "mako not found in PATH — install ≥ 0.5.1 from https://github.com/loreste/mako/releases" >&2; exit 1; }
@"$(MAKO)" version >/dev/null
@v=$$("$(MAKO)" version 2>/dev/null | sed -n 's/.*mako\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\).*/\1/p' | head -1); \
if [ -z "$$v" ]; then echo "could not parse mako version from: $$("$(MAKO)" version 2>&1)" >&2; exit 1; fi; \
major=$$(echo "$$v" | cut -d. -f1); minor=$$(echo "$$v" | cut -d. -f2); patch=$$(echo "$$v" | cut -d. -f3); \
ok=0; \
if [ "$$major" -gt 0 ]; then ok=1; fi; \
if [ "$$major" -eq 0 ] && [ "$$minor" -gt 5 ]; then ok=1; fi; \
if [ "$$major" -eq 0 ] && [ "$$minor" -eq 5 ] && [ "$$patch" -ge 1 ]; then ok=1; fi; \
if [ "$$ok" -ne 1 ]; then \
echo "Leba requires Mako ≥ 0.5.1 (found $$v). Upgrade: https://github.com/loreste/mako/releases" >&2; \
exit 1; \
fi; \
echo "mako ok: $$("$(MAKO)" version 2>&1 | head -1) backend=$(MAKO_BACKEND) release=$(MAKO_RELEASE) allocator=$${MAKO_ALLOCATOR:-system}"
build: check-mako
@echo "building leba: backend=$(MAKO_BACKEND) release=$(MAKO_RELEASE) allocator=$${MAKO_ALLOCATOR:-system}"
$(MAKO) build main.mko -o leba --backend $(MAKO_BACKEND) $(MAKO_RELEASE_FLAG)
# Fast iterate without -O3 / LTO.
build-debug:
$(MAKE) build MAKO_RELEASE=0 MAKO_ALLOCATOR=system
# Explicit production binary (same as default when MAKO_RELEASE=1).
build-release:
$(MAKE) build MAKO_RELEASE=1
# C backend (sanitizers, older Mako, or differential vs native).
build-c:
$(MAKE) build MAKO_BACKEND=c
# Force native (same as default when MAKO_BACKEND=native).
build-native:
$(MAKE) build MAKO_BACKEND=native
# Unit suites only (fast). Prefer these over `mako test .` (C redefinition).
test: check-mako
$(MAKO) test leba_core1_test.mko --backend $(MAKO_BACKEND)
$(MAKO) test leba_core2_test.mko --backend $(MAKO_BACKEND)
$(MAKO) test leba_web_test.mko --backend $(MAKO_BACKEND)
test-linux-assets:
test -f deploy/linux/leba.service
test -f deploy/linux/leba.env
test -f deploy/linux/leba.conf
test -f deploy/linux/admin-users.conf
test -f deploy/linux/sysctl.conf
grep -q 'ExecStart=/usr/local/bin/leba -f' deploy/linux/leba.service
grep -q 'LimitNOFILE=1048576' deploy/linux/leba.service
grep -q 'LEBA_CONFIG=/etc/leba/leba.conf' deploy/linux/leba.env
grep -q 'LEBA_ADMIN_AUTH=CHANGE_ME_ADMIN:CHANGE_ME_PASSWORD' deploy/linux/leba.env
grep -q 'bind 80' deploy/linux/leba.conf
grep -q 'state_file /var/lib/leba/state' deploy/linux/leba.conf
grep -q 'admin_users_file /etc/leba/admin-users.conf' deploy/linux/leba.conf
grep -q 'acme_webroot /var/lib/leba/acme' deploy/linux/leba.conf
grep -q 'acme_storage /var/lib/leba/acme-state' deploy/linux/leba.conf
grep -q 'acme_email' deploy/linux/leba.conf
test -f deploy/linux/leba-acme-renew.timer
test -f deploy/linux/leba-acme-renew.service
grep -q 'CHANGE_ME_KDF_ADMIN_PASSWORD' deploy/linux/admin-users.conf
grep -q '10.0.10.11:8080' deploy/linux/leba.conf
test-ha-assets:
test -f deploy/ha/README.md
test -f deploy/ha/keepalived.conf.example
test -f deploy/ha/docker-compose.ha.yml
test -f deploy/ha/leba-healthcheck.sh
test-docs:
test -f docs/PRODUCTION.md
test -f docs/LIMITS.md
test -f docs/ROADMAP.md
test -f docs/ADVERSARIAL_REVIEW.md
test -f docs/HA.md
test -f docs/SCORECARD.md
test -f docs/ACME.md
test -f docs/MAKO.md
test -f scripts/ha_peers_smoke.sh
test -f scripts/concurrent_smoke.sh
test -f scripts/adversarial_smoke.sh
test -f scripts/soak.sh
test -f scripts/bench_vs_nginx.sh
test -f scripts/bench_proxy_matrix.sh
test-adversarial: test test-linux-assets
chmod +x scripts/adversarial_smoke.sh
MAKO_BIN="$(MAKO)" ./scripts/adversarial_smoke.sh
test-concurrent: build
chmod +x scripts/concurrent_smoke.sh
./scripts/concurrent_smoke.sh 200
# Connection budget, keep-alive, body limit, reload under load.
test-soak: build
chmod +x scripts/soak.sh
./scripts/soak.sh 200 6
# Dual-node peers smoke: HELLO, proxy, stick UPSERT sync, reconnect.
test-ha-peers: build
chmod +x scripts/ha_peers_smoke.sh
./scripts/ha_peers_smoke.sh
test-haproxy-compare: build
chmod +x scripts/haproxy_compare.sh
./scripts/haproxy_compare.sh
# Pre-push local gate: units + assets + concurrent + adversarial (no multi-min soak).
test-full: test build test-linux-assets test-ha-assets test-docs test-concurrent test-adversarial
# Matches .github/workflows/ci.yml (units, assets, soak, peers).
test-ci: test build test-linux-assets test-ha-assets test-docs test-concurrent test-adversarial test-soak test-ha-peers
# Full matrix including optional HAProxy behavior sample (needs haproxy in PATH).
test-all: test-ci test-haproxy-compare
# Directional RPS/latency vs local nginx (requires nginx in PATH).
bench-nginx: build
chmod +x scripts/bench_vs_nginx.sh
./scripts/bench_vs_nginx.sh 8 40
# Docker-backed RPS/latency matrix vs nginx + HAProxy.
# Strict gate: LEBA_REQUIRE_WIN=1 make bench-proxy-matrix
bench-proxy-matrix: build
chmod +x scripts/bench_proxy_matrix.sh
./scripts/bench_proxy_matrix.sh 8 40
check: doctor
doctor: build
./leba doctor configs/leba.conf
doctor-linux: build
./leba doctor deploy/linux/leba.conf
explain: build
./leba explain configs/leba.conf GET /api/hello localhost
run: build
./leba -f configs/leba.conf
smoke: build
chmod +x scripts/smoke.sh
./scripts/smoke.sh
# Wipe Mako object cache after upgrading the compiler.
clean-cache:
rm -rf .mako/cache
clean: clean-cache
rm -f leba /tmp/leba /tmp/leba_origin