pkgname=cargo-c
pkgver=0.10.16
pkgdesc='A cargo subcommand to build and install C-ABI compatible dynamic and static libraries'
arch=('x86_64')
url='https://github.com/lu-zero/cargo-c/'
license=('MIT')
depends=(
  'cargo'
  'curl'
  'gcc'
  'glibc'
  'openssl'
  'zlib'
)
sources=("${pkgname}-${pkgver}.tar.gz"
  "${pkgname}-${pkgver}.Cargo.lock"
)
urls=("https://github.com/lu-zero/cargo-c/archive/refs/tags/v${pkgver}.tar.gz"
  "https://github.com/lu-zero/cargo-c/releases/download/v${pkgver}/Cargo.lock"
)
md5sums=("b2cd3dbd325519c5eba15c319e520967"
  "31fbd21611f04092e9cbccfccc25d4c7"
)

src_prepare() {
  tar -xf ${distdir}/${sources[0]} --strip-components=1
  cp -v "${distdir}/${sources[1]}" ./Cargo.lock
  cargo fetch --locked --target "$(rustc --print host-tuple)" --manifest-path="./Cargo.toml"
}

src_build() {
  export CFLAGS+=' -ffat-lto-objects'
  export CARGO_TARGET_DIR="${pkgname}-${pkgver}/target"
  cargo build --release --frozen --manifest-path="Cargo.toml"
}

src_check() {
  export CFLAGS+=' -ffat-lto-objects'
  export CARGO_TARGET_DIR="${pkgname}-${pkgver}/target"
  cargo test --frozen --manifest-path="Cargo.toml"
}

src_install() {
    find "${pkgname}-${pkgver}/target/release" -maxdepth 1 -type f -executable -exec install -vDm755 -t "${pkgdir}/usr/bin" {} +
    install -D -m644 "LICENSE" -t "${pkgdir}/usr/share/licenses/${pkgname}"
}


# vim:ft=sh syn=sh et sw=2:
