...
1# See https://just.systems/man/
2
3##
4## General recipes
5##
6
7default: rs-fetch rs-deny gen lint rs-test
8
9lint: md-lint gen-check rs-clippy rs-docs
10
11md-lint:
12 markdownlint-cli2 '**/*.md' '!**/node_modules' '!**/target'
13
14# Generate Go & Rust bindings from protobuf.
15gen: rs-gen go-gen
16
17# Regenerate bindings and error if they don't match what is already in version
18# control.
19gen-check: rs-gen-check go-gen-check
20
21# The `protoc` binary to use for both Go & Rust.
22export PROTOC := env_var_or_default("PROTOC", "protoc")
23
24# Used by Rust's `prost` to disallow compiling protoc.
25export PROTOC_NO_VENDOR := "1"
26
27##
28## Rust recipes
29##
30
31export RUST_BACKTRACE := env_var_or_default("RUST_BACKTRACE", "short")
32
33cargo-toolchain := ""
34_cargo := 'just-cargo' + if cargo-toolchain != '' { ' toolchain=' + cargo-toolchain } else { '' }
35
36features := "all"
37_features := if features == "all" { "--all-features" } else { "--features=" + features }
38
39# Fetch Rust dependencies
40rs-fetch:
41 {{ _cargo }} fetch --locked
42
43# Check Rust code formatting
44rs-check-fmt:
45 {{ _cargo }} fmt -- --check
46
47# Check Rust code compilation
48rs-check *flags:
49 {{ _cargo }} check --all-targets {{ _features }} {{ flags }}
50
51alias clippy := rs-clippy
52
53# Lint Rust code
54rs-clippy *flags:
55 {{ _cargo }} clippy --all-targets {{ _features }} {{ flags }}
56
57# Audit Rust dependencies with `cargo-deny`
58rs-deny *args:
59 cargo-deny {{ _features }} check {{ args}}
60
61# Generate Rust documentation for this crate.
62rs-docs:
63 {{ _cargo }} doc --no-deps {{ _features }}
64
65# Generate Rust bindings from protobuf.
66rs-gen:
67 cargo run --example=gen
68
69# Regenerate Rust bindings and error if they don't match what is already in
70# version control.
71rs-gen-check: rs-gen
72 #!/usr/bin/env sh
73 if [ $(git diff-index -p HEAD -- src/gen | wc -l) -gt 0 ]; then
74 echo 'rust bindings are not up to date' >&2
75 git diff-index -p HEAD -- src/gen >&2
76 exit 1
77 fi
78
79# Build Rust tests.
80rs-test-build *flags:
81 {{ _cargo }} test-build {{ _features }} {{ flags }}
82
83# Run Rust tests.
84rs-test *flags:
85 {{ _cargo }} test {{ _features }} {{ flags }}
86
87# Public the Rust crate to crates.io.
88rs-publish *flags:
89 cargo publish {{ _features }} {{ flags }}
90
91##
92## Go recipes
93##
94
95# Fetch Go dependencies.
96go-mod:
97 go mod tidy
98 go mod download
99
100# Errors if `go mod tidy` changes the manifests
101go-mod-check: go-mod
102 #!/usr/bin/env sh
103 if [ $(git diff-index -p HEAD -- go.{mod,sum} | wc -l) -gt 0 ]; then
104 echo 'go.mod can be tidied' >&2
105 git diff-index -p HEAD -- go.{mod,sum} >&2
106 exit 1
107 fi
108
109# Install go tools needed to generate bindings.
110go-tools:
111 @sed -nE 's/\s+_ "(.*)"/\1/p' tools.go | xargs -t go install
112
113# Generate Go bindings from protobuf.
114go-gen: go-tools
115 #!/usr/bin/env bash
116 set -eu
117 # Delete the directory to ensure module deletions are honored.
118 echo rm -rf go
119 rm -rf go
120 # Find non-vendored protobuf files in the `proto` dir.
121 for path in $(find proto -maxdepth 2 -name '*.proto'); do
122 # Extract the name of the module.
123 name="${path%.proto}"
124 name="${name#proto/}"
125 # Create a directory for the module.
126 echo mkdir -p go/$name
127 mkdir -p go/$name
128 # Generate basic protobuf bindings for the module.
129 echo {{ PROTOC }} -I proto --go_out=paths=source_relative:./go/$name $path
130 {{ PROTOC }} -I proto --go_out=paths=source_relative:./go/$name $path
131 # If the protobuf includes a service definition, generate gRPC bindings as well.
132 if grep -q '^service ' "$path" >/dev/null; then
133 echo {{ PROTOC }} -I proto --go-grpc_out=paths=source_relative:./go/$name $path
134 {{ PROTOC }} -I proto --go-grpc_out=paths=source_relative:./go/$name $path
135 fi
136 done
137
138go-build:
139 go build ./go/...
140
141# Regenerate Go bindings and error if they don't match what is already in
142# version control.
143go-gen-check: go-gen
144 #!/usr/bin/env sh
145 if [ $(git diff-index -p HEAD -- go | wc -l) -gt 0 ]; then
146 echo 'go bindings are not up to date' >&2
147 git diff-index -p HEAD -- go >&2
148 exit 1
149 fi
150
151# vim: set ft=make :
View as plain text