#!/bin/bash

VERSION=$1

rm -rf hyperfine-*.tar.?z cargo-hyperfine*

echo "Downloading hyperfine-$VERSION..."

wget --content-disposition "https://github.com/sharkdp/hyperfine/archive/refs/tags/v$VERSION.tar.gz"

tar xf hyperfine-$VERSION.tar.gz

tar cf hyperfine-$VERSION.tar hyperfine-$VERSION

cd hyperfine-$VERSION

  # Configure cargo-vendor-filterer
  cat << EOF >> Cargo.toml
[package.metadata.vendor-filter]
platforms = ["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"]
all-features = true
EOF


  if ! [ -f /usr/bin/cargo-vendor-filterer ]; then
    echo "WARNING: Creating unfiltered vendor libs tarball!"
    cargo vendor
  else
    cargo vendor-filterer
  fi

  mv vendor ../cargo-hyperfine-$VERSION
cd ..

tar cf cargo-hyperfine-$VERSION.tar cargo-hyperfine-$VERSION

plzip -9 cargo-hyperfine-$VERSION.tar
plzip -9 hyperfine-$VERSION.tar

rm -rf hyperfine-$VERSION
rm -rf cargo-hyperfine-$VERSION
rm -f hyperfine-$VERSION.tar.gz
