#!/usr/bin/make -f
# debian/rules for agtop — builds the Rust binary, offline, against
# the vendored crates that packages/ppa/build.sh stages into the
# orig.tar.gz before debuild runs.
#
# Launchpad PPA builders have NO network during the build phase, so
# we cannot rely on dh-cargo's default behaviour of resolving deps
# against crates.io or against Debian's `librust-*-dev` archive.
# Instead the upstream tarball ships:
#
#   vendor/                 cargo-vendor output, full dep tree
#   .cargo/config.toml      redirects crate fetches to vendor/
#
# `--frozen --offline` then make cargo refuse to touch the network.

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export RUSTFLAGS = -C link-arg=-Wl,-z,relro,-z,now
export CARGO_NET_OFFLINE = true

# Pin to noble's rustc-1.89 / cargo-1.89.  Stock noble ships
# rustc 1.75 (no edition2024); a number of our deps require Rust
# >= 1.88 (sysinfo, ratatui, darling, instability, time…) and
# edition2024 (clap_derive et al, stabilised in 1.85).  1.89 is
# the highest noble-main rustc that satisfies both.
CARGO  ?= /usr/bin/cargo-1.89
RUSTC  ?= /usr/bin/rustc-1.89
export CARGO RUSTC

%:
	dh $@

override_dh_auto_build:
	$(CARGO) build --release --frozen --offline --locked

override_dh_auto_test:
	$(CARGO) test --release --frozen --offline --locked

override_dh_auto_install:
	install -Dm755 target/release/agtop \
		debian/agtop/usr/bin/agtop
	install -Dm644 README.md \
		debian/agtop/usr/share/doc/agtop/README.md

override_dh_auto_clean:
	rm -rf target Cargo.lock.bak
	dh_auto_clean
