This repository has been archived by the owner on Nov 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
360 lines (300 loc) · 10.8 KB
/
Makefile
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
.DEFAULT_GOAL := help
SHELL = /bin/bash
# ARCHVARIANT: arm64, armv7, amd64
# CARGO: cargo, cross
# DENY_CHECK_WHICH: advisories, bans, licenses, sources
# GRCOV_COVERAGE_TYPE: cobertura, lcov, html
# MESSAGE_FORMAT: human, json
# MIRI_SUB_COMMAND: run, test
# NIGHTLY: +nightly
# PACKAGE: fip_api
# RELEASE: --release
# STRIP: aarch64-linux-gnu-strip, arm-linux-gnueabihf-strip, strip
# TARGET: aarch64-unknown-linux-musl, armv7-unknown-linux-musleabihf, x86_64-unknown-linux-musl
# VERSION: 0.1.0
ARCHVARIANT ?= $(shell rustup show | sed -n "s/^Default host: \(.*\)/\1/p" | cut -d "-" -f 1)
CARGO ?= cargo
DENY_CHECK_WHICH ?= advisories bans licenses sources
GRCOV_COVERAGE_TYPE ?= lcov
MESSAGE_FORMAT ?= human
PACKAGE ?= fip_api
MIRI_SUB_COMMAND ?= run
# RELEASE ?= --release
STRIP ?= strip
TARGET ?= $(shell rustup show | sed -n "s/^Default host: \(.*\)/\1/p")
VERSION ?= 0.1.0
TARGET_DIR := target/$(TARGET)
BIN_DIR := $(TARGET_DIR)/debug
ifdef RELEASE
BIN_DIR := $(TARGET_DIR)/release
endif
BIN := $(BIN_DIR)/$(PACKAGE)
BIN_NAME := $(PACKAGE)-v$(VERSION)-$(ARCHVARIANT)
COVERAGE_DIR := $(TARGET_DIR)/cov
DETECTED_OS := $(shell uname 2>/dev/null || echo "Windows")
DOCUMENTATION_DIR := $(TARGET_DIR)/doc
CARGO_BENCH = $(CARGO) $(NIGHTLY) bench --all-features --all-targets --frozen --message-format $(MESSAGE_FORMAT) --package $(PACKAGE) $(RELEASE) --target $(TARGET)
CARGO_BUILD = $(CARGO) $(NIGHTLY) build --all-features --all-targets --frozen --message-format $(MESSAGE_FORMAT) --package $(PACKAGE) $(RELEASE) --target $(TARGET)
CARGO_CHECK = $(CARGO) $(NIGHTLY) check --all-features --all-targets --frozen --message-format $(MESSAGE_FORMAT) --package $(PACKAGE) $(RELEASE) --target $(TARGET)
CARGO_CLEAN = $(CARGO) $(NIGHTLY) clean --frozen --package $(PACKAGE) $(RELEASE) --target $(TARGET)
CARGO_DOC = $(CARGO) $(NIGHTLY) doc --all-features --document-private-items --frozen --no-deps --message-format $(MESSAGE_FORMAT) --package $(PACKAGE) $(RELEASE) --target $(TARGET)
CARGO_FETCH = $(CARGO) $(NIGHTLY) fetch --locked --target $(TARGET)
CARGO_FIX = $(CARGO) $(NIGHTLY) fix --all-features --all-targets --frozen --message-format $(MESSAGE_FORMAT) --package $(PACKAGE) $(RELEASE) --target $(TARGET)
CARGO_RUN = $(CARGO) $(NIGHTLY) run --all-features --frozen --message-format $(MESSAGE_FORMAT) --package $(PACKAGE) $(RELEASE) --target $(TARGET)
CARGO_TEST = $(CARGO) $(NIGHTLY) test --all-features --all-targets --frozen --message-format $(MESSAGE_FORMAT) --package $(PACKAGE) $(RELEASE) --target $(TARGET)
CARGO_AUDIT = $(CARGO) audit
CARGO_CLIPPY = $(CARGO) clippy --all-features --all-targets --frozen --message-format $(MESSAGE_FORMAT) --workspace -- \
--deny clippy::all \
--deny clippy::cargo \
--deny clippy::nursery \
--deny clippy::pedantic \
--deny warnings \
--allow clippy::multiple_crate_versions \
\
--allow clippy::module_name_repetitions
CARGO_DENY = $(CARGO) deny --all-features --format $(MESSAGE_FORMAT) --workspace
CARGO_FMT = $(CARGO) fmt --all --message-format $(MESSAGE_FORMAT)
ifeq ("$(MIRI_SUB_COMMAND)", "run")
CARGO_MIRI = $(CARGO) +nightly miri run --all-features --frozen --package $(PACKAGE) $(RELEASE) --target $(TARGET)
else
CARGO_MIRI = $(CARGO) +nightly miri test --all-features --all-targets --frozen --package $(PACKAGE) $(RELEASE) --target $(TARGET)
endif
$(BIN): add-fmt fetch
$(CARGO_BUILD)
GIT_HOOKS = .git/hooks/commit-msg .git/hooks/pre-commit .git/hooks/pre-push .git/hooks/prepare-commit-msg
$(GIT_HOOKS): .git/hooks/%: .githooks/%
.githooks/%:
touch $@
.git/hooks/%:
cp $< $@
.PHONY: add-audit
add-audit: ## Add the audit
$(CARGO) install cargo-audit
.PHONY: add-clippy
add-clippy: ## Add the clippy
rustup $(NIGHTLY) component add clippy
.PHONY: add-conventional-commits-linter
add-conventional-commits-linter: ## Add the conventional commits linter
$(CARGO) install --locked conventional_commits_linter
.PHONY: add-deny
add-deny: ## Add the deny
$(CARGO) install --locked cargo-deny
.PHONY: add-os-dependency
add-os-dependency: ## Add the os dependency
ifeq ("$(DETECTED_OS)", "Darwin")
bash -c "$(curl --fail --location --show-error --silent https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" \
&& brew install \
cmake \
sqlite3
else ifeq ("$(DETECTED_OS)", "Linux")
export DEBIAN_FRONTEND="noninteractive" \
&& apt-get update \
&& apt-get install --no-install-recommends --yes \
cmake \
sqlite3 \
&& apt-get autoremove --yes \
&& apt-get clean --yes \
&& rm -fr /tmp/* /var/lib/apt/lists/* /var/tmp/*
else
echo "Please install dependencies on $(DETECTED_OS)"
endif
.PHONY: add-fmt
add-fmt: ## Add the fmt
rustup $(NIGHTLY) component add rustfmt
.PHONY: add-git-configs
add-git-configs: ## Add the git configs
git config --global branch.autosetuprebase always
git config --global color.branch true
git config --global color.diff true
git config --global color.interactive true
git config --global color.status true
git config --global color.ui true
git config --global commit.gpgsign true
git config --global core.autocrlf input
git config --global core.editor "code --wait"
git config --global diff.tool code
git config --global difftool.code.cmd "code --diff \$$LOCAL \$$REMOTE --wait"
git config --global gpg.program gpg
git config --global init.defaultbranch main
git config --global log.date relative
git config --global merge.tool code
git config --global mergetool.code.cmd "code --wait \$$MERGED"
git config --global pull.default current
git config --global pull.rebase true
git config --global push.default current
git config --global rebase.autostash true
git config --global rerere.enabled true
git config --global stash.showpatch true
git config --global tag.gpgsign true
.PHONY: add-git-hooks
add-git-hooks: clean-git-hooks $(GIT_HOOKS) ## Add the git hooks
.PHONY: add-grcov
add-grcov: ## Add the grcov
$(CARGO) install --locked grcov
.PHONY: add-llvm-tools-preview
add-llvm-tools-preview: ## Add the llvm tools preview
rustup $(NIGHTLY) component add llvm-tools-preview
.PHONY: add-measureme
add-measureme: ## Add the measureme
$(CARGO) install --git https://github.com/rust-lang/measureme --tag 10.0.0 crox flamegraph stack_collapse summarize
.PHONY: add-miri
add-miri: NIGHTLY = +nightly
add-miri: add-nightly-toolchain ## Add the miri
rustup $(NIGHTLY) component add miri
$(CARGO) $(NIGHTLY) miri setup
.PHONY: add-nightly-toolchain
add-nightly-toolchain: ## Add nightly toolchain
rustup toolchain install nightly
.PHONY: add-target
add-target: ## Add a target
rustup target add $(TARGET)
.PHONY: audit
audit: add-audit ## Audit
$(CARGO_AUDIT)
.PHONY: bench
bench: add-fmt fetch ## Bench
$(CARGO_BENCH)
.PHONY: build
build: clean-build $(BIN) ## Build
.PHONY: check
check: add-fmt fetch ## Check
$(CARGO_CHECK)
.PHONY: clean
clean: clean-coverage clean-doc clean-profile clean-release ## Clean
rm -fr target
.PHONY: clean-build
clean-build: fetch ## Clean build
$(CARGO_CLEAN)
.PHONY: clean-coverage
clean-coverage: ## Clean coverage
find . -type f -name *.prof* -exec rm -fr {} +
rm -fr $(COVERAGE_DIR)
rm -fr coverage
.PHONY: clean-doc
clean-doc: ## Clean doc
rm -fr $(DOCUMENTATION_DIR)
rm -fr documentation
.PHONY: clean-git-hooks
clean-git-hooks: ## Clean git hooks
rm -fr $(GIT_HOOKS)
.PHONY: clean-profile
clean-profile: ## Clean profile
rm -fr profile
.PHONY: clean-release
clean-release: ## Clean release
rm -fr release
.PHONY: clippy
clippy: add-clippy add-fmt fetch ## Clippy
$(CARGO_CLIPPY)
.PHONY: conventional-commits-linter
conventional-commits-linter: add-conventional-commits-linter ## Conventional commits linter
conventional_commits_linter --allow-angular-type-only --from-stdin
.PHONY: coverage
# coverage: NIGHTLY = +nightly
coverage: add-fmt add-grcov add-llvm-tools-preview add-nightly-toolchain clean-coverage fetch ## Coverage
mkdir -p $(COVERAGE_DIR)
mkdir -p coverage
RUSTC_BOOTSTRAP=1 RUSTFLAGS="-Zinstrument-coverage -Zpanic_abort_tests" $(CARGO_BUILD)
RUSTC_BOOTSTRAP=1 RUSTFLAGS="-Zinstrument-coverage -Zpanic_abort_tests" LLVM_PROFILE_FILE="$(PACKAGE)-%p-%m.profraw" $(CARGO_TEST)
ifeq ("$(GRCOV_COVERAGE_TYPE)", "cobertura")
grcov . \
--binary-path $(BIN_DIR) \
--branch \
--guess-directory-when-missing \
--ignore "/*" \
--ignore-not-existing \
--output-path $(COVERAGE_DIR)/coverage.xml \
--output-type cobertura \
--source-dir .
else ifeq ("$(GRCOV_COVERAGE_TYPE)", "lcov")
grcov . \
--binary-path $(BIN_DIR) \
--branch \
--guess-directory-when-missing \
--ignore "/*" \
--ignore-not-existing \
--output-path $(COVERAGE_DIR)/lcov.info \
--output-type lcov \
--source-dir .
else ifeq ("$(GRCOV_COVERAGE_TYPE)", "html")
grcov . \
--binary-path $(BIN_DIR) \
--branch \
--guess-directory-when-missing \
--ignore "/*" \
--ignore-not-existing \
--output-path $(COVERAGE_DIR) \
--output-type html \
--source-dir .
else
echo "Unknown coverage type: $(GRCOV_COVERAGE_TYPE)"
endif
cp -R $(COVERAGE_DIR)/* coverage
.PHONY: deny-check
deny-check: add-deny ## Deny check
$(CARGO_DENY) check $(DENY_CHECK_WHICH)
.PHONY: deny-fetch
deny-fetch: add-deny ## Deny fetch
$(CARGO_DENY) fetch
.PHONY: deny-fix
deny-fix: add-deny ## Deny fix
$(CARGO_DENY) fix
.PHONY: doc
doc: add-fmt clean-doc fetch ## Doc
$(CARGO_DOC)
mkdir -p documentation
cp -R $(DOCUMENTATION_DIR)/* documentation
.PHONY: fetch
fetch: Cargo.lock add-target ## Fetch
$(CARGO_FETCH)
.PHONY: fix
fix: fetch ## Fix
$(CARGO_FIX)
.PHONY: fmt
fmt: add-fmt ## FMT
$(CARGO_FMT)
.PHONY: fmt-check
fmt-check: add-fmt ## FMT check
$(CARGO_FMT) -- --check
.PHONY: generate-lockfile
generate-lockfile: ## Generate lockfile
$(CARGO) generate-lockfile
.PHONY: git
git: add-git-configs add-git-hooks ## Add git configs & hooks
.PHONY: help
help: ## Help
@grep --extended-regexp '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| sort \
| awk 'BEGIN { FS = ":.*?## " }; { printf "\033[36m%-33s\033[0m %s\n", $$1, $$2 }'
.PHONY: measureme
measureme: NIGHTLY = +nightly
measureme: add-measureme add-nightly-toolchain ## Measureme flamegraph
RUSTFLAGS="-Zself-profile=profile -Zself-profile-events=default,args" $(CARGO_BUILD)
.PHONY: measureme-crox
measureme-crox: measureme ## Measureme crox
crox --dir profile --minimum-duration 2
.PHONY: measureme-flamegraph
measureme-flamegraph: measureme ## Measureme flamegraph
flamegraph $(PACKAGE)-$(PID)
.PHONY: measureme-stack-collapse
measureme-stack-collapse: measureme ## Measureme stack collapse
stack_collapse $(PACKAGE)-$(PID)
.PHONY: measureme-summarize
measureme-summarize: measureme ## Measureme summarize
summarize summarize $(PACKAGE)-$(PID)
.PHONY: miri
miri: add-miri ## Miri
$(CARGO_MIRI)
.PHONY: release
release: $(BIN) clean-release ## Release
mkdir -p release
cp $(BIN) release/$(BIN_NAME)
$(STRIP) release/$(BIN_NAME)
shasum --algorithm 256 release/$(BIN_NAME) \
| cut -d " " -f 2 > release/$(BIN_NAME).sha256
.PHONY: run
run: fetch ## Run
$(CARGO_RUN)
.PHONY: test
test: add-fmt fetch ## Test
$(CARGO_TEST)