# Maintainer: monikapurpl3 <monikapurpl3@users.noreply.github.com>
#
# breeze-core, built from source by makepkg. Generated by
# packaging/source/build-source.sh from PKGBUILD.in, which is the file to edit.
#
# The same package as the one in the aspic repository -- the same name, files,
# service account and install scriptlets, so either replaces the other -- with
# a binary built here by Arch's Rust and linked against Arch's glibc, where the
# repository's is static musl.

pkgname=breeze-core
pkgver=4.3.2
pkgrel=1
pkgdesc="Self-hosted, LAN-first control for Midea air conditioners (built from source)"
arch=(x86_64 aarch64 armv7h riscv64)
url="https://github.com/monikapurpl3/breeze-core-native"
license=(AGPL-3.0-or-later)
depends=(gcc-libs glibc)
# 1.88 is the oldest Rust the dependencies accept (the ICU crates, by way of
# idna); Arch's is always newer.
makedepends=(cargo)
backup=(etc/breeze-core/breeze-core.env)
install=breeze-core.install
# !lto: makepkg's -flto CFLAGS would reach ring's C objects, which rustc's
# linker then cannot use. !debug: the release profile strips the binary, so a
# debug package would be empty.
options=(!lto !debug)
source=("breeze-core-$pkgver.tar.xz"
        "breeze-core-$pkgver-vendor.tar.xz")
sha256sums=('92b9bae6bad2e63882dbe28e982b6403edc739f6c8fd18905eff2291ae90fcdd'
            '63018ac488cd804ca788ce2c9e9b23f1b0edf117c9d69c25698194145e1d2479')

prepare() {
  cd "breeze-core-$pkgver"
  ln -sfn "$srcdir/vendor" vendor
  mkdir -p .cargo
  # The vendored crates and nothing else: a clean-chroot build has no network.
  printf '[source.crates-io]\nreplace-with = "vendored-sources"\n\n[source.vendored-sources]\ndirectory = "vendor"\n' > .cargo/config.toml
}

build() {
  cd "breeze-core-$pkgver"
  export BREEZE_COMMIT=2ef0d09
  cargo build --release --locked --offline -p breeze-core
}

check() {
  cd "breeze-core-$pkgver"
  cargo test --locked --offline --workspace
}

package() {
  cd "breeze-core-$pkgver"
  install -Dm0755 target/release/breeze-core "$pkgdir/usr/bin/breeze-core"
  install -d "$pkgdir/usr/lib/breeze-core"
  ln -s /usr/bin/breeze-core "$pkgdir/usr/lib/breeze-core/breeze-core"
  install -Dm0644 packaging/nfpm/breeze-core.service "$pkgdir/usr/lib/systemd/system/breeze-core.service"
  install -d -m0750 "$pkgdir/etc/breeze-core"
  install -m0640 packaging/nfpm/breeze-core.env "$pkgdir/etc/breeze-core/breeze-core.env"
  install -Dm0644 README.md LICENSE -t "$pkgdir/usr/share/doc/breeze-core/"
}
