-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
86 lines (71 loc) · 1.98 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
DATABASE_URL = "sqlite:farcaster.db"
MIGRATIONS_DIR = "./lib/storage/migrations"
define install_package
if ! command -v $(1) >/dev/null 2>&1; then \
echo "installing $(1)..."; \
$(2); \
fi
endef
define install_rust
if ! command -v rustc >/dev/null 2>&1; then \
echo "installing rust..."; \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y; \
fi
endef
define install_protobuf
if ! command -v protoc >/dev/null 2>&1; then \
echo "installing protobufs compiler..."; \
$(1); \
fi
endef
define install_prerequisites
case $$OSTYPE in \
darwin*) \
echo "detected macos"; \
$(call install_package,brew,/bin/bash -c "$$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"); \
$(call install_rust); \
$(call install_protobuf,brew install protobuf); \
;; \
linux*) \
echo "detected linux"; \
$(call install_rust); \
$(call install_protobuf,sudo apt update && sudo apt install -y protobuf-compiler); \
;; \
*) \
echo "unsupported operating system"; \
exit 1; \
;; \
esac
endef
db-create:
DATABASE_URL=$(DATABASE_URL) sqlx db create
db-migrate:
DATABASE_URL=$(DATABASE_URL) sqlx migrate run --source $(MIGRATIONS_DIR)
db-query-prepare:
DATABASE_URL=$(DATABASE_URL) cargo sqlx prepare --workspace
install:
@$(call install_prerequisites)
@if ! command -v sqlx >/dev/null 2>&1; then \
echo "installing sqlx cli..."; \
. $$HOME/.cargo/env && cargo install sqlx-cli; \
fi
@echo "all prerequisites installed successfully!"
check:
@echo "Check: Running cargo check"
cargo check
test:
@echo "Test: Running cargo test"
cargo test
fmt:
@echo "Fmt: Running cargo fmt"
cargo +nightly fmt --all -- --check
clippy:
@echo "Clippy: Running cargo clippy"
cargo clippy -- -D warnings
verify:
@echo "Running all checks"
@make check
@make test
@make fmt
@make clippy
.PHONY: db-create db-migrate db-query-prepare install clippy fmt test check verify