-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
149 lines (127 loc) · 5.21 KB
/
Copy pathMakefile
File metadata and controls
149 lines (127 loc) · 5.21 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
# Kalshi C++ SDK - Root Makefile
# Wraps CMake for convenient day-to-day workflow
BUILD_DIR := build
CPP_AUTO_AUDIT := python3 tools/cpp_auto_audit.py
CMAKE := cmake
NPROC := $(shell nproc 2>/dev/null || echo 4)
BENCH_ITERATIONS := 254
.PHONY: all build debug test lint clean configure configure-debug help bench bench-compare format pre-commit install-hooks coverage run-get_markets run-basic_usage run-get_daily_temp
# Default target
all: build
# Configure CMake (if needed)
configure:
@mkdir -p $(BUILD_DIR)
@cd $(BUILD_DIR) && $(CMAKE) .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
# Configure CMake for a Debug build (-O0 -g, sanitizer-friendly)
configure-debug:
@mkdir -p $(BUILD_DIR)
@cd $(BUILD_DIR) && $(CMAKE) .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
# Build all targets
build: configure
@$(CMAKE) --build $(BUILD_DIR) -j$(NPROC)
# Build all targets with Debug symbols + -O0 (for gdb/valgrind/asan)
debug: configure-debug
@$(CMAKE) --build $(BUILD_DIR) -j$(NPROC)
# Run tests
test: build
@cd $(BUILD_DIR) && ctest --output-on-failure
# Run linting (clang-format check)
lint:
@if command -v clang-format >/dev/null 2>&1; then \
echo "Checking code formatting..."; \
find src include tests examples \( -name '*.cpp' -o -name '*.hpp' \) -print0 | \
xargs -0 clang-format --dry-run --Werror && \
echo "Format check passed."; \
else \
echo "clang-format not found. Install clang-format to run lint."; \
exit 1; \
fi
$(CPP_AUTO_AUDIT)
# Format code in place
format:
@if command -v clang-format >/dev/null 2>&1; then \
echo "Formatting code..."; \
find src include tests examples \( -name '*.cpp' -o -name '*.hpp' \) -print0 | xargs -0 clang-format -i; \
echo "Done"; \
else \
echo "clang-format not found. Install clang-format to format code."; \
exit 1; \
fi
# pre-commit: auto-format, then lint. Run before every commit to avoid
# the recurring "push -> Linux CI lint fail -> follow-up fix PR" loop.
# `format` is idempotent (running it again is a no-op) so this target
# is safe to wire into a git pre-commit hook (see install-hooks below).
pre-commit: format lint
# install-hooks: drop a .git/hooks/pre-commit shim that runs `make pre-commit`
# automatically on `git commit`. One-shot operator setup — no-op if the
# hook is already installed.
install-hooks:
@mkdir -p .git/hooks
@if [ -f .git/hooks/pre-commit ] && grep -q 'make pre-commit' .git/hooks/pre-commit 2>/dev/null; then \
echo "pre-commit hook already installed"; \
else \
printf '#!/bin/sh\nexec make pre-commit\n' > .git/hooks/pre-commit; \
chmod +x .git/hooks/pre-commit; \
echo "Installed .git/hooks/pre-commit -> make pre-commit"; \
fi
# Code coverage (requires lcov)
coverage:
@mkdir -p build-coverage
@cd build-coverage && $(CMAKE) .. -DCMAKE_BUILD_TYPE=Debug -DKALSHI_ENABLE_COVERAGE=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
@$(CMAKE) --build build-coverage -j$(NPROC)
@cd build-coverage && ctest --output-on-failure
@lcov --capture --directory build-coverage --output-file build-coverage/coverage.info --ignore-errors mismatch
@lcov --remove build-coverage/coverage.info '/usr/*' '*/build-coverage/_deps/*' --output-file build-coverage/coverage_filtered.info --ignore-errors unused
@genhtml build-coverage/coverage_filtered.info --output-directory build-coverage/coverage-report
@echo "Coverage report: build-coverage/coverage-report/index.html"
# Clean build artifacts
clean:
@rm -rf $(BUILD_DIR) build-coverage
@echo "Cleaned build directory"
# Run benchmark
bench: build
@./tools/bench.sh $(BENCH_ITERATIONS)
# Compare benchmarks between HEAD and working tree (or two refs)
bench-compare:
@./tools/bench.sh --compare $(BENCH_ITERATIONS)
# Load .env and run example (creates temp PEM if KALSHI_API_PRIVATE_KEY is set)
define run_example
@if [ -f .env ]; then \
set -a && . ./.env && set +a && \
if [ -n "$$KALSHI_API_PRIVATE_KEY" ] && [ -z "$$KALSHI_API_KEY_FILE" ]; then \
TMPFILE=$$(mktemp) && \
echo "$$KALSHI_API_PRIVATE_KEY" | base64 -d | openssl rsa -inform DER -outform PEM -out $$TMPFILE 2>/dev/null && \
KALSHI_API_KEY_FILE=$$TMPFILE $(1) ; \
rm -f $$TMPFILE; \
else \
$(1); \
fi; \
else \
$(1); \
fi
endef
# Run examples
run-get_markets: build
$(call run_example,./$(BUILD_DIR)/examples/example_markets)
run-basic_usage: build
$(call run_example,./$(BUILD_DIR)/examples/example_basic)
run-get_daily_temp: build
$(call run_example,./$(BUILD_DIR)/examples/example_daily_temp)
# Help
help:
@echo "Kalshi C++ SDK Build System"
@echo ""
@echo "Targets:"
@echo " make build - Configure and build the SDK (Release)"
@echo " make debug - Configure and build the SDK (Debug: -O0 -g, sanitizer-friendly)"
@echo " make test - Run tests"
@echo " make bench - Run benchmark ($(BENCH_ITERATIONS) iterations)"
@echo " make bench-compare - Compare HEAD vs working tree"
@echo " make lint - Check code formatting"
@echo " make format - Format code in place"
@echo " make coverage - Generate code coverage report (requires lcov)"
@echo " make clean - Remove build artifacts"
@echo " make help - Show this help"
@echo ""
@echo "Variables:"
@echo " BENCH_ITERATIONS=N - Override benchmark iterations (default: 254)"