summaryrefslogtreecommitdiff
path: root/Makefile
blob: 3ae72eab26eee5b025e25f3b7b5b1eac1fcfa79b (plain)
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
# Compiler and flags
CC = gcc
CFLAGS = -static -O2
GO_BUILD_FLAGS = -v
CGO_ENABLED = 1

# Paths
LAUNCHER_SRC = internal/namespace/launcher_src/launcher.c
LAUNCHER_BIN = internal/namespace/launcher.bin
BINARY = wg-wrap

# Fuzzing settings
FUZZ_PARALLEL ?= 2
FUZZ_TIME ?= 30s

.PHONY: all clean test fuzz $(BINARY)

# Default target: build the final binary
all: $(BINARY)

# Build the Go binary
# Use a temporary build file to ensure we don't leave a partially-built or stale binary
$(BINARY): $(LAUNCHER_BIN)
	CGO_ENABLED=$(CGO_ENABLED) go build $(GO_BUILD_FLAGS) -o $(BINARY).tmp cmd/wg-wrap/main.go && mv $(BINARY).tmp $(BINARY)

# Build the embedded C launcher binary
$(LAUNCHER_BIN): $(LAUNCHER_SRC)
	$(CC) $(CFLAGS) $(LAUNCHER_SRC) -o $(LAUNCHER_BIN)

# Test arguments (can be overridden from CLI: make test TEST_ARGS="-run TestName")
TEST_ARGS ?= -timeout 30s

# Run tests
test: $(BINARY)
	@echo "Running tests with WG_WRAP_BIN=$(shell pwd)/$(BINARY)"
	WG_WRAP_BIN=$(shell pwd)/$(BINARY) go test -v -race $(TEST_ARGS) ./...

# Run fuzzing tests
fuzz: clean
	$(MAKE) $(BINARY)
	@echo "Running fuzzing with WG_WRAP_BIN=$(shell pwd)/$(BINARY)"
	WG_WRAP_BIN=$(shell pwd)/$(BINARY) go test -v -race -fuzz=FuzzArgumentIntegrity -parallel $(FUZZ_PARALLEL) -fuzztime=$(FUZZ_TIME) ./tests/e2e/fuzz_args_test.go

clean:
	rm -f $(BINARY) $(LAUNCHER_BIN)