set shell := ["bash", "-euo", "pipefail", "-c"]

# Everything below assumes the flake's environment — `nix develop`, or direnv
# with `use flake`. That is where the compiler, the C toolchain, PipeWire's
# headers and the kernel headers bindgen wants come from; a bare shell has none
# of them, and the recipes deliberately do not paper over that.
#
# The nix outputs are the other half of this file. `just build` is the edit
# loop; `nix build` is the artifact.

default:
    @just --list

# The shared objects, ready to be put on a loader search path.
build *args:
    cargo build --release {{args}}

# The same three objects, built by nix instead of by the ambient cargo — pinned
# compiler, pinned crate graph, byte-identical between machines. This is what
# `just buck-build` used to be, minus the second dependency graph.
nix-build:
    nix build .#libs
    @echo "{{justfile_directory()}}/result/lib"

# Both objects, cross-compiled for a 64-bit Android device. The NDK comes from
# the flake, so the only thing a machine needs installed for this is nix.
#
# The camera needs two things from the APK that this recipe cannot supply: a
# `CameraCapture` class in its classes.dex (frq has one), and a call to
# joltmoq_android_init. See android/jolt_main.c.
ffi-android:
    nix build .#android
    @echo "{{justfile_directory()}}/result/lib/arm64-v8a"

# Where a consumer points LD_LIBRARY_PATH.
libdir:
    @echo "{{justfile_directory()}}/target/release"

test *args:
    cargo test --workspace {{args}}

# Without cpal's PipeWire host — device *names* get worse (ALSA PCMs only),
# everything else is equal. Kept for a machine outside the flake that has
# neither pkg-config nor PipeWire's headers.
test-minimal:
    cargo test --workspace --no-default-features

lint:
    cargo clippy --workspace --all-targets -- -D warnings
    cargo fmt --all --check

# Everything CI runs, in one go: fmt, clippy, tests and all three objects.
check:
    nix flake check
