This repository has been archived by the owner on Mar 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
89 lines (63 loc) · 2.5 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
RUSTUP = rustup
# The CI should pass a RUST_TOOLCHAIN env var, if not we default to our MSRV 1.40.0
RUST_TOOLCHAIN ?= 1.40.0
TOOLCHAIN = $(RUST_TOOLCHAIN)
CARGO = $(RUSTUP) run --install $(TOOLCHAIN) cargo --color always
NIGHTLY_TOOLCHAIN = nightly-2020-04-10
CARGO_NIGHTLY = $(RUSTUP) run --install $(NIGHTLY_TOOLCHAIN) cargo --color always
GIT_HOOKS_PATH = ".githooks"
GIT_HOOKS = $(wildcard $(GIT_HOOKS_PATH)/*)
INSTALLED_TOOLCHAINS = $(shell $(RUSTUP) toolchain list)
INSTALLED_COMPONENTS = $(shell $(RUSTUP) component list --installed --toolchain $(TOOLCHAIN))
INSTALLED_NIGHTLY_COMPONENTS = $(shell $(RUSTUP) component list --installed --toolchain $(NIGHTLY_TOOLCHAIN))
AVAILABLE_CARGO_COMMANDS = $(shell $(CARGO) --list)
# All our targets go into .PHONY because none of them actually create files
.PHONY: init_git_hooks default install_rust install_rust_nightly install_clippy install_rustfmt install_tomlfmt install clean all ci build clippy test doc check_format format check_rust_format check_toml_format check_ts_format
default: init_git_hooks format build clippy
init_git_hooks:
git config core.hooksPath $(GIT_HOOKS_PATH)
## Dev environment
install_rust:
ifeq (,$(findstring $(TOOLCHAIN),$(INSTALLED_TOOLCHAINS)))
$(RUSTUP) install $(TOOLCHAIN)
endif
install_rust_nightly:
ifeq (,$(findstring $(NIGHTLY_TOOLCHAIN),$(INSTALLED_TOOLCHAINS)))
$(RUSTUP) install $(NIGHTLY_TOOLCHAIN)
endif
install_clippy: install_rust
ifeq (,$(findstring clippy,$(INSTALLED_COMPONENTS)))
$(RUSTUP) component add clippy --toolchain $(TOOLCHAIN)
endif
install_rustfmt: install_rust_nightly
ifeq (,$(findstring rustfmt,$(INSTALLED_NIGHTLY_COMPONENTS)))
$(RUSTUP) component add rustfmt --toolchain $(NIGHTLY_TOOLCHAIN)
endif
install_tomlfmt: install_rust
ifeq (,$(findstring tomlfmt,$(AVAILABLE_CARGO_COMMANDS)))
$(CARGO) install cargo-tomlfmt
endif
## Development tasks
clean:
$(CARGO) clean
all: init_git_hooks format clippy test build doc
ci: check_format clippy test build doc
build:
$(CARGO) build --all --all-targets $(BUILD_ARGS)
clippy: install_clippy
$(CARGO) clippy --all-targets -- -D warnings
test:
$(CARGO) test --all
doc:
$(CARGO) doc
check_format: check_rust_format check_toml_format
format: install_rustfmt install_tomlfmt
$(CARGO_NIGHTLY) fmt
$(CARGO) tomlfmt -p Cargo.toml
force_format: install_rustfmt install_tomlfmt
$(CARGO_NIGHTLY) fmt
$(CARGO) tomlfmt -p Cargo.toml
check_rust_format: install_rustfmt
$(CARGO_NIGHTLY) fmt -- --check
check_toml_format: install_tomlfmt
$(CARGO) tomlfmt -d -p Cargo.toml