11#!/ usr/ bin/ env just --justfile
22
33main_crate := ' fastpfor'
4+ features_flag := ' --all-features'
45
56# if running in CI, treat warnings as errors by setting RUSTFLAGS and RUSTDOCFLAGS to '-D warnings' unless they are already set
67# Use `CI=true just ci-test` to run the same tests as in GitHub CI.
78# Use `just env-info` to see the current values of RUSTFLAGS and RUSTDOCFLAGS
8- ci_mode := if env (' CI' , ' ' ) != ' ' { ' 1' } else { ' ' }
9+ ci_mode := if env (' CI' , ' ' ) != ' ' {' 1' } else {' ' }
10+ # cargo-binstall needs a workaround due to caching
11+ # ci_mode might be manually set by user, so re-check the env var
12+ binstall_args := if env (' CI' , ' ' ) != ' ' {' --no-track' } else {' ' }
913export RUSTFLAGS := env (' RUSTFLAGS' , if ci_mode == ' 1' {' -D warnings' } else {' ' })
1014export RUSTDOCFLAGS := env (' RUSTDOCFLAGS' , if ci_mode == ' 1' {' -D warnings' } else {' ' })
1115export RUST_BACKTRACE := env (' RUST_BACKTRACE' , if ci_mode == ' 1' {' 1' } else {' ' })
1216
1317@_ default :
14- just --list
18+ {{ just_executable () }} --list
1519
1620# Run integration tests and save its output as the new expected output
1721bless * args : (cargo-install ' cargo-insta' )
18- TRYBUILD=overwrite cargo insta test --accept --unreferenced=delete --all-features
22+ cargo insta test --accept --unreferenced=delete {{ features_flag }} {{ args }}
1923
2024# Build the project
2125build :
22- cargo build --workspace --all-targets --all-features
26+ cargo build --workspace --all-targets {{ features_flag }}
2327
2428# Quick compile without building a binary
2529check :
26- cargo check --workspace --all-targets --all-features
27-
28- # Verify that the current version of the crate is not the same as the one published on crates.io
29- check-if-published : (assert ' jq' )
30- #!/usr/bin/env bash
31- set -euo pipefail
32- LOCAL_VERSION=" $({{ just_executable ()}} get-crate-field version)"
33- echo " Detected crate version: '$LOCAL_VERSION'"
34- CRATE_NAME=" $({{ just_executable ()}} get-crate-field name)"
35- echo " Detected crate name: '$CRATE_NAME'"
36- PUBLISHED_VERSION=" $(cargo search ${CRATE_NAME} | grep " ^${CRATE_NAME} =" | sed -E 's/.* = " (.*)" .*/\1 /')"
37- echo " Published crate version: '$PUBLISHED_VERSION'"
38- if [ " $LOCAL_VERSION" = " $PUBLISHED_VERSION" ]; then
39- echo " ERROR: The current crate version has already been published."
40- exit 1
41- else
42- echo " The current crate version has not yet been published."
43- fi
30+ cargo check --workspace --all-targets {{ features_flag}}
4431
4532# Generate code coverage report to upload to codecov.io
46- ci-coverage : && \
33+ ci-coverage : env-info && \
4734 (coverage ' --codecov --output-path target/llvm-cov/codecov.info' )
4835 # ATTENTION: the full file path above is used in the CI workflow
4936 mkdir -p target/ llvm-cov
5037
5138# Run all tests as expected by CI
52- ci-test : env-info test-fmt build clippy test test-doc
53- #!/usr/bin/env bash
54- set -euo pipefail
55- if [ -n " $(git status --untracked-files --porcelain)" ]; then
56- >&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.'
57- >&2 echo ' ######### git status ##########'
58- git status
59- exit 1
60- fi
39+ ci-test : env-info test-fmt build clippy test test-doc && assert-git-is-clean
6140
6241# Run minimal subset of tests to ensure compatibility with MSRV
6342ci-test-msrv : env-info test
@@ -69,64 +48,73 @@ clean:
6948
7049# Run cargo clippy to lint the code
7150clippy * args :
72- cargo clippy --workspace --all-targets --all-features {{ args}}
51+ cargo clippy --workspace --all-targets {{ features_flag }} {{ args}}
7352
7453# Generate code coverage report. Will install `cargo llvm-cov` if missing.
7554coverage * args = ' --no-clean --open': (cargo-install ' cargo-llvm-cov' )
76- cargo llvm-cov --workspace --all-targets --all-features --include-build-script {{ args}}
55+ cargo llvm-cov --workspace --all-targets {{ features_flag }} --include-build-script {{ args}}
7756
7857# Build and open code documentation
79- docs :
80- cargo doc --no-deps --all-features --open
58+ docs * args = ' --open' :
59+ DOCS_RS= 1 cargo doc --no-deps {{ args }} --workspace {{ features_flag }}
8160
8261# Print environment info
8362env -info:
8463 @ echo " Running {{ if ci_mode == ' 1' {' in CI mode' } else {' in dev mode' } }} on {{ os ()}} / {{ arch ()}} "
64+ @ echo " PWD $(pwd)"
8565 {{ just_executable ()}} --version
8666 rustc --version
8767 cargo --version
8868 rustup --version
8969 @ echo " RUSTFLAGS='$RUSTFLAGS'"
9070 @ echo " RUSTDOCFLAGS='$RUSTDOCFLAGS'"
71+ @ echo " RUST_BACKTRACE='$RUST_BACKTRACE'"
9172
9273# Reformat all code `cargo fmt`. If nightly is available, use it for better results
9374fmt :
9475 #!/usr/bin/env bash
9576 set -euo pipefail
96- if rustup component list --toolchain nightly | grep rustfmt &> / dev/ null; then
77+ if ( rustup toolchain list | grep nightly && rustup component list --toolchain nightly | grep rustfmt) &> / dev/ null; then
9778 echo ' Reformatting Rust code using nightly Rust fmt to sort imports'
9879 cargo + nightly fmt --all -- --config imports_granularity=Module,group_imports=StdExternalCrate
9980 else
10081 echo ' Reformatting Rust with the stable cargo fmt. Install nightly with `rustup install nightly` for better results'
10182 cargo fmt --all
10283 fi
10384
85+ # Reformat all Cargo.toml files using cargo-sort
86+ fmt-toml * args : (cargo-install ' cargo-sort' )
87+ cargo sort --workspace --grouped {{ args}}
88+
10489# Get any package's field from the metadata
105- get-crate-field field package = main_crate:
106- cargo metadata --format-version 1 | jq -r ' .packages | map(select(.name == "{{ package}} ")) | first | .{{ field}} '
90+ get-crate-field field package = main_crate: ( assert-cmd ' jq' )
91+ cargo metadata --format-version 1 | jq -e - r ' .packages | map(select(.name == "{{ package}} ")) | first | .{{ field}} | select(. != null) '
10792
10893# Get the minimum supported Rust version (MSRV) for the crate
109- get-msrv : (get-crate-field ' rust_version' )
94+ get-msrv package = main_crate : (get-crate-field ' rust_version' package )
11095
11196# Find the minimum supported Rust version (MSRV) using cargo-msrv extension, and update Cargo.toml
11297msrv : (cargo-install ' cargo-msrv' )
113- cargo msrv find --write-msrv --component rustfmt --all-features --ignore-lockfile -- {{ just_executable ()}} ci-test-msrv
98+ cargo msrv find --write-msrv --component rustfmt {{ features_flag}} --ignore-lockfile -- {{ just_executable ()}} ci-test-msrv
99+
100+ # Run cargo-release
101+ release * args = ' ': (cargo-install ' release-plz' )
102+ release-plz {{ args}}
114103
115104# Check semver compatibility with prior published version. Install it with `cargo install cargo-semver-checks`
116105semver * args : (cargo-install ' cargo-semver-checks' )
117- cargo semver-checks {{ args}}
106+ cargo semver-checks {{ features_flag }} {{ args}}
118107
119- # Run all tests
108+ # Run all unit and integration tests
120109test :
121- cargo test --workspace --all-targets --all-features
110+ cargo test --workspace --all-targets {{ features_flag}}
111+ cargo test --workspace --doc {{ features_flag}}
122112
123- # Test documentation
124- test-doc :
125- cargo test --doc --all-features
126- cargo doc --all-features --no-deps
113+ # Test documentation generation
114+ test-doc : (docs ' ' )
127115
128116# Test code formatting
129- test-fmt :
117+ test-fmt : && ( fmt-toml ' --check' ' --check-format' )
130118 cargo fmt --all -- --check
131119
132120# Use the experimental workspace publishing with --dry-run. Requires nightly Rust.
@@ -135,7 +123,7 @@ test-publish:
135123
136124# Find unused dependencies. Install it with `cargo install cargo-udeps`
137125udeps : (cargo-install ' cargo-udeps' )
138- cargo + nightly udeps --all-targets -- workspace --all-features
126+ cargo + nightly udeps --workspace --all-targets {{ features_flag }}
139127
140128# Update all dependencies, including breaking changes. Requires nightly toolchain (install with `rustup install nightly`)
141129update :
@@ -144,12 +132,23 @@ update:
144132
145133# Ensure that a certain command is available
146134[private ]
147- assert command:
135+ assert -cmd command:
148136 @ if ! type {{ command}} > / dev/ null; then \
149137 echo " Command '{{ command}} ' could not be found. Please make sure it has been installed on your computer." ;\
150138 exit 1 ;\
151139 fi
152140
141+ # Make sure the git repo has no uncommitted changes
142+ [private ]
143+ assert -git-is-clean :
144+ @ if [ -n " $(git status --untracked-files --porcelain)" ]; then \
145+ >&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." ;\
146+ >&2 echo " ######### git status ##########" ;\
147+ git status ;\
148+ git --no-pager diff ;\
149+ exit 1 ;\
150+ fi
151+
153152# Check if a certain Cargo command is installed, and install it if needed
154153[private ]
155154cargo-install $ COMMAND $ INSTALL_CMD = ' ' * args = ' ':
@@ -160,7 +159,7 @@ cargo-install $COMMAND $INSTALL_CMD='' *args='':
160159 echo " $COMMAND could not be found. Installing it with cargo install ${INSTALL_CMD:-$COMMAND} --locked {{ args}} "
161160 cargo install ${INSTALL_CMD:-$COMMAND} --locked {{ args}}
162161 else
163- echo " $COMMAND could not be found. Installing it with cargo binstall ${INSTALL_CMD:-$COMMAND} --locked {{ args}} "
164- cargo binstall ${INSTALL_CMD:-$COMMAND} --locked {{ args}}
162+ echo " $COMMAND could not be found. Installing it with cargo binstall ${INSTALL_CMD:-$COMMAND} {{ binstall_args }} --locked {{ args}} "
163+ cargo binstall ${INSTALL_CMD:-$COMMAND} {{ binstall_args }} --locked {{ args}}
165164 fi
166165 fi
0 commit comments