# BlueRune's pinned copy of Virtical's AUR recipe virtical
# (https://git.joeypayne.com/jyapayne/virtical, packaging/aur/virtical at 94dc219a819f4391003abda02710f976f98f7473),
# unchanged below this comment. release/publish.sh --extras builds it in a clean chroot and
# publishes it to BlueRune's repository. To move to a newer version, copy Virtical's
# packaging/aur/virtical over this directory and update the commit above.
#
# Maintainer: Joey Yakimowich-Payne <jyapayne@pm.me>
pkgname=virtical
pkgver=0.1.0
pkgrel=1
pkgdesc='Desktop manager for KVM/QEMU virtual machines, over libvirt'
arch=('x86_64')
url='https://git.joeypayne.com/jyapayne/virtical'
license=('MIT')
# wayland, libxkbcommon and vulkan-icd-loader are loaded with dlopen(); qemu is what libvirt
# runs the VMs with.
depends=('glibc' 'libgcc' 'libvirt' 'qemu' 'wayland' 'libxkbcommon' 'vulkan-icd-loader' 'hicolor-icon-theme')
makedepends=('cargo')
optdepends=(
    'qemu-vmvga: the VMware SVGA 3D display adapter'
    'libguestfs: Mount Virtual Disks and Compact'
    'virt-viewer: open SPICE VMs'
    'swtpm: virtual TPM for new VMs'
    'edk2-ovmf: UEFI firmware for VMs'
    'osinfo-db: operating system list in the New VM wizard'
    'libisoburn: xorriso, for Easy Install media'
    'fuse3: dragging files out of VMs onto the desktop (fusermount3)'
    'libxcursor: running in an X11 session'
    'libxi: running in an X11 session'
)
source=("$pkgname-$pkgver.tar.gz::$url/archive/v$pkgver.tar.gz")
sha256sums=('edb1dde55610e4e6fdff859ad2e39d7200ede58526baf2a0d8badbea4305f42d')

_id=dev.virtical.Virtical

# rust-toolchain.toml pins the version developers use (with clippy and rustfmt); the code
# builds with any current stable Rust, so packages use the distribution's.
prepare() {
    cd "$pkgname"
    export RUSTUP_TOOLCHAIN=stable
    cargo fetch --locked --target "$(rustc -vV | sed -n 's/^host: //p')"
}

build() {
    cd "$pkgname"
    export RUSTUP_TOOLCHAIN=stable
    export CARGO_TARGET_DIR=target
    cargo build --frozen --release -p virtical
}

check() {
    cd "$pkgname"
    export RUSTUP_TOOLCHAIN=stable
    export CARGO_TARGET_DIR=target
    cargo test --frozen --release --workspace
}

package() {
    cd "$pkgname"
    install -Dm755 target/release/virtical "$pkgdir/usr/bin/virtical"
    install -Dm644 "packaging/$_id.desktop" "$pkgdir/usr/share/applications/$_id.desktop"
    install -Dm644 "packaging/$_id.metainfo.xml" "$pkgdir/usr/share/metainfo/$_id.metainfo.xml"
    local size
    for size in 16 24 32 48 64 128 256 512; do
        install -Dm644 "packaging/icons/hicolor/${size}x${size}/$_id.png" \
            "$pkgdir/usr/share/icons/hicolor/${size}x${size}/apps/$_id.png"
    done
    install -Dm644 "packaging/icons/$_id.svg" "$pkgdir/usr/share/icons/hicolor/scalable/apps/$_id.svg"
    install -Dm644 "packaging/icons/$_id-symbolic.svg" "$pkgdir/usr/share/icons/hicolor/symbolic/apps/$_id-symbolic.svg"
    install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
