-
Notifications
You must be signed in to change notification settings - Fork 35
/
justfile
167 lines (133 loc) · 5.23 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
export RUST_BACKTRACE := env_var_or_default("RUST_BACKTRACE", "short")
export DOCKER_PROGRESS := env_var_or_default('DOCKER_PROGRESS', 'auto')
export RESTATE_TEST_PORTS_POOL := "/tmp/restate_tests_ports_pool"
dev_tools_image := "ghcr.io/restatedev/dev-tools:latest"
# Docker image name & tag.
docker_repo := "localhost/restatedev/restate"
docker_tag := if path_exists(justfile_directory() / ".git") == "true" {
`git rev-parse --abbrev-ref HEAD | sed 's|/|.|g'` + "." + `git rev-parse --short HEAD`
} else {
"unknown"
}
docker_image := docker_repo + ":" + docker_tag
features := ""
libc := "gnu"
arch := "" # use the default architecture
os := "" # use the default os
_features := if features == "all" {
"--all-features"
} else if features != "" {
"--features=" + features
} else { "" }
_arch := if arch == "" {
arch()
} else if arch == "amd64" {
"x86_64"
} else if arch == "x86_64" {
"x86_64"
} else if arch == "arm64" {
"aarch64"
} else if arch == "aarch64" {
"aarch64"
} else {
error("unsupported arch=" + arch)
}
_docker_arch := if _arch == "x86_64" {
"amd64"
} else if _arch == "aarch64" {
"arm64"
} else {
_arch
}
_os := if os == "" {
os()
} else {
os
}
_os_target := if _os == "macos" {
"apple-darwin"
} else if _os == "linux" {
"unknown-linux"
} else {
error("unsupported os=" + _os)
}
_default_target := `rustc -vV | sed -n 's|host: ||p'`
target := _arch + "-" + _os_target + if _os == "linux" { "-" + libc } else { "" }
_resolved_target := if target != _default_target { target } else { "" }
_target-option := if _resolved_target != "" { "--target " + _resolved_target } else { "" }
_flamegraph_options := if os() == "macos" { "--root" } else { "" }
clean:
cargo clean
fmt:
cargo fmt --all
check-fmt:
cargo fmt --all -- --check
clippy: (_target-installed target)
cargo clippy {{ _target-option }} --all-targets --workspace -- -D warnings
# Runs all lints (fmt, clippy, deny)
lint: check-fmt clippy check-deny
# Extract dependencies
chef-prepare:
cargo chef prepare --recipe-path recipe.json
# Compile dependencies
chef-cook *flags: (_target-installed target)
cargo chef cook --recipe-path recipe.json {{ _target-option }} {{ _features }} {{ flags }}
build *flags: (_target-installed target)
cargo build {{ _target-option }} {{ _features }} {{ flags }}
build-tools *flags: (_target-installed target)
cd {{justfile_directory()}}/tools/xtask; cargo build {{ _target-option }} {{ _features }} {{ flags }}
cd {{justfile_directory()}}/tools/service-protocol-wireshark-dissector; cargo build {{ _target-option }} {{ _features }} {{ flags }}
# Might be able to use cross-rs at some point but for now it could not handle a container image that
# has a rust toolchain installed. Alternatively, we can create a separate cross-rs builder image.
cross-build *flags:
#!/usr/bin/env bash
if [[ {{ target }} =~ "linux" ]]; then
docker run --rm -it -v `pwd`:/restate:Z -w /restate {{ dev_tools_image }} just _resolved_target={{ target }} features={{ features }} build {{ flags }}
elif [[ {{ target }} =~ "darwin" ]]; then
if [[ {{ os() }} != "macos" ]]; then
echo "Cannot built macos target on non-macos host";
else
just _resolved_target={{ target }} features={{ features }} build {{ flags }};
fi
else
echo "Unsupported target: {{ target }}";
fi
print-target:
@echo {{ _resolved_target }}
run *flags: (_target-installed target)
cargo run {{ _target-option }} {{ flags }}
test: (_target-installed target)
# remove possible old test ports
rm -rf {{RESTATE_TEST_PORTS_POOL}}
cargo nextest run {{ _target-option }} --all-features --target-dir target/tests
test-package package *flags:
cargo nextest run --all-features --no-capture --package {{ package }} --target-dir target/tests {{ flags }}
doctest:
cargo test --doc
# Runs lints and tests
verify: lint test doctest
docker:
# podman builds do not work without --platform set, even though it claims to default to host arch
docker buildx build . --platform linux/{{ _docker_arch }} --file docker/Dockerfile --tag={{ docker_image }} --progress='{{ DOCKER_PROGRESS }}' --build-arg RESTATE_FEATURES={{ features }} --load
notice-file:
cargo license -d -a --avoid-build-deps --avoid-dev-deps {{ _features }} | (echo "Restate Runtime\nCopyright (c) 2024 Restate Software, Inc., Restate GmbH <[email protected]>\n" && cat) > NOTICE
generate-config-schema:
cargo xtask generate-config-schema > restate_config_schema.json
check-deny:
#!/usr/bin/env bash
# cargo-deny-action runs as a standalone workflow in CI
if [[ -z "$CI" ]]; then
cargo deny --all-features check
fi
flamegraph *flags:
cargo flamegraph {{ _flamegraph_options }} {{ flags }}
udeps *flags:
RUSTC_BOOTSTRAP=1 cargo udeps --all-features --all-targets {{ flags }}
_target-installed target:
#!/usr/bin/env bash
set -euo pipefail
if ! rustup target list --installed |grep -qF '{{ target }}' 2>/dev/null ; then
rustup target add '{{ target }}'
fi
check-license-headers:
tools/scripts/check-license-headers