forked from xdp2-dev/xdp2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
370 lines (319 loc) · 13.9 KB
/
Copy pathMakefile
File metadata and controls
370 lines (319 loc) · 13.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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# Makefile for XDP2
#
# This Makefile provides convenient targets for building and testing XDP2
# using Nix. All builds are performed via Nix flakes.
#
# Usage:
# make help - Show all available targets
# make build - Build xdp2 (production)
# make test - Run all x86_64 tests
# make test-riscv64 - Run RISC-V tests via binfmt
#
# Output directories:
# result/ - Default xdp2 build
# result-debug/ - Debug build with assertions
# result-samples/ - Pre-built samples (native)
# result-riscv64/ - RISC-V cross-compiled xdp2
# result-riscv64-samples/ - RISC-V pre-built samples
# result-aarch64/ - AArch64 cross-compiled xdp2
# result-aarch64-samples/ - AArch64 pre-built samples
#
.PHONY: help build build-debug build-all clean
.PHONY: test test-all test-simple test-offset test-ports test-flow
.PHONY: samples samples-riscv64 samples-aarch64
.PHONY: riscv64 riscv64-debug riscv64-samples riscv64-tests test-riscv64 test-riscv64-vm
.PHONY: aarch64 aarch64-debug aarch64-samples aarch64-tests test-aarch64 test-aarch64-vm
.PHONY: vm-x86 vm-aarch64 vm-riscv64 vm-test-all
.PHONY: deb deb-x86
.PHONY: analysis analysis-quick analysis-standard analysis-deep
.PHONY: dev shell check eval
# Default target
.DEFAULT_GOAL := help
# =============================================================================
# Help
# =============================================================================
help:
@echo "XDP2 Build System (Nix-based)"
@echo ""
@echo "=== Quick Start ==="
@echo " make build Build xdp2 (production)"
@echo " make test Run all x86_64 tests"
@echo " make dev Enter development shell"
@echo ""
@echo "=== Native Builds (x86_64) ==="
@echo " make build Build xdp2 production -> result/"
@echo " make build-debug Build xdp2 with assertions -> result-debug/"
@echo " make samples Build pre-built samples -> result-samples/"
@echo ""
@echo "=== Native Tests ==="
@echo " make test Run all sample tests"
@echo " make test-simple Run simple_parser tests only"
@echo " make test-offset Run offset_parser tests only"
@echo " make test-ports Run ports_parser tests only"
@echo " make test-flow Run flow_tracker_combo tests only"
@echo ""
@echo "=== RISC-V Cross-Compilation ==="
@echo " make riscv64 Build xdp2 for RISC-V -> result-riscv64/"
@echo " make riscv64-debug Build debug xdp2 for RISC-V -> result-riscv64-debug/"
@echo " make riscv64-samples Build pre-built samples -> result-riscv64-samples/"
@echo " make test-riscv64 Run RISC-V tests via binfmt (requires binfmt enabled)"
@echo " make test-riscv64-vm Run RISC-V tests in MicroVM"
@echo ""
@echo "=== AArch64 Cross-Compilation ==="
@echo " make aarch64 Build xdp2 for AArch64 -> result-aarch64/"
@echo " make aarch64-debug Build debug xdp2 for AArch64 -> result-aarch64-debug/"
@echo " make aarch64-samples Build pre-built samples -> result-aarch64-samples/"
@echo " make test-aarch64 Run AArch64 tests via binfmt (requires binfmt enabled)"
@echo " make test-aarch64-vm Run AArch64 tests in MicroVM"
@echo ""
@echo "=== MicroVM Testing ==="
@echo " make vm-x86 Build x86_64 MicroVM -> result-vm-x86/"
@echo " make vm-aarch64 Build AArch64 MicroVM -> result-vm-aarch64/"
@echo " make vm-riscv64 Build RISC-V MicroVM -> result-vm-riscv64/"
@echo " make vm-test-all Run full VM lifecycle tests (all architectures)"
@echo ""
@echo "=== Static Analysis ==="
@echo " make analysis Run quick static analysis (alias for analysis-quick)"
@echo " make analysis-quick Run clang-tidy + cppcheck"
@echo " make analysis-standard Run + flawfinder, clang-analyzer, gcc-warnings"
@echo " make analysis-deep Run all 8 tools including gcc-analyzer, semgrep, sanitizers"
@echo ""
@echo "=== Packaging ==="
@echo " make deb Build Debian package -> result-deb/"
@echo ""
@echo "=== Development ==="
@echo " make dev Enter nix development shell"
@echo " make shell Alias for 'make dev'"
@echo " make check Verify nix flake"
@echo " make eval Evaluate all flake outputs (syntax check)"
@echo ""
@echo "=== Cleanup ==="
@echo " make clean Remove all result-* symlinks"
@echo " make gc Run nix garbage collection"
@echo ""
@echo "=== Prerequisites ==="
@echo " - Nix with flakes enabled"
@echo " - For RISC-V/AArch64 binfmt: boot.binfmt.emulatedSystems in NixOS config"
@echo ""
# =============================================================================
# Native Builds (x86_64)
# =============================================================================
# Build production xdp2
build:
@echo "Building xdp2 (production)..."
nix build .#xdp2 -o result
# Build debug xdp2 with assertions enabled
build-debug:
@echo "Building xdp2 (debug with assertions)..."
nix build .#xdp2-debug -o result-debug
# Build both production and debug
build-all: build build-debug
# Build pre-built samples (native x86_64)
samples:
@echo "Building native x86_64 samples..."
@echo "Note: Native samples are built at test runtime, this target is for reference"
nix build .#xdp-samples -o result-samples
# =============================================================================
# Native Tests (x86_64)
# =============================================================================
# Run all tests
test:
@echo "Running all x86_64 sample tests..."
nix run .#run-sample-tests
# Alias for test
test-all: test
# Run individual test suites
test-simple:
@echo "Running simple_parser tests..."
nix run .#tests.simple-parser
test-offset:
@echo "Running offset_parser tests..."
nix run .#tests.offset-parser
test-ports:
@echo "Running ports_parser tests..."
nix run .#tests.ports-parser
test-flow:
@echo "Running flow_tracker_combo tests..."
nix run .#tests.flow-tracker-combo
# =============================================================================
# RISC-V Cross-Compilation
# =============================================================================
# Build xdp2 for RISC-V (production)
riscv64:
@echo "Building xdp2 for RISC-V (production)..."
nix build .#xdp2-debug-riscv64 -o result-riscv64
# Build xdp2 for RISC-V (debug) - same as above, debug is default for cross
riscv64-debug: riscv64
# Build pre-built samples for RISC-V
# These are compiled on x86_64 host using xdp2-compiler, then cross-compiled to RISC-V
riscv64-samples:
@echo "Building pre-built samples for RISC-V..."
@echo " - xdp2-compiler runs on x86_64 host"
@echo " - Sample binaries are cross-compiled to RISC-V"
nix build .#prebuilt-samples-riscv64 -o result-riscv64-samples
# Build RISC-V test derivations
riscv64-tests:
@echo "Building RISC-V test derivations..."
nix build .#riscv64-tests.all -o result-riscv64-tests
# Run RISC-V tests via binfmt emulation (requires binfmt enabled)
# This runs RISC-V binaries directly on x86_64 via QEMU user-mode
test-riscv64: riscv64-samples
@echo "Running RISC-V tests via binfmt emulation..."
@echo "Prerequisites: boot.binfmt.emulatedSystems = [ \"riscv64-linux\" ];"
@echo ""
@if [ ! -f /proc/sys/fs/binfmt_misc/riscv64-linux ]; then \
echo "ERROR: RISC-V binfmt not registered!"; \
echo "Run: sudo systemctl restart systemd-binfmt.service"; \
exit 1; \
fi
@echo "Testing simple_parser (parser_notmpl)..."
./result-riscv64-samples/bin/parser_notmpl data/pcaps/tcp_ipv6.pcap
@echo ""
@echo "Testing simple_parser optimized (-O)..."
./result-riscv64-samples/bin/parser_notmpl -O data/pcaps/tcp_ipv6.pcap
@echo ""
@echo "Testing offset_parser..."
./result-riscv64-samples/bin/parser data/pcaps/tcp_ipv6.pcap
@echo ""
@echo "RISC-V binfmt tests completed!"
# Run RISC-V tests inside MicroVM
test-riscv64-vm:
@echo "Running RISC-V tests in MicroVM..."
nix run .#run-riscv64-tests
# =============================================================================
# AArch64 Cross-Compilation
# =============================================================================
# Build xdp2 for AArch64
aarch64:
@echo "Building xdp2 for AArch64..."
nix build .#xdp2-debug-aarch64 -o result-aarch64
# Build xdp2 for AArch64 (debug) - same as above, debug is default for cross
aarch64-debug: aarch64
# Build pre-built samples for AArch64
aarch64-samples:
@echo "Building pre-built samples for AArch64..."
@echo " - xdp2-compiler runs on x86_64 host"
@echo " - Sample binaries are cross-compiled to AArch64"
nix build .#prebuilt-samples-aarch64 -o result-aarch64-samples
# Build AArch64 test derivations
aarch64-tests:
@echo "Building AArch64 test derivations..."
nix build .#aarch64-tests.all -o result-aarch64-tests
# Run AArch64 tests via binfmt emulation (requires binfmt enabled)
test-aarch64: aarch64-samples
@echo "Running AArch64 tests via binfmt emulation..."
@echo "Prerequisites: boot.binfmt.emulatedSystems = [ \"aarch64-linux\" ];"
@echo ""
@if [ ! -f /proc/sys/fs/binfmt_misc/aarch64-linux ]; then \
echo "ERROR: AArch64 binfmt not registered!"; \
echo "Run: sudo systemctl restart systemd-binfmt.service"; \
exit 1; \
fi
@echo "Testing simple_parser (parser_notmpl)..."
./result-aarch64-samples/bin/parser_notmpl data/pcaps/tcp_ipv6.pcap
@echo ""
@echo "Testing simple_parser optimized (-O)..."
./result-aarch64-samples/bin/parser_notmpl -O data/pcaps/tcp_ipv6.pcap
@echo ""
@echo "Testing offset_parser..."
./result-aarch64-samples/bin/parser data/pcaps/tcp_ipv6.pcap
@echo ""
@echo "AArch64 binfmt tests completed!"
# Run AArch64 tests inside MicroVM
test-aarch64-vm:
@echo "Running AArch64 tests in MicroVM..."
nix run .#run-aarch64-tests
# =============================================================================
# MicroVM Testing
# =============================================================================
# Build MicroVMs for each architecture
vm-x86:
@echo "Building x86_64 MicroVM..."
nix build .#microvm-x86_64 -o result-vm-x86
vm-aarch64:
@echo "Building AArch64 MicroVM..."
nix build .#microvm-aarch64 -o result-vm-aarch64
vm-riscv64:
@echo "Building RISC-V MicroVM..."
nix build .#microvm-riscv64 -o result-vm-riscv64
# Run full VM lifecycle tests for all architectures
vm-test-all:
@echo "Running full VM lifecycle tests (all architectures)..."
nix run .#microvms.test-all
# =============================================================================
# Packaging
# =============================================================================
# Build Debian package for x86_64
deb:
@echo "Building Debian package..."
nix build .#deb-x86_64 -o result-deb
deb-x86: deb
# =============================================================================
# Static Analysis
# =============================================================================
# Quick analysis: clang-tidy + cppcheck
analysis: analysis-quick
analysis-quick:
@echo "Running quick static analysis (clang-tidy + cppcheck)..."
nix build .#analysis-quick -o result-analysis-quick
@echo ""
@cat result-analysis-quick/summary.txt
# Standard analysis: + flawfinder, clang-analyzer, gcc-warnings
analysis-standard:
@echo "Running standard static analysis..."
nix build .#analysis-standard -o result-analysis-standard
@echo ""
@cat result-analysis-standard/summary.txt
# Deep analysis: all 8 tools
analysis-deep:
@echo "Running deep static analysis (all tools)..."
nix build .#analysis-deep -o result-analysis-deep
@echo ""
@cat result-analysis-deep/summary.txt
# =============================================================================
# Development
# =============================================================================
# Enter development shell
dev:
@echo "Entering development shell..."
nix develop
shell: dev
# Verify flake
check:
@echo "Checking nix flake..."
nix flake check
# Evaluate all outputs (quick syntax/reference check)
eval:
@echo "Evaluating flake outputs..."
@echo "Native packages:"
nix eval .#xdp2 --apply 'x: x.name' 2>/dev/null && echo " xdp2: OK" || echo " xdp2: FAIL"
nix eval .#xdp2-debug --apply 'x: x.name' 2>/dev/null && echo " xdp2-debug: OK" || echo " xdp2-debug: FAIL"
@echo "Tests:"
nix eval .#tests.simple-parser --apply 'x: x.name' 2>/dev/null && echo " tests.simple-parser: OK" || echo " tests.simple-parser: FAIL"
nix eval .#tests.all --apply 'x: x.name' 2>/dev/null && echo " tests.all: OK" || echo " tests.all: FAIL"
@echo "RISC-V:"
nix eval .#xdp2-debug-riscv64 --apply 'x: x.name' 2>/dev/null && echo " xdp2-debug-riscv64: OK" || echo " xdp2-debug-riscv64: FAIL"
nix eval .#prebuilt-samples-riscv64 --apply 'x: x.name' 2>/dev/null && echo " prebuilt-samples-riscv64: OK" || echo " prebuilt-samples-riscv64: FAIL"
nix eval .#riscv64-tests.all --apply 'x: x.name' 2>/dev/null && echo " riscv64-tests.all: OK" || echo " riscv64-tests.all: FAIL"
@echo "AArch64:"
nix eval .#xdp2-debug-aarch64 --apply 'x: x.name' 2>/dev/null && echo " xdp2-debug-aarch64: OK" || echo " xdp2-debug-aarch64: FAIL"
nix eval .#prebuilt-samples-aarch64 --apply 'x: x.name' 2>/dev/null && echo " prebuilt-samples-aarch64: OK" || echo " prebuilt-samples-aarch64: FAIL"
nix eval .#aarch64-tests.all --apply 'x: x.name' 2>/dev/null && echo " aarch64-tests.all: OK" || echo " aarch64-tests.all: FAIL"
@echo "Analysis:"
nix eval .#analysis-quick --apply 'x: x.name' 2>/dev/null && echo " analysis-quick: OK" || echo " analysis-quick: FAIL"
nix eval .#analysis-standard --apply 'x: x.name' 2>/dev/null && echo " analysis-standard: OK" || echo " analysis-standard: FAIL"
nix eval .#analysis-deep --apply 'x: x.name' 2>/dev/null && echo " analysis-deep: OK" || echo " analysis-deep: FAIL"
@echo ""
@echo "All evaluations completed."
# =============================================================================
# Cleanup
# =============================================================================
# Remove all result symlinks
clean:
@echo "Removing result symlinks..."
rm -f result result-*
@echo "Done. Run 'make gc' to garbage collect nix store."
# Nix garbage collection
gc:
@echo "Running nix garbage collection..."
nix-collect-garbage -d