deno/revendor_source.sh

64 lines
1.4 KiB
Bash
Raw Normal View History

#!/bin/sh
set -euo pipefail
# packaging helper to workaround:
# https://github.com/rust-lang/cargo/issues/9054
# https://github.com/rust-lang/cargo/issues/7058#issuecomment-751589229
# This script merges rusty_v8 into place from source,
# and nukes superfluous source objects.
#
# output is a single, merged vendor tarball
wd="$(mktemp -d /tmp/revendor.XXXXX)"
# take what we need into the build
cp rusty_v8*xz $wd
cp vendor*xz $wd
cd $wd
echo -n "Extracting vendor..."
tar xf vendor*xz
echo "done"
echo -n "Extracting rusty_v8..."
tar xf rusty*xz \
--exclude="Cargo.toml" \
--exclude="Cargo.lock"
echo " done"
# take vendored Cargo toml and lock which
# can still be used
cp vendor/rusty_v8/{Cargo.*,.cargo*} .
# get rid of everything else
rm -fr vendor/rusty_v8
# drop version prefix
target=$(find . -name "rusty_v8-*" -type d)
mv $target rusty_v8
# insert proper files
mv Cargo.* .cargo* rusty_v8
echo "Check final rusty_v8 root:"
ls -la rusty_v8
mv rusty_v8 vendor
# extra: workaround winapi bloat
# by ejecting it from the build
#
# https://github.com/rust-lang/cargo/issues/7058
echo -n "Pruning winapi bloat... "
rm -fr vendor/winapi*gnu*/lib/*.a
echo "done"
# remake tarball
echo -n "Compressing archive... "
tar -cf - vendor/ | xz -9 -c - > vendor-merged.tar.xz
echo "done"
echo "Inspect the tarball and replace the"
echo "existing one if it's ok. Should be under 30MB."
ls -lh "$wd/vendor-merged.tar.xz"