.PHONY: build check test fmt clippy run deploy ts backdrop backdrop-check

build:
	cargo build --release

check: fmt clippy test

fmt:
	cargo fmt --all -- --check

clippy:
	cargo clippy --workspace --all-targets -- -D warnings

test:
	cargo test --workspace

run:
	cargo run -- --data data serve

# TypeScript declarations of the API types, for the VS Code extensions.
ts:
	cargo run -q -p hub-api --bin hub-api-typescript > crates/hub-api/ts/index.d.ts

# Developer edition on Earth (docs/deploy.md).
deploy:
	rsync -a --delete --exclude target --exclude node_modules --exclude .oxy/objects/loose ../oxygen ../oxygenflow ../oxygenhub claude@earth:src/
	B="$$(oxy --plain describe 2>/dev/null)"; ssh claude@earth "source ~/.cargo/env && cd src/oxygenhub && OXY_BUILD='$$B' cargo build --release && sudo install -m 0755 target/release/oxygenhub /usr/local/bin/oxygenhub && sudo systemctl restart oxygenhub && systemctl is-active oxygenhub"

# Move the pinned oxygenflow (deps/oxygenflow) to its main on Earth, with the
# oxygen it pins; the next commit records the new pin. Push oxygen, then
# oxygenflow (with `make pins` there), first.
.PHONY: pins
pins:
	cd deps/oxygenflow && oxy --plain pull origin && oxy --plain submodule update --init

# Backdrops (docs/backgrounds.md): build the engine (crates/backdrop, a
# workspace of its own) for wasm32 and write its .wasm and wasm-bindgen glue
# to assets/backdrop/, which the hub embeds and which are committed, so the
# hub build and its CI need no wasm toolchain. Needs the wasm32-unknown-unknown
# target and wasm-bindgen-cli at the version in crates/backdrop/Cargo.lock.
backdrop:
	cd crates/backdrop && cargo build --release --target wasm32-unknown-unknown
	wasm-bindgen --target web --no-typescript --out-dir assets/backdrop crates/backdrop/target/wasm32-unknown-unknown/release/backdrop.wasm

backdrop-check:
	cd crates/backdrop && cargo fmt --check && cargo clippy --target wasm32-unknown-unknown -- -D warnings && cargo test
