# Project gates. Plain `make` runs everything that must pass before a commit.

.PHONY: all fmt lint test build proto bench clean desktop desktop-lint

all: fmt lint test build

fmt:
	cargo fmt --all
	npm --prefix apps/viewer run format

lint:
	cargo fmt --all --check
	cargo clippy --workspace --all-targets -- -D warnings
	npm --prefix apps/viewer run lint

# `--skip export_bindings`: the ts-rs generation tests would write into
# apps/viewer/src/proto on every run. The `proto` target handles that, along
# with the matching formatting.
test:
	cargo test --workspace -- --skip export_bindings

# The protocol's TypeScript types are generated, never written by hand.
# They are excluded from the formatter and the linter (see biome.json): their
# format belongs to ts-rs, otherwise every `make` leaves a diff in the repository.
proto:
	cargo test -p rs-proto -p rs-store -p rs-session -p rs-signaling export_bindings

build:
	cargo build --workspace
	npm --prefix apps/viewer run build

# Test bench: always in release, a debug binary skews the measurements.
bench:
	cargo run --release -p rs-session --bin rustscreen-cli -- --synthetic

# The Tauri shell: WebKitGTK at build time, so inside `nix develop .#desktop`.
# Its crate has its own workspace; it shares the target directory to avoid
# rebuilding everything. pnpm for the shell's interface, npm for the viewer.
desktop:
	pnpm --dir apps/desktop install --frozen-lockfile
	pnpm --dir apps/desktop build
	cd apps/desktop/src-tauri && CARGO_TARGET_DIR=../../../target cargo build --release --features pipewire

desktop-lint:
	node scripts/check-licenses.mjs --desktop
	pnpm --dir apps/desktop lint
	pnpm --dir apps/desktop test
	cd apps/desktop/src-tauri && cargo fmt --check && CARGO_TARGET_DIR=../../../target cargo clippy --features pipewire -- -D warnings

clean:
	cargo clean
	rm -rf apps/viewer/dist apps/desktop/dist
