11#!/ usr/ bin/ env just --justfile
22
3+ main_crate := ' fastpfor'
4+
5+ # if running in CI, treat warnings as errors by setting RUSTFLAGS and RUSTDOCFLAGS to '-D warnings' unless they are already set
6+ # Use `CI=true just ci-test` to run the same tests as in GitHub CI.
7+ # Use `just env-info` to see the current values of RUSTFLAGS and RUSTDOCFLAGS
8+ export RUSTFLAGS := env (' RUSTFLAGS' , if env (' CI' , ' ' ) == ' true' {' -D warnings' } else {' ' })
9+ export RUSTDOCFLAGS := env (' RUSTDOCFLAGS' , if env (' CI' , ' ' ) == ' true' {' -D warnings' } else {' ' })
10+ export RUST_BACKTRACE := env (' RUST_BACKTRACE' , if env (' CI' , ' ' ) == ' true' {' 1' } else {' ' })
11+
312@_ default :
413 just --list
514
6- # Run tests, and accept their results. Requires insta to be installed.
7- bless : (cargo-install " cargo-insta" )
8- TRYBUILD=overwrite cargo insta test --accept --all-features
15+ # Run integration tests and save its output as the new expected output
16+ bless * args : (cargo-install ' cargo-insta' )
17+ TRYBUILD=overwrite cargo insta test --accept --unreferenced=delete -- all-features
918
10- # Default build
11- build * ARGS :
12- cargo build --all-targets --workspace -- all-features {{ ARGS }}
19+ # Build the project
20+ build :
21+ cargo build --workspace -- all-targets --all-features
1322
1423# Quick compile without building a binary
1524check :
1625 cargo check --workspace --all-targets --all-features
1726
1827# Verify that the current version of the crate is not the same as the one published on crates.io
19- check-if-published : (assert " jq" )
28+ check-if-published : (assert ' jq' )
2029 #!/usr/bin/env bash
2130 set -euo pipefail
22- LOCAL_VERSION=" $(grep '^version =' Cargo.toml | sed -E 's/ version = " ([^ " ]*)" .* / \ 1 / ' )"
23- echo "Detected crate version: $LOCAL_VERSION"
24- CRATE_NAME="$(grep ' ^name = ' Cargo.toml | head -1 | sed -E ' s / name = " (.*)" / \ 1 / ' )"
25- echo "Detected crate name: $CRATE_NAME"
31+ LOCAL_VERSION=" $({{ just_executable () }} get-crate-field version)"
32+ echo " Detected crate version: ' $LOCAL_VERSION' "
33+ CRATE_NAME=" $({{ just_executable () }} get-crate-field name)"
34+ echo " Detected crate name: ' $CRATE_NAME' "
2635 PUBLISHED_VERSION=" $(cargo search ${CRATE_NAME} | grep " ^${CRATE_NAME} =" | sed -E 's/.* = " (.*)" .*/\1 /')"
27- echo "Published crate version: $PUBLISHED_VERSION"
36+ echo " Published crate version: ' $PUBLISHED_VERSION' "
2837 if [ " $LOCAL_VERSION" = " $PUBLISHED_VERSION" ]; then
2938 echo " ERROR: The current crate version has already been published."
3039 exit 1
@@ -39,64 +48,81 @@ ci-coverage: && \
3948 mkdir -p target/ llvm-cov
4049
4150# Run all tests as expected by CI
42- ci-test: rust-info test-fmt
43- RUSTFLAGS=' -D warnings' {{ just_executable ()}} build
44- {{ just_executable ()}} clippy -- -D warnings
45- RUSTFLAGS=' -D warnings' {{ just_executable ()}} test
46- RUSTDOCFLAGS=' -D warnings' {{ just_executable ()}} test-doc
51+ ci-test : env-info test-fmt build clippy test test-doc
52+ #!/usr/bin/env bash
53+ set -euo pipefail
54+ if [ -n " $(git status --untracked-files --porcelain)" ]; then
55+ >&2 echo ' ERROR: git repo is no longer clean. Make sure compilation and tests artifacts are in the .gitignore, and no repo files are modified.'
56+ >&2 echo ' ######### git status ##########'
57+ git status
58+ exit 1
59+ fi
4760
4861# Run minimal subset of tests to ensure compatibility with MSRV
49- ci-test-msrv: rust -info test
62+ ci-test-msrv : env -info test
5063
5164# Clean all build artifacts
5265clean :
5366 cargo clean
5467 rm -f Cargo.lock
5568
5669# Run cargo clippy to lint the code
57- clippy *ARGS :
58- cargo clippy --workspace --all-targets --all-features {{ ARGS }}
70+ clippy * args :
71+ cargo clippy --workspace --all-targets --all-features {{ args }}
5972
60- # Generate code coverage report
61- coverage *ARGS=" --no-clean --open":
62- cargo llvm-cov test --workspace --all-targets --all-features --include-build-script {{ ARGS }}
73+ # Generate code coverage report. Will install `cargo llvm-cov` if missing.
74+ coverage * args = ' --no-clean --open' : ( cargo-install ' cargo-llvm-cov' )
75+ cargo llvm-cov --workspace --all-targets --all-features --include-build-script {{ args }}
6376
6477# Build and open code documentation
6578docs :
6679 cargo doc --no-deps --all-features --open
6780
81+ # Print environment info
82+ env -info:
83+ @ echo " Running on {{ os ()}} / {{ arch ()}} "
84+ {{ just_executable ()}} --version
85+ rustc --version
86+ cargo --version
87+ rustup --version
88+ @ echo " RUSTFLAGS='$RUSTFLAGS'"
89+ @ echo " RUSTDOCFLAGS='$RUSTDOCFLAGS'"
90+
6891# Reformat all code `cargo fmt`. If nightly is available, use it for better results
6992fmt :
7093 #!/usr/bin/env bash
7194 set -euo pipefail
72- if command -v cargo + nightly &> /dev/null; then
95+ if rustup component list --toolchain nightly | grep rustfmt &> / dev/ null; then
7396 echo ' Reformatting Rust code using nightly Rust fmt to sort imports'
7497 cargo + nightly fmt --all -- --config imports_granularity=Module,group_imports=StdExternalCrate
7598 else
7699 echo ' Reformatting Rust with the stable cargo fmt. Install nightly with `rustup install nightly` for better results'
77100 cargo fmt --all
78101 fi
79102
103+ # Get any package's field from the metadata
104+ get-crate-field field package = main_crate:
105+ cargo metadata --format-version 1 | jq -r ' .packages | map(select(.name == "{{ package}} ")) | first | .{{ field}} '
106+
107+ # Get the minimum supported Rust version (MSRV) for the crate
108+ get-msrv : (get-crate-field ' rust_version' )
109+
80110# Find the minimum supported Rust version (MSRV) using cargo-msrv extension, and update Cargo.toml
81- msrv:
111+ msrv : ( cargo-install ' cargo-msrv' )
82112 cargo msrv find --write-msrv --component rustfmt --all-features --ignore-lockfile -- {{ just_executable ()}} ci-test-msrv
83113
84- rust-info:
85- rustc --version
86- cargo --version
87-
88114# Check semver compatibility with prior published version. Install it with `cargo install cargo-semver-checks`
89- semver *ARGS:
90- cargo semver-checks {{ ARGS }}
115+ semver * args : ( cargo-install ' cargo-semver-checks' )
116+ cargo semver-checks {{ args }}
91117
92118# Run all tests
93- test *ARGS :
94- cargo test --all-targets --workspace -- all-features {{ ARGS }}
119+ test :
120+ cargo test --workspace -- all-targets --all-features
95121
96122# Test documentation
97123test-doc :
98124 cargo test --doc --all-features
99- cargo doc --no-deps --all-features
125+ cargo doc --all-features --no-deps
100126
101127# Test code formatting
102128test-fmt :
@@ -107,7 +133,7 @@ test-publish:
107133 cargo + nightly -Z package-workspace publish --dry-run
108134
109135# Find unused dependencies. Install it with `cargo install cargo-udeps`
110- udeps:
136+ udeps : ( cargo-install ' cargo-udeps' )
111137 cargo + nightly udeps --all-targets --workspace --all-features
112138
113139# Update all dependencies, including breaking changes. Requires nightly toolchain (install with `rustup install nightly`)
@@ -117,23 +143,23 @@ update:
117143
118144# Ensure that a certain command is available
119145[private ]
120- assert $COMMAND :
121- @if ! type " {{ COMMAND }} " > /dev/null; then \
122- echo "Command ' {{COMMAND }}' could not be found. Please make sure it has been installed on your computer." ;\
146+ assert command :
147+ @ if ! type {{ command }} > / dev/ null; then \
148+ echo " Command '{{ command }} ' could not be found. Please make sure it has been installed on your computer." ;\
123149 exit 1 ;\
124150 fi
125151
126152# Check if a certain Cargo command is installed, and install it if needed
127153[private ]
128- cargo-install $COMMAND $INSTALL_CMD="" *ARGS="" :
154+ cargo-install $ COMMAND $ INSTALL_CMD = ' ' * args = ' ' :
129155 #!/usr/bin/env bash
130156 set -euo pipefail
131157 if ! command -v $COMMAND > / dev/ null; then
132158 if ! command -v cargo-binstall > / dev/ null; then
133- echo "$COMMAND could not be found. Installing it with cargo install ${INSTALL_CMD:-$COMMAND} {{ ARGS }} "
134- cargo install ${INSTALL_CMD:-$COMMAND} {{ ARGS }}
159+ echo " $COMMAND could not be found. Installing it with cargo install ${INSTALL_CMD:-$COMMAND} --locked {{ args }} "
160+ cargo install ${INSTALL_CMD:-$COMMAND} --locked {{ args }}
135161 else
136- echo "$COMMAND could not be found. Installing it with cargo binstall ${INSTALL_CMD:-$COMMAND} {{ ARGS }} "
137- cargo binstall ${INSTALL_CMD:-$COMMAND} {{ ARGS }}
162+ echo " $COMMAND could not be found. Installing it with cargo binstall ${INSTALL_CMD:-$COMMAND} --locked {{ args }} "
163+ cargo binstall ${INSTALL_CMD:-$COMMAND} --locked {{ args }}
138164 fi
139165 fi
0 commit comments