justfile (2914B)
1 # Standard recipes: build (debug), release, clean, test, install. 2 # 3 # just build debug build with AddressSanitizer -> build/debug/sonar 4 # just release optimised build -> build/release/sonar 5 # just test run every imported package's tests under ASan -> build/test/ 6 # just check type-check both modes without producing a binary 7 # just clean remove build/ 8 # 9 # The debug allocator and flow come from the jm collection at ~/Source/Personal/jm 10 # (override with JM=<path>); they are resolved by path until sonar ships. 11 # 12 # Debug and test builds carry -sanitize:address. The debug allocator poisons its 13 # guard bytes and freed blocks, so instrumented reads past the end or after free 14 # trap at the faulting instruction. Pass SAN= to build without it: 15 # `SAN= just build`. Odin does not create output directories, hence the mkdir. 16 17 odin := env("ODIN", "odin") 18 jm := env("JM", home_directory() / "Source" / "Personal" / "jm") 19 flags := "-vet -strict-style -collection:jm=" + jm 20 san := env("SAN", "-sanitize:address") 21 exe := if os() == "windows" { ".exe" } else { "" } 22 bin := "sonar" 23 24 # `just` alone lists the recipes. 25 default: 26 @just --list --unsorted 27 28 # Debug build with AddressSanitizer -> build/debug/sonar 29 build: 30 mkdir -p build/debug 31 {{odin}} build . -debug {{san}} {{flags}} -out:build/debug/{{bin}}{{exe}} 32 33 # Optimised build -> build/release/sonar 34 release: 35 mkdir -p build/release 36 {{odin}} build . -o:speed {{flags}} -out:build/release/{{bin}}{{exe}} 37 38 # Run the tests of every package the binary imports under ASan -> build/test/ 39 test: 40 mkdir -p build/test 41 {{odin}} test . -all-packages -debug {{san}} {{flags}} -out:build/test/{{bin}}{{exe}} 42 43 # Type-check both modes without producing a binary. 44 check: 45 {{odin}} check . {{flags}} 46 {{odin}} check . -debug {{flags}} 47 48 # Remove build/. 49 clean: 50 rm -rf build 51 52 # Copy the release binary to a directory on PATH. An installed copy is replaced in 53 # place; otherwise ~/.local/bin, ~/bin, GOBIN, GOPATH/bin, /usr/local/bin, else the 54 # first writable PATH entry. 55 install: release 56 #!/usr/bin/env bash 57 set -euo pipefail 58 dest="" 59 if existing=$(command -v {{bin}} 2>/dev/null) && [[ -w ${existing%/*} ]]; then 60 dest=${existing%/*} 61 fi 62 gopath=$(go env GOPATH 2>/dev/null || true); gobin=$(go env GOBIN 2>/dev/null || true) 63 for d in "$HOME/.local/bin" "$HOME/bin" "$gobin" "${gopath:+$gopath/bin}" /usr/local/bin; do 64 [[ -z $dest && -n $d && -d $d && -w $d && ":$PATH:" == *":$d:"* ]] && dest=$d 65 done 66 if [[ -z $dest ]]; then 67 IFS=: read -ra dirs <<<"$PATH" 68 for d in "${dirs[@]}"; do [[ -d $d && -w $d ]] && { dest=$d; break; }; done 69 fi 70 [[ -n $dest ]] || { echo "install: no writable directory on PATH" >&2; exit 1; } 71 install -m 755 build/release/{{bin}}{{exe}} "$dest/{{bin}}" 72 echo "installed $dest/{{bin}}"