makedepends=(rustc cargo-c nasm)

description="An AV1 encoder focused on speed and safety"
url=https://github.com/xiph/rav1e/

name=rav1e
version=0.8.1
release=3

source=(
  https://github.com/xiph/rav1e/archive/refs/tags/v${version}.tar.gz
  https://github.com/xiph/rav1e/releases/download/v${version}/Cargo.lock
)

prepare() {

  cp -f Cargo.lock rav1e-${version}/Cargo.lock
  cargo fetch \
    --locked \
    --manifest-path rav1e-${version}/Cargo.toml
}

build() {
  cargo build \
    --release \
    --frozen \
    --manifest-path rav1e-${version}/Cargo.toml

  cargo cbuild \
    --release \
    --frozen \
    --prefix=/usr \
    --libdir=/usr/lib \
    --manifest-path rav1e-${version}/Cargo.toml

  cargo test \
    --release \
    --frozen \
    --manifest-path rav1e-${version}/Cargo.toml
}

package() {
  cd rav1e-${version}
  cargo install \
    --frozen \
    --offline \
    --no-track \
    --path . \
    --root "${PKG}"/usr

  cargo cinstall \
    --release \
    --frozen \
    --prefix=/usr \
    --libdir=/usr/lib \
    --destdir "${PKG}"

  install -Dm 644 LICENSE PATENTS -t "${PKG}"/usr/share/licenses/rav1e/
}
