Repository navigation
Expand file tree
/
Copy pathjustfile
More file actions
executable file
·325 lines (282 loc) · 14.6 KB
/
Copy pathjustfile
File metadata and controls
executable file
·325 lines (282 loc) · 14.6 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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#!/usr/bin/env just --justfile
main_crate := 'fastpfor'
# How to call the current just executable. Note that just_executable() may have `\` in Windows paths, so we need to quote it.
just := quote(just_executable())
# cargo-binstall needs a workaround due to caching when used in CI
binstall_args := if env('CI', '') != '' {'--no-confirm --no-track --disable-telemetry'} else {''}
# location of the coverage output, used by CI
coverage_lcov := 'target/llvm-cov/lcov.info'
# location of the jscpd copy/paste detection reports, used by CI
cpd_output := 'target/jscpd'
# if running in CI, treat warnings as errors by setting CARGO_BUILD_WARNINGS to 'deny' unless it is already set
# Use `CI=true just ci-test` to run the same tests as in GitHub CI.
# Use `just env-info` to see the current value of CARGO_BUILD_WARNINGS
ci_mode := if env('CI', '') != '' {'1'} else {''}
export CARGO_BUILD_WARNINGS := env('CARGO_BUILD_WARNINGS', if ci_mode == '1' {'deny'} else {'warn'})
export RUST_BACKTRACE := env('RUST_BACKTRACE', if ci_mode == '1' {'1'} else {'0'})
mod bench 'benches/justfile'
mod fuzz 'fuzz/justfile'
@_default:
{{just}} --list
# Run integration tests and save its output as the new expected output
bless *args: (cargo-install 'cargo-insta')
cargo insta test --accept --unreferenced=delete --features _all_compatible {{args}}
# Build the project
build:
cargo build --workspace --all-targets --features _all_compatible
# Quick compile without building a binary
check:
cargo check --workspace --all-targets --features _all_compatible,__testing
cargo check --workspace --all-targets --no-default-features --features cpp
cargo check --workspace --all-targets --no-default-features --features rust
cargo check --workspace --all-targets --manifest-path fuzz/Cargo.toml
# Run `check` for every SIMD platform: x86_64 without and with AVX2, aarch64 with and without NEON.
# Non-native architectures only check the library: the `cpp` feature and dev-dependencies need a C cross-compiler.
# Install their std with `rustup target add <triple>`, e.g. `aarch64-unknown-linux-gnu`.
check-platforms:
{{just}} _check-platform x86_64 no-avx2 '-C target-feature=-avx2'
{{just}} _check-platform x86_64 avx2 '-C target-feature=+avx2'
{{just}} _check-platform aarch64 neon '-C target-feature=+neon'
# rustc warns that disabling NEON changes the aarch64 float ABI; that is expected here.
{{just}} _check-platform aarch64 no-neon '-C target-feature=-neon'
# Check one platform. An explicit target keeps RUSTFLAGS away from build scripts, and a separate target dir keeps caches apart.
_check-platform arch name rustflags:
#!/usr/bin/env bash
set -euo pipefail
triple='{{arch}}-{{if os() == "macos" { "apple-darwin" } else { "unknown-linux-gnu" } }}'
export RUSTFLAGS={{quote(rustflags)}}
export CARGO_BUILD_TARGET="$triple"
export CARGO_TARGET_DIR='target/check-{{name}}'
echo "::: Checking $triple with RUSTFLAGS='$RUSTFLAGS'"
if [ '{{arch}}' = '{{arch()}}' ]; then
{{just}} check
else
cargo check --workspace --lib --no-default-features --features rust,simd,__testing
fi
# Generate LCOV coverage report for CI to upload to codecov.io
ci-coverage: env-info && \
(_coverage '--lcov' '--output-path' quote(coverage_lcov))
rm -rf {{quote(parent_directory(coverage_lcov))}}
mkdir -p {{quote(parent_directory(coverage_lcov))}}
# Find copy/pasted code, marking clones absent from base_ref as new, and write a Markdown summary for the PR comment
ci-cpd base_ref='origin/main': (assert-cmd 'jq') (cpd '--reporters' 'console,json' '--output' cpd_output '--baseline-from-ref' base_ref)
jq -r --arg base {{quote(base_ref)}} -f .github/jscpd-summary.jq {{quote(cpd_output / 'jscpd-report.json')}} > {{quote(cpd_output / 'summary.md')}}
cat {{quote(cpd_output / 'summary.md')}} >> "${GITHUB_STEP_SUMMARY:-/dev/stdout}"
# Counts cycles too if `perf` can read the CPU counters. With `base_ref`, also counts that commit and shows the changes.
# Count instructions of all FastPFor implementations into a Markdown report, as expected by CI
ci-bench output='target/bench/summary.md' base_ref='': (assert-cmd 'valgrind')
#!/usr/bin/env bash
set -euo pipefail
out_dir="$(realpath -m "$(dirname {{quote(output)}})")"
mkdir -p "$out_dir"
rm -f "$out_dir"/base-*.tsv
perf=0
if {{just}} bench perf-check 2> "$out_dir/perf.log"; then perf=1; else cat "$out_dir/perf.log" >&2; fi
base_note=""
if [ -n {{quote(base_ref)}} ]; then
# Count the base commit with this commit's benchmark, so that both use the same workload and
# measurement. Its worktree is outside this one, so cargo does not see two nested packages.
base_src="$(mktemp -d)/base"
trap 'git worktree remove --force "$base_src" 2>/dev/null || true' EXIT
git worktree add --quiet --detach "$base_src" {{quote(base_ref)}}
git -C "$base_src" submodule update --quiet --init --recursive --depth 1
cp benches/instructions.rs "$base_src/benches/instructions.rs"
if ! grep -q '^name = "instructions"' "$base_src/Cargo.toml"; then
printf '\n[[bench]]\nname = "instructions"\nrequired-features = ["rust"]\nharness = false\n' >> "$base_src/Cargo.toml"
fi
features="rust,cpp_portable"
if grep -q '^simd = ' "$base_src/Cargo.toml"; then features="$features,simd"; fi
base_bench() {
(cd "$base_src" && cargo bench --bench instructions --features "$features" -- "$@") > /dev/null 2>> "$out_dir/base.log"
}
: > "$out_dir/base.log"
if base_bench --save "$out_dir/base-callgrind.tsv"; then
if [ "$perf" = 1 ]; then
FASTPFOR_BENCH_CPU=2 base_bench --perf --save "$out_dir/base-perf.tsv" || rm -f "$out_dir/base-perf.tsv"
fi
base_note="Compared with the base commit $(git rev-parse --short {{quote(base_ref)}}), counted with this commit's benchmark."
else
base_note="The base commit $(git rev-parse --short {{quote(base_ref)}}) could not be counted with this commit's benchmark (e.g. the public API changed); see the job log."
echo "::warning::Could not benchmark the base commit:" >&2
tail -n 30 "$out_dir/base.log" >&2
fi
fi
baseline() { if [ -f "$out_dir/base-$1.tsv" ]; then echo "--baseline $out_dir/base-$1.tsv"; fi; }
{{just}} bench instructions portable $(baseline callgrind) > "$out_dir/callgrind.md"
if [ "$perf" = 1 ] && {{just}} bench perf portable 2 $(baseline perf) > "$out_dir/perf.md" 2>> "$out_dir/perf.log"; then
perf_section="$(cat "$out_dir/perf.md")"
else
perf_section="Not available on this machine: $(grep -m1 '^error' "$out_dir/perf.log" || tail -n1 "$out_dir/perf.log")"
fi
{
echo "## FastPFor instruction counts"
echo
echo "Commit $(git rev-parse --short HEAD), $(lscpu | sed -n 's/^Model name: *//p'), C++ built in portable mode."
echo "Counted with valgrind's callgrind, so the counts are exact and repeat on any CPU with the same features."
if [ -n "$base_note" ]; then echo "$base_note"; fi
cat "$out_dir/callgrind.md"
echo
echo "<details><summary>Hardware counters (<code>perf stat</code>): instructions and cycles</summary>"
echo
echo "$perf_section"
echo
echo "</details>"
} > {{quote(output)}}
cat {{quote(output)}} >> "${GITHUB_STEP_SUMMARY:-/dev/stdout}"
# Run all tests as expected by CI
ci-test: env-info test-fmt check build clippy test test-doc fuzz::ci-test && assert-git-is-clean
# Compile default features with minimal dependencies on the configured MSRV
ci-test-msrv:
{{just}} ci_mode=0 env-info _check-msrv-default
{{just}} test
{{just}} assert-git-is-clean
# Set toolchain and run ci-test-msrv
ci-test-msrv-with-toolchain:
RUSTUP_TOOLCHAIN="$({{just}} get-msrv)" {{just}} ci-test-msrv
# Clean all build artifacts
clean:
cargo clean
rm -f Cargo.lock
cd fuzz && cargo clean && rm -f Cargo.lock
# Run cargo clippy to lint the code
clippy *args:
cargo clippy --workspace --all-targets --features _all_compatible,__testing {{args}}
cargo clippy --workspace --all-targets --manifest-path fuzz/Cargo.toml {{args}}
# Generate and open the HTML coverage report
coverage: (_coverage '--open')
# Clean, collect, and aggregate coverage using the requested report arguments
_coverage *report_args: (cargo-install 'cargo-llvm-cov')
cargo llvm-cov clean --workspace
cargo llvm-cov --no-report --workspace --all-targets --features _all_compatible,__testing
cargo llvm-cov report --include-build-script {{report_args}}
# Find copy/pasted code with jscpd, configured in .jscpd.json. See `just cpd --help` for all options
cpd *args: (cargo-install 'jscpd' 'jscpd --bin jscpd' '--bin-dir={bin}{binary-ext}')
jscpd {{args}}
# Build and open code documentation
docs *args='--features _all_compatible --open':
DOCS_RS=1 cargo doc --no-deps {{args}} --workspace
# Print environment info
env-info:
@echo "Running for '{{main_crate}}' crate {{if ci_mode == '1' {'in CI mode'} else {'in dev mode'} }} on {{os()}} / {{arch()}}"
@echo "PWD {{justfile_directory()}}"
{{just}} --version
rustc --version
cargo --version
rustup --version
@echo "CARGO_BUILD_WARNINGS='$CARGO_BUILD_WARNINGS'"
@echo "RUST_BACKTRACE='$RUST_BACKTRACE'"
# Reformat all code `cargo fmt`. If nightly is available, use it for better results
fmt:
#!/usr/bin/env bash
set -euo pipefail
for dir in "./" "fuzz"; do
pushd "$dir"
if (rustup toolchain list | grep nightly && rustup component list --toolchain nightly | grep rustfmt) &> /dev/null; then
echo "Reformatting Rust code using nightly Rust fmt to sort imports in $dir"
cargo +nightly fmt --all -- --config imports_granularity=Module,group_imports=StdExternalCrate
else
echo "Reformatting Rust with the stable cargo fmt in $dir. Install nightly with \`rustup install nightly\` for better results"
cargo fmt --all
fi
popd
done
# Reformat all Cargo.toml files using cargo-sort
fmt-toml *args: (cargo-install 'cargo-sort')
cargo sort --workspace --grouped {{args}}
# Get a package field from the metadata
get-crate-field field package=main_crate: (assert-cmd 'jq')
@cargo metadata --no-deps --format-version 1 | jq -e -r '.packages | map(select(.name == "{{package}}")) | first | .{{field}} // error("Field \"{{field}}\" is missing in Cargo.toml for package {{package}}")'
# Get the minimum supported Rust version (MSRV) for the crate
get-msrv package=main_crate: (get-crate-field 'rust_version' package)
# Find the minimum supported Rust version (MSRV), update Cargo.toml, and test minimal dependencies
msrv: (cargo-install 'cargo-msrv')
cargo msrv find --write-msrv --features _all_compatible --ignore-lockfile -- {{just}} _check-msrv-default
# Compile the crate's default features using a dynamically generated minimal Cargo.lock
_check-msrv-default: (cargo-install 'cargo-minimal-versions') (cargo-install 'cargo-hack')
#!/usr/bin/env bash
set -euo pipefail
# cargo-msrv probes with rustup, but nested cargo subcommands may otherwise
# fall back to the default Cargo and emit flags unsupported by the candidate rustc.
toolchain="$(rustc --version | cut -d' ' -f2)"
export RUSTUP_TOOLCHAIN="$toolchain"
export CARGO="$(rustup which --toolchain "$toolchain" cargo)"
cargo minimal-versions check --direct --package {{main_crate}}
# Run cargo-release
release *args='': (cargo-install 'release-plz')
release-plz {{args}}
# Check semver compatibility with prior published version. Install it with `cargo install cargo-semver-checks`
semver *args: (cargo-install 'cargo-semver-checks')
cargo semver-checks --features _all_compatible {{args}}
# Run all tests
test:
cargo test --workspace --all-targets --features _all_compatible,__testing
cargo test --doc --workspace --features _all_compatible,__testing
# Test with a specific SIMD mode (portable, native)
test-simd mode='portable':
cargo test --workspace --all-targets --features cpp_{{mode}}
# Test all SIMD modes
test-all-simd-modes:
cargo clean -p fastpfor
{{just}} test-simd portable
cargo clean -p fastpfor
{{just}} test-simd native
# Test documentation generation
test-doc: (docs '') (docs '--features _all_compatible')
# Test code formatting
test-fmt: && (fmt-toml '--check' '--check-format')
cargo fmt --all -- --check
# Use the experimental workspace publishing with --dry-run. Requires nightly Rust.
test-publish:
cargo +nightly -Z package-workspace publish --dry-run
# Find unused dependencies. Uses `cargo-udeps`
udeps: (cargo-install 'cargo-udeps')
cargo +nightly udeps --workspace --all-targets --features _all_compatible
# Update all dependencies, including breaking changes. Requires nightly toolchain (install with `rustup install nightly`)
update:
cargo +nightly -Z unstable-options update --breaking
cargo update
# Ensure that a certain command is available
[private]
assert-cmd command:
@if ! type {{command}} > /dev/null; then \
echo "Command '{{command}}' could not be found. Please make sure it has been installed on your computer." ;\
exit 1 ;\
fi
# Make sure the git repo has no uncommitted changes. Fails if CI envvar is set.
[private]
assert-git-is-clean:
#!/usr/bin/env bash
set -euo pipefail
if [ -n "$(git status --porcelain --untracked-files=all)" ]; then
>&2 echo "::error::git repo is not clean. Make sure compilation and tests artifacts are in the .gitignore, and no repo files are modified."
if [[ "{{ci_mode}}" == "1" ]]; then
>&2 echo "::group::git status"
git status
>&2 echo "::endgroup::"
>&2 echo "::group::git diff (tracked changes)"
git add . --intent-to-add
git --no-pager diff
>&2 echo "::endgroup::"
exit 1
else
>&2 echo "git repo is not clean, but not failing because CI mode is not enabled."
fi
fi
# Check if a certain Cargo command is installed, and install it if needed
[private]
cargo-install $COMMAND $INSTALL_CMD='' *args='':
#!/usr/bin/env bash
set -euo pipefail
unset CARGO_BUILD_WARNINGS
if ! command -v $COMMAND > /dev/null; then
echo "$COMMAND could not be found. Installing..."
if ! command -v cargo-binstall > /dev/null; then
set -x
cargo install ${INSTALL_CMD:-$COMMAND} --locked {{args}}
{ set +x; } 2>/dev/null
else
set -x
cargo binstall ${INSTALL_CMD:-$COMMAND} {{binstall_args}} --locked
{ set +x; } 2>/dev/null
fi
fi