# Tapir monorepo — top-level tasks.
#
# Parts: the Rust workspace (this directory), the website (web/, Zola), the
# handbook (book/, mdBook), the mobile app (mobile/, Flutter) and the brand art
# (icon/, SVG -> PNG). Each part is a `just` module: run e.g. `just web build`,
# `just book serve`, `just mobile apk`, `just art render`. Build the whole
# project with `just all`.
#
#   just            # list recipes
#   just build      # debug-build the Rust workspace
#   just all        # build every buildable part (Rust + web + art)
#   just web serve  # run a part's recipe

set shell := ["bash", "-uc"]

# Sub-projects as modules.
mod web
mod book
mod mobile
mod art 'icon/justfile'

# Default: list available recipes.
default:
    @just --list --unsorted

# --- Rust workspace (the primary project) ------------------------------------

# Debug-build the whole workspace.
build:
    cargo build --workspace

# Optimized release build (LLVM) — for shipping binaries.
release:
    cargo build --workspace --release

# Run the test suite.
test:
    cargo test --workspace

# Lint with clippy across all targets.
clippy:
    cargo clippy --workspace --all-targets

# Format the code in place.
fmt:
    cargo fmt --all

# Fail if any code is unformatted (CI).
fmt-check:
    cargo fmt --all -- --check

# Build + clippy + tests (CI gate for the Rust part).
check: build clippy test

# Build the library API docs (this workspace's crates only, no dependencies).
doc:
    cargo doc --workspace --no-deps

# Build the docs and open them in a browser.
doc-open:
    cargo doc --workspace --no-deps --open

# One-time setup: `rustup toolchain install nightly` and
# `rustup component add rustc-codegen-cranelift-preview --toolchain nightly`.
# Fast dev build via Cranelift — ~2x faster codegen (nightly, dev-only, unoptimized).
dev *args:
    cargo +nightly -Zcodegen-backend --config 'profile.dev.codegen-backend="cranelift"' build --workspace {{args}}

# Like `dev`, but runs the tests with the Cranelift backend.
dev-test *args:
    cargo +nightly -Zcodegen-backend --config 'profile.dev.codegen-backend="cranelift"' test --workspace {{args}}

# --- Whole monorepo ----------------------------------------------------------

# Mobile APK is separate (needs the Android SDK + a device): `just mobile apk`.
# Build every buildable part: Rust workspace + website + handbook + art.
all: build (web::build) (book::build) (art::render)

# Remove build outputs across the parts (not the committed art PNGs).
clean: (web::clean) (book::clean) (mobile::clean)
    cargo clean
