-
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathMakefile
More file actions
142 lines (112 loc) · 4.04 KB
/
Copy pathMakefile
File metadata and controls
142 lines (112 loc) · 4.04 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
ARGS ?=
SUDO ?= sudo -E
ZEITGEIST_VERSION ?= v0.7.0
# Avoid cargo/nix warnings about HOME ownership when running via sudo
ifeq ($(shell id -u),0)
export HOME := /root
endif
KUBERNIX ?= $(SUDO) target/release/kubernix $(ARGS)
BUILD_DIR ?= build
COLOR := \033[36m
NOCOLOR := \033[0m
WIDTH := 30
all: build
.PHONY: help
help: ## Display this help.
@awk \
-v "col=${COLOR}" -v "nocol=${NOCOLOR}" \
' \
BEGIN { \
FS = ":.*##" ; \
printf "Usage:\n make %s<target>%s\n", col, nocol \
} \
/^[./a-zA-Z_-]+:.*?##/ { \
printf " %s%-${WIDTH}s%s %s\n", col, $$1, nocol, $$2 \
} \
/^##@/ { \
printf "\n%s\n", substr($$0, 5) \
} \
' $(MAKEFILE_LIST)
##@ Nix targets:
.PHONY: nix-update
nix-update: ## Update pinned nixpkgs to latest nixpkgs-unstable.
nix flake update nixpkgs
##@ Build targets:
.PHONY: clean
clean: kill ## Remove runtime data and build artifacts.
$(SUDO) rm -rf kubernix-run
cargo clean
.PHONY: build
build: ## Build in debug mode.
cargo build
.PHONY: build-release
build-release: ## Build in release mode.
cargo build --release
.PHONY: build-static
build-static: ## Build the static release binary for the host architecture.
RUSTFLAGS="-C target-feature=+crt-static" cargo build --release --target x86_64-unknown-linux-gnu
strip -s target/x86_64-unknown-linux-gnu/release/kubernix
ldd target/x86_64-unknown-linux-gnu/release/kubernix 2>&1 | grep -qE '(statically linked)|(not a dynamic executable)'
CROSS_TARGET ?= x86_64-unknown-linux-gnu
.PHONY: build-cross
build-cross: ## Cross-compile a static release binary via cross (set CROSS_TARGET).
RUSTFLAGS="-C target-feature=+crt-static" cross build --release --target $(CROSS_TARGET)
.PHONY: release-snapshot
release-snapshot: ## Build snapshot binaries for all supported targets.
$(MAKE) build-cross CROSS_TARGET=x86_64-unknown-linux-gnu
$(MAKE) build-cross CROSS_TARGET=aarch64-unknown-linux-gnu
$(MAKE) build-cross CROSS_TARGET=armv7-unknown-linux-gnueabihf
$(MAKE) build-cross CROSS_TARGET=powerpc64le-unknown-linux-gnu
$(MAKE) build-cross CROSS_TARGET=s390x-unknown-linux-gnu
$(MAKE) build-cross CROSS_TARGET=riscv64gc-unknown-linux-gnu
.PHONY: docs
docs: ## Build the documentation.
cargo doc --no-deps
##@ Lint targets:
.PHONY: lint-clippy
lint-clippy: ## Run clippy linter.
cargo clippy --all -- -D warnings
.PHONY: lint-rustfmt
lint-rustfmt: ## Check code formatting.
cargo fmt --check
.PHONY: lint-audit
lint-audit: ## Audit dependencies for security vulnerabilities.
cargo audit
.PHONY: lint-dependencies
lint-dependencies: ## Validate dependency versions via zeitgeist.
@test -x $(BUILD_DIR)/zeitgeist || { \
echo "Installing zeitgeist $(ZEITGEIST_VERSION)..."; \
mkdir -p $(BUILD_DIR); \
curl -sSfL https://github.com/kubernetes-sigs/zeitgeist/releases/download/$(ZEITGEIST_VERSION)/zeitgeist-amd64-linux \
-o $(BUILD_DIR)/zeitgeist && chmod +x $(BUILD_DIR)/zeitgeist; \
}
$(BUILD_DIR)/zeitgeist validate --local-only --base-path . --config dependencies.yaml
.PHONY: lint-deny
lint-deny: ## Check licenses and duplicate dependencies via cargo-deny.
cargo deny check
.PHONY: lint
lint: lint-clippy lint-rustfmt lint-audit lint-deny lint-dependencies ## Run all linters.
##@ Run targets:
.PHONY: run
run: build-release ## Run kubernix.
$(KUBERNIX)
.PHONY: shell
shell: build-release ## Run kubernix with a shell.
$(KUBERNIX) shell
.PHONY: kill
kill: ## Kill a running kubernix instance and unmount leftover volumes.
@if [ -f kubernix-run/kubernix.pid ]; then \
$(SUDO) kill $$(cat kubernix-run/kubernix.pid) 2>/dev/null; \
echo "Waiting for kubernix to shut down..."; \
timeout 15 sh -c 'while [ -f kubernix-run/kubernix.pid ]; do sleep 1; done' 2>/dev/null; \
fi
$(SUDO) sh -c 'grep -s kubernix-run /proc/mounts | cut -d" " -f2 | sort -r | xargs -r umount' 2>/dev/null || true
##@ Test targets:
.PHONY: test-unit
test-unit: ## Run unit tests.
cargo test --lib
.PHONY: test-coverage
test-coverage: ## Generate local LCOV coverage report.
cargo llvm-cov --all-features --lib --lcov --output-path lcov.info
.PHONY: test
test: test-unit ## Run all tests.