-
Notifications
You must be signed in to change notification settings - Fork 37
/
justfile
151 lines (119 loc) · 4.06 KB
/
justfile
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
# See https://just.systems/man/
##
## General recipes
##
default: rs-fetch rs-deny gen lint rs-test
lint: md-lint gen-check rs-clippy rs-docs
md-lint:
markdownlint-cli2 '**/*.md' '!**/node_modules' '!**/target'
# Generate Go & Rust bindings from protobuf.
gen: rs-gen go-gen
# Regenerate bindings and error if they don't match what is already in version
# control.
gen-check: rs-gen-check go-gen-check
# The `protoc` binary to use for both Go & Rust.
export PROTOC := env_var_or_default("PROTOC", "protoc")
# Used by Rust's `prost` to disallow compiling protoc.
export PROTOC_NO_VENDOR := "1"
##
## Rust recipes
##
export RUST_BACKTRACE := env_var_or_default("RUST_BACKTRACE", "short")
cargo-toolchain := ""
_cargo := 'just-cargo' + if cargo-toolchain != '' { ' toolchain=' + cargo-toolchain } else { '' }
features := "all"
_features := if features == "all" { "--all-features" } else { "--features=" + features }
# Fetch Rust dependencies
rs-fetch:
{{ _cargo }} fetch --locked
# Check Rust code formatting
rs-check-fmt:
{{ _cargo }} fmt -- --check
# Check Rust code compilation
rs-check *flags:
{{ _cargo }} check --all-targets {{ _features }} {{ flags }}
alias clippy := rs-clippy
# Lint Rust code
rs-clippy *flags:
{{ _cargo }} clippy --all-targets {{ _features }} {{ flags }}
# Audit Rust dependencies with `cargo-deny`
rs-deny *args:
cargo-deny {{ _features }} check {{ args}}
# Generate Rust documentation for this crate.
rs-docs:
{{ _cargo }} doc --no-deps {{ _features }}
# Generate Rust bindings from protobuf.
rs-gen:
cargo run --example=gen
# Regenerate Rust bindings and error if they don't match what is already in
# version control.
rs-gen-check: rs-gen
#!/usr/bin/env sh
if [ $(git diff-index -p HEAD -- src/gen | wc -l) -gt 0 ]; then
echo 'rust bindings are not up to date' >&2
git diff-index -p HEAD -- src/gen >&2
exit 1
fi
# Build Rust tests.
rs-test-build *flags:
{{ _cargo }} test-build {{ _features }} {{ flags }}
# Run Rust tests.
rs-test *flags:
{{ _cargo }} test {{ _features }} {{ flags }}
# Public the Rust crate to crates.io.
rs-publish *flags:
cargo publish {{ _features }} {{ flags }}
##
## Go recipes
##
# Fetch Go dependencies.
go-mod:
go mod tidy
go mod download
# Errors if `go mod tidy` changes the manifests
go-mod-check: go-mod
#!/usr/bin/env sh
if [ $(git diff-index -p HEAD -- go.{mod,sum} | wc -l) -gt 0 ]; then
echo 'go.mod can be tidied' >&2
git diff-index -p HEAD -- go.{mod,sum} >&2
exit 1
fi
# Install go tools needed to generate bindings.
go-tools:
@sed -nE 's/\s+_ "(.*)"/\1/p' tools.go | xargs -t go install
# Generate Go bindings from protobuf.
go-gen: go-tools
#!/usr/bin/env bash
set -eu
# Delete the directory to ensure module deletions are honored.
echo rm -rf go
rm -rf go
# Find non-vendored protobuf files in the `proto` dir.
for path in $(find proto -maxdepth 2 -name '*.proto'); do
# Extract the name of the module.
name="${path%.proto}"
name="${name#proto/}"
# Create a directory for the module.
echo mkdir -p go/$name
mkdir -p go/$name
# Generate basic protobuf bindings for the module.
echo {{ PROTOC }} -I proto --go_out=paths=source_relative:./go/$name $path
{{ PROTOC }} -I proto --go_out=paths=source_relative:./go/$name $path
# If the protobuf includes a service definition, generate gRPC bindings as well.
if grep -q '^service ' "$path" >/dev/null; then
echo {{ PROTOC }} -I proto --go-grpc_out=paths=source_relative:./go/$name $path
{{ PROTOC }} -I proto --go-grpc_out=paths=source_relative:./go/$name $path
fi
done
go-build:
go build ./go/...
# Regenerate Go bindings and error if they don't match what is already in
# version control.
go-gen-check: go-gen
#!/usr/bin/env sh
if [ $(git diff-index -p HEAD -- go | wc -l) -gt 0 ]; then
echo 'go bindings are not up to date' >&2
git diff-index -p HEAD -- go >&2
exit 1
fi
# vim: set ft=make :