-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
264 lines (220 loc) · 7.92 KB
/
Makefile
File metadata and controls
264 lines (220 loc) · 7.92 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
# nvctl Makefile
# Build and development automation
.PHONY: all build release debug build-docker docker-image install clean check test lint fmt doc help
.PHONY: ci ci-quick ci-full run completions install-completions
# Disable parallel execution to avoid cargo lock conflicts
.NOTPARALLEL:
# Configuration
BINARY := nvctl
BIN_DIR := bin
CARGO := cargo
INSTALL_PATH := /usr/local/bin
DOCKER_IMAGE := nvctl-builder
# Default target
all: build
# =============================================================================
# Build Targets
# =============================================================================
## Build release binary to bin/
build: release
## Build optimized release binary
release:
@mkdir -p $(BIN_DIR)
$(CARGO) build --release
@cp target/release/$(BINARY) $(BIN_DIR)/$(BINARY)
@echo "Built: $(BIN_DIR)/$(BINARY)"
## Build debug binary
debug:
@mkdir -p $(BIN_DIR)
$(CARGO) build
@cp target/debug/$(BINARY) $(BIN_DIR)/$(BINARY)-debug
@echo "Built: $(BIN_DIR)/$(BINARY)-debug"
## Build Docker image with dependencies
docker-image:
docker build -t $(DOCKER_IMAGE) .
## Build release binary using Docker
build-docker:
@mkdir -p .cache/registry .cache/git
docker run --rm --user $(shell id -u):$(shell id -g) \
-v $(shell pwd):/app \
-v $(shell pwd)/.cache/registry:/usr/local/cargo/registry \
-v $(shell pwd)/.cache/git:/usr/local/cargo/git \
-w /app $(DOCKER_IMAGE) make build
## Install binary to system (requires sudo)
install: release
@sudo cp $(BIN_DIR)/$(BINARY) $(INSTALL_PATH)/$(BINARY)
@echo "Installed: $(INSTALL_PATH)/$(BINARY)"
## Remove build artifacts
clean:
$(CARGO) clean
@rm -rf $(BIN_DIR) $(COMPLETIONS_DIR)
@echo "Cleaned build artifacts"
# =============================================================================
# Quality Checks
# =============================================================================
## Run all checks (fmt, lint, test)
check: fmt-check lint test
@echo "All checks passed!"
## Run tests
test:
$(CARGO) test
## Run clippy linter
lint:
$(CARGO) clippy -- -D warnings
## Check code formatting
fmt-check:
$(CARGO) fmt --check
## Format code
fmt:
$(CARGO) fmt
## Generate documentation
doc:
$(CARGO) doc --no-deps --open
## Check documentation builds
doc-check:
$(CARGO) doc --no-deps
# =============================================================================
# CI Targets
# =============================================================================
## Quick CI check (fmt + lint + test)
ci-quick: fmt-check lint test
@echo "CI quick checks passed!"
## Full CI pipeline (clean build + all checks + release)
ci-full: clean fmt-check lint test release
@echo "CI full pipeline passed!"
@echo "Binary: $(BIN_DIR)/$(BINARY)"
@ls -lh $(BIN_DIR)/$(BINARY)
## Alias for ci-full
ci: ci-full
# =============================================================================
# GUI Targets
# =============================================================================
.PHONY: gui gui-dev gui-check gui-test gui-build gui-build-docker gui-clean
## Run GUI in release mode (smooth animations)
gui:
cargo run --release --package nvctl-gui
## Run GUI in debug mode
gui-dev:
cargo run --package nvctl-gui
## Check GUI code (fmt + clippy)
gui-check:
cargo fmt --package nvctl-gui -- --check
cargo clippy --package nvctl-gui -- -D warnings
## Run GUI tests
gui-test:
cargo test --package nvctl-gui
## Build GUI release binary
gui-build:
cargo build --release --package nvctl-gui
@echo "Binary: target/release/nvctl-gui"
## Build GUI release binary using Docker
gui-build-docker:
@mkdir -p .cache/registry .cache/git
docker run --rm --user $(shell id -u):$(shell id -g) \
-v $(shell pwd):/app \
-v $(shell pwd)/.cache/registry:/usr/local/cargo/registry \
-v $(shell pwd)/.cache/git:/usr/local/cargo/git \
-w /app $(DOCKER_IMAGE) \
cargo build --release --package nvctl-gui
@echo "Binary: target/release/nvctl-gui"
## Clean GUI build artifacts
gui-clean:
cargo clean --package nvctl-gui
# =============================================================================
# Development
# =============================================================================
## Run debug build
run: debug
./$(BIN_DIR)/$(BINARY)-debug $(ARGS)
## Run release build
run-release: release
./$(BIN_DIR)/$(BINARY) $(ARGS)
## Watch for changes and run tests
watch:
$(CARGO) watch -x test
## Show binary size info
size: release
@echo "Binary size:"
@ls -lh $(BIN_DIR)/$(BINARY)
@echo ""
@echo "Stripped size estimate:"
@strip -o /tmp/$(BINARY)-stripped $(BIN_DIR)/$(BINARY) && ls -lh /tmp/$(BINARY)-stripped
# =============================================================================
# Shell Completions
# =============================================================================
COMPLETIONS_DIR := completions
## Generate shell completions for all shells
completions: release
@mkdir -p $(COMPLETIONS_DIR)
@echo "Generating bash completions..."
@./$(BIN_DIR)/$(BINARY) completions bash > $(COMPLETIONS_DIR)/$(BINARY).bash
@echo "Generating zsh completions..."
@./$(BIN_DIR)/$(BINARY) completions zsh > $(COMPLETIONS_DIR)/_$(BINARY)
@echo "Generating fish completions..."
@./$(BIN_DIR)/$(BINARY) completions fish > $(COMPLETIONS_DIR)/$(BINARY).fish
@echo "Completions generated in $(COMPLETIONS_DIR)/"
@ls -la $(COMPLETIONS_DIR)/
## Install completions to system directories (requires sudo)
install-completions: completions
@echo "Installing bash completions..."
@sudo install -Dm644 $(COMPLETIONS_DIR)/$(BINARY).bash /usr/share/bash-completion/completions/$(BINARY)
@echo "Installing zsh completions..."
@sudo install -Dm644 $(COMPLETIONS_DIR)/_$(BINARY) /usr/share/zsh/site-functions/_$(BINARY)
@echo "Installing fish completions..."
@sudo install -Dm644 $(COMPLETIONS_DIR)/$(BINARY).fish /usr/share/fish/vendor_completions.d/$(BINARY).fish
@echo "Completions installed!"
@echo ""
@echo "Reload your shell or run:"
@echo " bash: source /usr/share/bash-completion/completions/$(BINARY)"
@echo " zsh: compinit"
@echo " fish: (automatic)"
# =============================================================================
# Help
# =============================================================================
## Show this help
help:
@echo "nvctl - NVIDIA GPU Control Tool"
@echo ""
@echo "Usage: make [target]"
@echo ""
@echo "Build:"
@echo " build Build release binary to bin/"
@echo " release Build optimized release binary"
@echo " debug Build debug binary"
@echo " build-docker Build using Docker container"
@echo " docker-image Build Docker image with dependencies"
@echo " install Install to $(INSTALL_PATH) (requires sudo)"
@echo " clean Remove build artifacts"
@echo ""
@echo "Quality:"
@echo " check Run all checks (fmt, lint, test)"
@echo " test Run tests"
@echo " lint Run clippy linter"
@echo " fmt Format code"
@echo " fmt-check Check code formatting"
@echo " doc Generate and open documentation"
@echo ""
@echo "CI:"
@echo " ci Full CI pipeline (clean + checks + release)"
@echo " ci-quick Quick checks (fmt + lint + test)"
@echo " ci-full Full CI pipeline"
@echo ""
@echo "GUI:"
@echo " gui Run GUI (release mode, smooth animations)"
@echo " gui-dev Run GUI (debug mode)"
@echo " gui-check Check GUI (fmt + clippy)"
@echo " gui-test Run GUI tests"
@echo " gui-build Build GUI release binary"
@echo " gui-build-docker Build GUI using Docker container"
@echo " gui-clean Clean GUI build artifacts"
@echo ""
@echo "Completions:"
@echo " completions Generate shell completions to completions/"
@echo " install-completions Install completions system-wide (requires sudo)"
@echo ""
@echo "Development:"
@echo " run Build and run debug binary"
@echo " run-release Build and run release binary"
@echo " size Show binary size info"
@echo ""
@echo "Pass arguments with: make run ARGS='list --format json'"