# Maintainer: Cleta LLC <https://archscript.org>
# https://github.com/Cleta-LLC/archscript

pkgname=archscript
pkgver=0.2.4
pkgrel=1
pkgdesc="ArchScript programming language — Python-like syntax, Haskell-inspired features, Arch Linux integration"
arch=('x86_64')
url="https://archscript.org"
license=('MPL-2.0')
makedepends=('rust' 'cargo')
optdepends=('yay: AUR helper integration for aur.* stdlib module')
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/Cleta-LLC/archscript/archive/refs/tags/v${pkgver}.tar.gz")
sha256sums=('SKIP')

prepare() {
    cd "${pkgname}-${pkgver}"
    export RUSTUP_TOOLCHAIN=stable
    cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

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

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

package() {
    cd "${pkgname}-${pkgver}"

    # Install binary
    install -Dm755 "target/release/${pkgname}" "${pkgdir}/usr/bin/${pkgname}"

    # Install license
    install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"

    # Install example scripts
    install -dm755 "${pkgdir}/usr/share/${pkgname}/examples"
    install -Dm644 examples/*.as "${pkgdir}/usr/share/${pkgname}/examples/"

    # Install documentation
    install -Dm644 README.md "${pkgdir}/usr/share/doc/${pkgname}/README.md"
}
