|
| 1 | +#!/usr/bin/env just --justfile |
| 2 | + |
| 3 | +main_crate := 'harfrust' |
| 4 | +features_flag := '--all-features' |
| 5 | + |
| 6 | +# if running in CI, treat warnings as errors by setting RUSTFLAGS and RUSTDOCFLAGS to '-D warnings' unless they are already set |
| 7 | +# Use `CI=true just ci-test` to run the same tests as in GitHub CI. |
| 8 | +# Use `just env-info` to see the current values of RUSTFLAGS and RUSTDOCFLAGS |
| 9 | +ci_mode := if env('CI', '') != '' {'1'} else {''} |
| 10 | +export RUSTFLAGS := env('RUSTFLAGS', if ci_mode == '1' {'-D warnings'} else {''}) |
| 11 | +export RUSTDOCFLAGS := env('RUSTDOCFLAGS', if ci_mode == '1' {'-D warnings'} else {''}) |
| 12 | +export RUST_BACKTRACE := env('RUST_BACKTRACE', if ci_mode == '1' {'1'} else {''}) |
| 13 | + |
| 14 | +@_default: |
| 15 | + {{just_executable()}} --list |
| 16 | + |
| 17 | +# Build the project |
| 18 | +build: build-lib build-lib-no-std |
| 19 | + cargo build --workspace --all-targets {{features_flag}} |
| 20 | + |
| 21 | +# Build just the core lib |
| 22 | +build-lib: |
| 23 | + cargo build --lib --package {{main_crate}} {{features_flag}} |
| 24 | + |
| 25 | +# Build just the core lib with no_std |
| 26 | +build-lib-no-std: |
| 27 | + cargo build --lib --package {{main_crate}} --no-default-features |
| 28 | + |
| 29 | +# Quick compile without building a binary |
| 30 | +check: |
| 31 | + cargo check --workspace --all-targets {{features_flag}} |
| 32 | + cargo check --lib --package {{main_crate}} {{features_flag}} |
| 33 | + cargo check --lib --package {{main_crate}} --no-default-features |
| 34 | + |
| 35 | +# Generate code coverage report to upload to codecov.io |
| 36 | +ci-coverage: env-info && \ |
| 37 | + (coverage '--codecov --output-path target/llvm-cov/codecov.info') |
| 38 | + # ATTENTION: the full file path above is used in the CI workflow |
| 39 | + mkdir -p target/llvm-cov |
| 40 | + |
| 41 | +# Run all tests as expected by CI |
| 42 | +ci-test: env-info test-fmt build test test-doc clippy && assert-git-is-clean |
| 43 | + |
| 44 | +# Run minimal subset of tests to ensure compatibility with MSRV |
| 45 | +ci-test-msrv: env-info build-lib build-lib-no-std test |
| 46 | + |
| 47 | +# Clean all build artifacts |
| 48 | +clean: |
| 49 | + cargo clean |
| 50 | + rm -f Cargo.lock |
| 51 | + |
| 52 | +# Run cargo clippy to lint the code |
| 53 | +clippy *args: |
| 54 | + cargo clippy --workspace --all-targets {{features_flag}} {{args}} |
| 55 | + |
| 56 | +# Generate code coverage report. Will install `cargo llvm-cov` if missing. |
| 57 | +coverage *args='--no-clean --open': (cargo-install 'cargo-llvm-cov') |
| 58 | + cargo llvm-cov --workspace --all-targets {{features_flag}} --include-build-script {{args}} |
| 59 | + |
| 60 | +# Build and open code documentation |
| 61 | +docs *args='--open': |
| 62 | + DOCS_RS=1 cargo doc --no-deps {{args}} --workspace {{features_flag}} |
| 63 | + |
| 64 | +# Print environment info |
| 65 | +env-info: |
| 66 | + @echo "Running {{if ci_mode == '1' {'in CI mode'} else {'in dev mode'} }} on {{os()}} / {{arch()}}" |
| 67 | + {{just_executable()}} --version |
| 68 | + rustc --version |
| 69 | + cargo --version |
| 70 | + rustup --version |
| 71 | + @echo "RUSTFLAGS='$RUSTFLAGS'" |
| 72 | + @echo "RUSTDOCFLAGS='$RUSTDOCFLAGS'" |
| 73 | + @echo "RUST_BACKTRACE='$RUST_BACKTRACE'" |
| 74 | + |
| 75 | +# Reformat all code `cargo fmt`. |
| 76 | +fmt: |
| 77 | + cargo fmt --all |
| 78 | + |
| 79 | +# Get any package's field from the metadata |
| 80 | +get-crate-field field package=main_crate: (assert-cmd 'jq') |
| 81 | + cargo metadata --format-version 1 | jq -e -r '.packages | map(select(.name == "{{package}}")) | first | .{{field}} | select(. != null)' |
| 82 | + |
| 83 | +# Get the minimum supported Rust version (MSRV) for the crate |
| 84 | +get-msrv package=main_crate: (get-crate-field 'rust_version' package) |
| 85 | + |
| 86 | +# Find the minimum supported Rust version (MSRV) using cargo-msrv extension, and update Cargo.toml |
| 87 | +msrv: (cargo-install 'cargo-msrv') |
| 88 | + cargo msrv find --write-msrv --ignore-lockfile {{features_flag}} |
| 89 | + |
| 90 | +release *args='': (cargo-install 'release-plz') |
| 91 | + release-plz {{args}} |
| 92 | + |
| 93 | +# Check semver compatibility with prior published version. Install it with `cargo install cargo-semver-checks` |
| 94 | +semver *args: (cargo-install 'cargo-semver-checks') |
| 95 | + cargo semver-checks {{features_flag}} {{args}} |
| 96 | + |
| 97 | +# Run all unit and integration tests |
| 98 | +test: |
| 99 | + cargo test --workspace --all-targets {{features_flag}} |
| 100 | + cargo test --workspace --doc {{features_flag}} |
| 101 | + |
| 102 | +# Test documentation generation |
| 103 | +test-doc: (docs '') |
| 104 | + |
| 105 | +# Test code formatting |
| 106 | +test-fmt: |
| 107 | + cargo fmt --all -- --check |
| 108 | + |
| 109 | +# Find unused dependencies. Install it with `cargo install cargo-udeps` |
| 110 | +udeps: (cargo-install 'cargo-udeps') |
| 111 | + cargo +nightly udeps --workspace --all-targets {{features_flag}} |
| 112 | + |
| 113 | +# Update all dependencies, including breaking changes. Requires nightly toolchain (install with `rustup install nightly`) |
| 114 | +update: |
| 115 | + cargo +nightly -Z unstable-options update --breaking |
| 116 | + cargo update |
| 117 | + |
| 118 | +# Ensure that a certain command is available |
| 119 | +[private] |
| 120 | +assert-cmd 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." ;\ |
| 123 | + exit 1 ;\ |
| 124 | + fi |
| 125 | + |
| 126 | +# Make sure the git repo has no uncommitted changes |
| 127 | +[private] |
| 128 | +assert-git-is-clean: |
| 129 | + @if [ -n "$(git status --untracked-files --porcelain)" ]; then \ |
| 130 | + >&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." ;\ |
| 131 | + >&2 echo "######### git status ##########" ;\ |
| 132 | + git status ;\ |
| 133 | + git --no-pager diff ;\ |
| 134 | + exit 1 ;\ |
| 135 | + fi |
| 136 | + |
| 137 | +# Check if a certain Cargo command is installed, and install it if needed |
| 138 | +[private] |
| 139 | +cargo-install $COMMAND $INSTALL_CMD='' *args='': |
| 140 | + #!/usr/bin/env bash |
| 141 | + set -euo pipefail |
| 142 | + if ! command -v $COMMAND > /dev/null; then |
| 143 | + if ! command -v cargo-binstall > /dev/null; then |
| 144 | + echo "$COMMAND could not be found. Installing it with cargo install ${INSTALL_CMD:-$COMMAND} --locked {{args}}" |
| 145 | + cargo install ${INSTALL_CMD:-$COMMAND} --locked {{args}} |
| 146 | + else |
| 147 | + echo "$COMMAND could not be found. Installing it with cargo binstall ${INSTALL_CMD:-$COMMAND} --locked {{args}}" |
| 148 | + cargo binstall ${INSTALL_CMD:-$COMMAND} --locked {{args}} |
| 149 | + fi |
| 150 | + fi |
0 commit comments