-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathjust-cargo
More file actions
executable file
·109 lines (83 loc) · 3.44 KB
/
just-cargo
File metadata and controls
executable file
·109 lines (83 loc) · 3.44 KB
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
#!/usr/bin/env -S just --working-directory . --justfile
# The command used to reinvoke just
_just := just_executable() + " --working-directory . --justfile " + justfile()
# Helpers for running Cargo.
profile := 'debug' # or 'release'
_release := if profile == 'release' { '--release' } else { '' }
toolchain := ""
export CARGO := env_var_or_default("CARGO", "cargo" + if toolchain != "" { " +" + toolchain } else { "" })
target := ''
_target := if target == '' {
''
} else {
'--target=' + target
}
export RUSTFLAGS := env_var_or_default("RUSTFLAGS", "-D warnings") + if target == 'aarch64-unknown-linux-musl' {
' --codegen linker=aarch64-linux-gnu-gcc'
} else { '' }
_llvm-version := '19'
_clang := 'clang-' + _llvm-version
_strip := 'llvm-strip-' + _llvm-version
_ar := 'llvm-ar-' + _llvm-version
# Use LLD to statically link binaries (when building for musl).
_rustflags-self-contained := "-Clink-self-contained=yes -Clinker=rust-lld -Clink-arg=-fuse-ld=lld -Clink-arg=-Wl,--no-rosegment"
# linux/arm64 + gnu
export AR_aarch64_unknown_linux_gnu := _ar
export CC_aarch64_unknown_linux_gnu := _clang
export STRIP_aarch64_unknown_linux_gnu := _strip
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER := 'aarch64-linux-gnu-gcc'
# linux/arm64 + musl
export AR_aarch64_unknown_linux_musl := _ar
export CC_aarch64_unknown_linux_musl := _clang
export STRIP_aarch64_unknown_linux_musl := _strip
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS := _rustflags-self-contained
# linux/amd64 + gnu
export AR_x86_64_unknown_linux_gnu := _ar
export CC_x86_64_unknown_linux_gnu := _clang
export STRIP_x86_64_unknown_linux_gnu := _strip
# linux/amd64 + musl
export AR_x86_64_unknown_linux_musl := _ar
export CC_x86_64_unknown_linux_musl := _clang
export STRIP_x86_64_unknown_linux_musl := _strip
export CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_RUSTFLAGS := _rustflags-self-contained
all: fetch clippy test
fetch *args='':
{{ CARGO }} fetch {{ args }}
clean:
{{ CARGO }} clean
build *args: _target-installed
{{ CARGO }} build {{ _release }} {{ _target }} {{ args }} {{ _fmt }}
fmt *args='':
{{ CARGO }} fmt {{ args }}
check *args='': _target-installed
{{ CARGO }} check {{ _release }} {{ _target }} {{ args }} {{ _fmt }}
clippy *args='': _target-installed
{{ CARGO }} clippy {{ _release }} {{ _target }} {{ args }} {{ _fmt }}
doc *args='':
{{ CARGO }} doc {{ _release }} {{ _target }} {{ args }} {{ _fmt }}
test-build *args='': _target-installed
{{ CARGO }} test --no-run {{ _release }} {{ _target }} {{ args }} {{ _fmt }}
test *args='': _target-installed
{{ CARGO }} nextest run {{ _release }} {{ _target }} {{ args }}
# Print the version of the named crate. E.g. `version = "1.2.3"` as "v1.2.3"
crate-version crate:
@{{ CARGO }} metadata --format-version=1 \
| jq -r '.packages[] | select(.name == "{{ crate }}") | "v" + .version' \
| head -n1
_target-installed:
#!/usr/bin/env bash
set -euo pipefail
if ! rustup target list --installed |grep -qF '{{ target }}' 2>/dev/null ; then
{{ _just }} target='{{ target }}' _target-add
fi
_target-add:
rustup target add '{{ target }}'
# If we're running in Github Actions and cargo-action-fmt is installed, then add
# a command suffix that formats errors.
_fmt := ```
if [ "${GITHUB_ACTIONS:-}" = "true" ] &&
command -v cargo-action-fmt >/dev/null 2>&1
then
echo "--message-format=json | cargo-action-fmt"
fi
```