-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
145 lines (119 loc) · 4.91 KB
/
Copy pathMakefile
File metadata and controls
145 lines (119 loc) · 4.91 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
BIN_NAME := aikey
VERSION := $(shell grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
CARGO := $(shell command -v cargo 2>/dev/null || echo $$HOME/.cargo/bin/cargo)
.PHONY: all release dev rebuild run test test-integration test-unit test-verbose \
lint fmt fmt-check install uninstall cross-compile clean help
# Default: release build (production-ready)
all: release
# ---------------------------------------------------------------------------
# Build
# ---------------------------------------------------------------------------
## Build optimized release binary → target/release/aikey
release:
$(CARGO) build --release
## Build debug binary (fast iteration) → target/debug/aikey
dev:
$(CARGO) build
## Force full recompile (clean + release)
rebuild:
$(CARGO) clean
$(CARGO) build --release
## Run release binary
run: release
./target/release/$(BIN_NAME)
# ---------------------------------------------------------------------------
# Test
# ---------------------------------------------------------------------------
## Run all tests
test:
$(CARGO) test
## Run integration tests only
test-integration:
$(CARGO) test --test '*'
## Run unit tests only
test-unit:
$(CARGO) test --lib
## Run tests with output visible
test-verbose:
$(CARGO) test -- --nocapture
# ---------------------------------------------------------------------------
# Code quality
# ---------------------------------------------------------------------------
## Lint with clippy (warnings as errors)
lint:
$(CARGO) clippy -- -D warnings
## Auto-format source
fmt:
$(CARGO) fmt
## Format check (CI)
fmt-check:
$(CARGO) fmt -- --check
# ---------------------------------------------------------------------------
# Install / uninstall
# ---------------------------------------------------------------------------
## Install release binary to ~/.aikey/bin (ad-hoc signed on macOS)
install: release
@mkdir -p $(HOME)/.aikey/bin
cp target/release/$(BIN_NAME) $(HOME)/.aikey/bin/$(BIN_NAME)
chmod 755 $(HOME)/.aikey/bin/$(BIN_NAME)
ifeq ($(shell uname -s),Darwin)
@xattr -d com.apple.provenance $(HOME)/.aikey/bin/$(BIN_NAME) 2>/dev/null || true
@codesign -fs - $(HOME)/.aikey/bin/$(BIN_NAME) 2>/dev/null || true
@echo "macOS: cleared provenance & re-signed"
endif
## Remove installed binary
uninstall:
$(CARGO) uninstall aikeylabs-aikey-cli 2>/dev/null || true
# ---------------------------------------------------------------------------
# Cross-compile
# ---------------------------------------------------------------------------
CROSS_OUT := target/cross
## Build release binaries for macOS / Linux / Windows
cross-compile:
@mkdir -p $(CROSS_OUT)
$(CARGO) build --release --target aarch64-apple-darwin
cp target/aarch64-apple-darwin/release/$(BIN_NAME) $(CROSS_OUT)/$(BIN_NAME)-$(VERSION)-darwin-arm64
$(CARGO) build --release --target x86_64-apple-darwin
cp target/x86_64-apple-darwin/release/$(BIN_NAME) $(CROSS_OUT)/$(BIN_NAME)-$(VERSION)-darwin-amd64
$(CARGO) build --release --target x86_64-unknown-linux-gnu
cp target/x86_64-unknown-linux-gnu/release/$(BIN_NAME) $(CROSS_OUT)/$(BIN_NAME)-$(VERSION)-linux-amd64
$(CARGO) build --release --target x86_64-pc-windows-gnu
cp target/x86_64-pc-windows-gnu/release/$(BIN_NAME).exe $(CROSS_OUT)/$(BIN_NAME)-$(VERSION)-windows-amd64.exe
@echo "Binaries written to $(CROSS_OUT)/"
# ---------------------------------------------------------------------------
# Clean
# ---------------------------------------------------------------------------
## Remove build artifacts
clean:
$(CARGO) clean
# ---------------------------------------------------------------------------
# Help
# ---------------------------------------------------------------------------
## Show this help
help:
@echo "Usage: make [target]"
@echo ""
@echo "Build:"
@printf " %-22s %s\n" "make / make release" "Release binary (default)"
@printf " %-22s %s\n" "make dev" "Debug binary (fast iteration)"
@printf " %-22s %s\n" "make rebuild" "Force full recompile"
@printf " %-22s %s\n" "make run" "Build release and run"
@echo ""
@echo "Test:"
@printf " %-22s %s\n" "make test" "All tests"
@printf " %-22s %s\n" "make test-unit" "Unit tests only"
@printf " %-22s %s\n" "make test-integration" "Integration tests only"
@printf " %-22s %s\n" "make test-verbose" "Tests with stdout visible"
@echo ""
@echo "Quality:"
@printf " %-22s %s\n" "make lint" "Clippy (warnings as errors)"
@printf " %-22s %s\n" "make fmt" "Auto-format source"
@printf " %-22s %s\n" "make fmt-check" "Format check (CI)"
@echo ""
@echo "Install:"
@printf " %-22s %s\n" "make install" "Install to ~/.cargo/bin"
@printf " %-22s %s\n" "make uninstall" "Remove installed binary"
@printf " %-22s %s\n" "make cross-compile" "All platform binaries"
@printf " %-22s %s\n" "make clean" "Remove build artifacts"
@echo ""
@echo "Version: $(VERSION)"