Skip to content

Commit

Permalink
Ensure rustfmt works in all environments
Browse files Browse the repository at this point in the history
Fixes Granola-Team#574

Nix environment has rustfmt nightly and won't work with +nightly. Non-Nix environment needs nightly toolchain installed and requires +nightly.

I ended up checking the rustfmt version instead of checking to see if we are inside the Nix environment. However, I'm leaving related reading about how to determine if inside a Nix environment: NixOS/nix#6677
  • Loading branch information
jhult committed Mar 13, 2024
1 parent 589210b commit e412cba
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
# The command 'just' will give usage information.
# See https://github.com/casey/just for more.

# Ensure rustfmt works in all environments
# Nix environment has rustfmt nightly and won't work with +nightly
# Non-Nix environment needs nightly toolchain installed and requires +nightly
is_rustfmt_nightly := `rustfmt --version | grep stable || echo "true"`
nightly_if_required := if is_rustfmt_nightly == "true" { "" } else { "+nightly" }

default:
@just --list --justfile {{justfile()}}

Expand All @@ -22,7 +28,7 @@ clean:
rm -rf result

format:
cargo fmt --all
cargo {{nightly_if_required}} fmt --all

test: test-unit
./test
Expand All @@ -46,7 +52,7 @@ audit:
cargo audit

lint: && audit disallow-unused-cargo-deps
cargo fmt --all --check
cargo {{nightly_if_required}} fmt --all --check
cargo clippy --all-targets --all-features -- -D warnings

images:
Expand Down

0 comments on commit e412cba

Please sign in to comment.