#!/bin/bash

VERSION=$1

rm -rf rustc-demangle-*.tar.?z cargo-rustc-demangle*

echo "Downloading rustc-demangle-$VERSION..."

wget --content-disposition "https://github.com/rust-lang/rustc-demangle/archive/refs/tags/$VERSION.tar.gz"

tar xf rustc-demangle-$VERSION.tar.gz

tar cf rustc-demangle-$VERSION.tar rustc-demangle-$VERSION

cd rustc-demangle-$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-rustc-demangle-$VERSION
cd ..

tar cf cargo-rustc-demangle-$VERSION.tar cargo-rustc-demangle-$VERSION

plzip -9 cargo-rustc-demangle-$VERSION.tar
plzip -9 rustc-demangle-$VERSION.tar

rm -rf rustc-demangle-$VERSION
rm -rf cargo-rustc-demangle-$VERSION
rm -f rustc-demangle-$VERSION.tar.gz
