makedepends=(rustc)

description="A cargo subcommand to build and install C-ABI compatibile dynamic and static libraries"
url="https://github.com/lu-zero/cargo-c/"

packager="Great-OS Team"
maintainer="Great-OS Team"

name=cargo-c
version=0.10.21
release=1

source=(https://github.com/lu-zero/cargo-c/archive/v${version}/${name}-${version}.tar.gz)

prepare() {
  cargo fetch --manifest-path="${name}-${version}/Cargo.toml"
}

build() {
  export CFLAGS+=' -ffat-lto-objects'
  export RUSTUP_TOOLCHAIN='stable'
  export CARGO_TARGET_DIR="${name}-${version}/target"
  cargo build --release --frozen --manifest-path="${name}-${version}/Cargo.toml"

  export CFLAGS+=' -ffat-lto-objects'
  export RUSTUP_TOOLCHAIN='stable'
  export CARGO_TARGET_DIR="${name}-${version}/target"
  cargo test --frozen --manifest-path="${name}-${version}/Cargo.toml"
}

package() {
  find "${name}-${version}/target/release" -maxdepth 1 -type f -executable -exec install -D -m755 -t "${PKG}/usr/bin" {} +
  install -D -m644 "${name}-${version}/LICENSE" -t "${PKG}/usr/share/licenses/${name}"
}
