diff --git a/.config/flakebox/bin/flakebox-in-each-cargo-workspace b/.config/flakebox/bin/flakebox-in-each-cargo-workspace new file mode 100755 index 00000000..addfa85d --- /dev/null +++ b/.config/flakebox/bin/flakebox-in-each-cargo-workspace @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +# Run a given command in every directory that contains cargo workspace +# Right now it just scans for `Cargo.lock` + +set -euo pipefail + +find . -name Cargo.lock | while read -r path ; do + ( + cd "$(dirname "$path")" + "$@" + ) +done diff --git a/.config/flakebox/id b/.config/flakebox/id index 74228ef7..c37296ab 100644 --- a/.config/flakebox/id +++ b/.config/flakebox/id @@ -1 +1 @@ -6ed8d7bac0d49950f28394f623607c29d00896bcf1505d366717626babadd81f8f111f93afd1b991b7087d5ce0684b4bcc10124aad93b3876ba1aba600a09cb4 +437409787773bc012f713d609c43406e98174dca8d94911ed7905618cc62f2d026781205d6583645176c630878fe6a238e3a17b85254677c632ec4c25b699a4a diff --git a/justfile b/justfile index fcc00cc5..512aeabd 100644 --- a/justfile +++ b/justfile @@ -12,38 +12,70 @@ default: # run `cargo build` on everything build: + #!/usr/bin/env bash + set -euo pipefail + if [ ! -f Cargo.toml ]; then + cd {{invocation_directory()}} + fi cargo build --workspace --all-targets # run `cargo check` on everything check: + #!/usr/bin/env bash + set -euo pipefail + if [ ! -f Cargo.toml ]; then + cd {{invocation_directory()}} + fi cargo check --workspace --all-targets # run all checks recommended before opening a PR final-check: lint clippy + #!/usr/bin/env bash + set -euo pipefail + if [ ! -f Cargo.toml ]; then + cd {{invocation_directory()}} + fi cargo test --doc just test # run code formatters format: + #!/usr/bin/env bash + set -euo pipefail + if [ ! -f Cargo.toml ]; then + cd {{invocation_directory()}} + fi cargo fmt --all nixpkgs-fmt $(echo **.nix) # run lints (git pre-commit hook) lint: + #!/usr/bin/env bash + set -euo pipefail env NO_STASH=true $(git rev-parse --git-common-dir)/hooks/pre-commit # run tests test: build + #!/usr/bin/env bash + set -euo pipefail + if [ ! -f Cargo.toml ]; then + cd {{invocation_directory()}} + fi cargo test # run and restart on changes watch: + #!/usr/bin/env bash + set -euo pipefail + if [ ! -f Cargo.toml ]; then + cd {{invocation_directory()}} + fi env RUST_LOG=${RUST_LOG:-debug} cargo watch -x run diff --git a/misc/git-hooks/pre-commit b/misc/git-hooks/pre-commit index 9d27b61f..bf4169bf 100755 --- a/misc/git-hooks/pre-commit +++ b/misc/git-hooks/pre-commit @@ -34,7 +34,7 @@ export -f check_nothing function check_cargo_fmt() { set -euo pipefail - cargo fmt --all --check + flakebox-in-each-cargo-workspace cargo fmt --all --check } export -f check_cargo_fmt @@ -43,7 +43,7 @@ function check_cargo_lock() { set -euo pipefail # https://users.rust-lang.org/t/check-if-the-cargo-lock-is-up-to-date-without-building-anything/91048/5 - cargo update --workspace --locked + flakebox-in-each-cargo-workspace cargo update --workspace --locked } export -f check_cargo_lock @@ -52,7 +52,7 @@ function check_leftover_dbg() { set -euo pipefail errors="" - for path in $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep '.*\.rs'); do + for path in $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep '.*\.rs'); do if grep 'dbg!(' "$path" > /dev/null; then >&2 echo "$path contains dbg! macro" errors="true"