diff options
-rw-r--r-- | development/cargo-vendor-filterer/README | 10 | ||||
-rw-r--r-- | development/cargo-vendor-filterer/cargo-mkvendored.sh | 126 | ||||
-rw-r--r-- | development/cargo-vendor-filterer/cargo-vendor-filterer.SlackBuild | 118 | ||||
-rw-r--r-- | development/cargo-vendor-filterer/cargo-vendor-filterer.info | 12 | ||||
-rw-r--r-- | development/cargo-vendor-filterer/slack-desc | 19 |
5 files changed, 285 insertions, 0 deletions
diff --git a/development/cargo-vendor-filterer/README b/development/cargo-vendor-filterer/README new file mode 100644 index 0000000000..83f9687535 --- /dev/null +++ b/development/cargo-vendor-filterer/README @@ -0,0 +1,10 @@ +cargo-vendor-filterer (Vendor rust libraries based on filters) + +cargo-vendor-filterer works like "cargo vendor", but supports filters +that allow excluding libraries one isn't interested in, like +libraries only needed on other platforms, etc. + +NOTE: +I've included a "cargo-mkvendored.sh" script to generate filtered +vendored sources for a rust or python/rust slackbuild. It needs to be +run from within a slackbuild directory. diff --git a/development/cargo-vendor-filterer/cargo-mkvendored.sh b/development/cargo-vendor-filterer/cargo-mkvendored.sh new file mode 100644 index 0000000000..39d1e2d6b2 --- /dev/null +++ b/development/cargo-vendor-filterer/cargo-mkvendored.sh @@ -0,0 +1,126 @@ +#!/bin/bash + +# Create $PRGNAM-vendored-sources-$VERSION-$BUILD.tar.xz +# Requires network access, but does not require root privilege. +# Requires that $PRGNAM's REQUIRES need to be installed first (rust16) +# and cargo-vendor-filterer installed to include just the linux deps +# +# Expects to be run within a slackbuild dir with the source archive +# already downloaded. + +INFO="$( echo *.info )" +if [ ! -e "$INFO" ]; then + echo "No (or multiple) .info file in current dir" 1>&2 + exit 1 +fi + +SBUILD="$( echo *.SlackBuild )" +if [ ! -e "$SBUILD" ]; then + echo "No (or multiple) .SlackBuild file in current dir" 1>&2 + exit 1 +fi + +CWD=$(pwd) +source ./$INFO + +INFOERR="variable not set, are you sure you have a valid *.info file?" +echo ${PRGNAM:?$INFOERR} +echo VERSION=${VERSION:?$INFOERR} + +set -e +WORKDIR=$( mktemp -d ) +cd $WORKDIR + +# don't depend on user's ~/.cargo +mkdir -p cargohome +export CARGO_HOME=$(pwd)/cargohome + +egrep "^BUILD=|^SRCNAM=" $CWD/$SBUILD > sbvars +source ./sbvars + +# if no SRCNAM in slackbuild set to PRGNAM +SRCNAM=${SRCNAM:-$PRGNAM} + +tar xvf $CWD/$SRCNAM-$VERSION.tar.gz +cd $SRCNAM-$VERSION || exit 1 + +if [ ! -e "Cargo.toml" ]; then + echo "No Cargo.toml file in $SRCNAM-$VERSION dir" 1>&2 + exit 1 +fi + +if [ -z "$ARCH" ]; then + case "$( uname -m )" in + i?86) ARCH=i586 ;; + arm*) ARCH=arm ;; + *) ARCH=$( uname -m ) ;; + esac +fi + +if [ "$ARCH" = "i586" ]; then + SLKCFLAGS="-O2 -march=i586 -mtune=i686" + LIBDIRSUFFIX="" +elif [ "$ARCH" = "i686" ]; then + SLKCFLAGS="-O2 -march=i686 -mtune=i686" + LIBDIRSUFFIX="" +elif [ "$ARCH" = "x86_64" ]; then + SLKCFLAGS="-O2 -fPIC" + LIBDIRSUFFIX="64" +elif [ "$ARCH" = "aarch64" ]; then + SLKCFLAGS="-O2 -fPIC" + LIBDIRSUFFIX="64" +else + SLKCFLAGS="-O2" + LIBDIRSUFFIX="" +fi + +# check if rust16 is installed +if [ ! -d /opt/rust16/bin ]; then + echo "ERROR: The rust16 slackbuild is required to be installed" + exit 1 +else + export PATH="/opt/rust16/bin:$PATH" + if [ -z "$LD_LIBRARY_PATH" ]; then + export LD_LIBRARY_PATH="/opt/rust16/lib$LIBDIRSUFFIX" + else + export LD_LIBRARY_PATH="/opt/rust16/lib$LIBDIRSUFFIX:$LD_LIBRARY_PATH" + fi +fi + +# 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 +exclude-crate-paths = [ + { name = "openssl-src", exclude = "openssl" }, +] +EOF + +if [ -f /usr/bin/cargo-vendor-filterer ]; then + echo "INFO: Creating filtered vendor libs tarball..." + /usr/bin/cargo-vendor-filterer +else + echo "WARNING: Creating unfiltered vendor libs tarball!" + cargo vendor +fi + +# build would fail if the .a files were removed +#find vendor -type f -a -name \*.a -print0 | xargs -0 rm -f + +mkdir -p .cargo + cat <<EOF >.cargo/config.toml +[source.crates-io] +replace-with = "vendored-sources" + +[source.vendored-sources] +directory = "vendor" +EOF +cd - + +cd $WORKDIR +tar cvfJ $CWD/$SRCNAM-vendored-sources-$VERSION-$BUILD.tar.xz \ + $SRCNAM-$VERSION/{vendor,.cargo} +md5sum $CWD/$SRCNAM-vendored-sources-$VERSION-$BUILD.tar.xz +cd $CWD +rm -rf $WORKDIR diff --git a/development/cargo-vendor-filterer/cargo-vendor-filterer.SlackBuild b/development/cargo-vendor-filterer/cargo-vendor-filterer.SlackBuild new file mode 100644 index 0000000000..b12e512c39 --- /dev/null +++ b/development/cargo-vendor-filterer/cargo-vendor-filterer.SlackBuild @@ -0,0 +1,118 @@ +#!/bin/bash + +# Copyright 2023 fourtysixandtwo <fourtysixandtwo@sliderr.net> +# Copyright 2022 Patrick J. Volkerding, Sebeka, MN, USA +# Copyright 2022 Heinz Wiesinger, Amsterdam, The Netherlands +# All rights reserved. +# +# Redistribution and use of this script, with or without modification, is +# permitted provided that the following conditions are met: +# +# 1. Redistributions of this script must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +cd $(dirname $0) ; CWD=$(pwd) + +PRGNAM=cargo-vendor-filterer +VERSION=${VERSION:-0.5.11} +BUILD=${BUILD:-1} +TAG=${TAG:-_SBo} +PKGTYPE=${PKGTYPE:-tgz} + +if [ -z "$ARCH" ]; then + case "$( uname -m )" in + i?86) ARCH=i586 ;; + arm*) ARCH=arm ;; + *) ARCH=$( uname -m ) ;; + esac +fi + +if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then + echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE" + exit 0 +fi + +TMP=${TMP:-/tmp/SBo} +PKG=$TMP/package-$PRGNAM +OUTPUT=${OUTPUT:-/tmp} + +if [ "$ARCH" = "i586" ]; then + SLKCFLAGS="-O2 -march=i586 -mtune=i686" + LIBDIRSUFFIX="" +elif [ "$ARCH" = "i686" ]; then + SLKCFLAGS="-O2 -march=i686 -mtune=i686" + LIBDIRSUFFIX="" +elif [ "$ARCH" = "x86_64" ]; then + SLKCFLAGS="-O2 -fPIC" + LIBDIRSUFFIX="64" +elif [ "$ARCH" = "aarch64" ]; then + SLKCFLAGS="-O2 -fPIC" + LIBDIRSUFFIX="64" +else + SLKCFLAGS="-O2" + LIBDIRSUFFIX="" +fi + +set -e + +rm -rf $PKG +mkdir -p $TMP $PKG $OUTPUT +cd $TMP +rm -rf $PRGNAM-$VERSION +tar xvf $CWD/$PRGNAM-$VERSION.tar.?z +tar xvf $CWD/$PRGNAM-vendored-sources-$VERSION-$BUILD.tar.?z +cd $PRGNAM-$VERSION + +chown -R root:root . +find -L . \ + \( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \ + -o -perm 511 \) -exec chmod 755 {} \+ -o \ + \( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \ + -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \+ + +export PATH="/opt/rust16/bin:$PATH" +if [ -z "$LD_LIBRARY_PATH" ]; then + export LD_LIBRARY_PATH="/opt/rust16/lib$LIBDIRSUFFIX" +else + export LD_LIBRARY_PATH="/opt/rust16/lib$LIBDIRSUFFIX:$LD_LIBRARY_PATH" +fi + +CFLAGS="$SLKCFLAGS" \ +CXXFLAGS="$SLKCFLAGS" \ +OPENSSL_NO_VENDOR=1 \ +cargo build \ + --offline \ + --release \ + --target $ARCH-unknown-linux-gnu + +mkdir -p $PKG/usr/bin +install -m 755 target/$ARCH-unknown-linux-gnu/release/cargo-vendor-filterer \ + $PKG/usr/bin/ + +# add script to generate filtered vendor sources +install -m 755 $CWD/cargo-mkvendored.sh $PKG/usr/bin/ + +find $PKG -print0 | xargs -0 file | grep -e "executable" -e "shared object" | grep ELF \ + | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true + +mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION +cp -a *.md LICENSE \ + $PKG/usr/doc/$PRGNAM-$VERSION +cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild + +mkdir -p $PKG/install +cat $CWD/slack-desc > $PKG/install/slack-desc + +cd $PKG +/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE diff --git a/development/cargo-vendor-filterer/cargo-vendor-filterer.info b/development/cargo-vendor-filterer/cargo-vendor-filterer.info new file mode 100644 index 0000000000..766cfc714e --- /dev/null +++ b/development/cargo-vendor-filterer/cargo-vendor-filterer.info @@ -0,0 +1,12 @@ +PRGNAM="cargo-vendor-filterer" +VERSION="0.5.11" +HOMEPAGE="https://github.com/coreos/cargo-vendor-filterer" +DOWNLOAD="https://github.com/coreos/cargo-vendor-filterer/archive/v0.5.11/cargo-vendor-filterer-0.5.11.tar.gz \ + https://slackware.uk/~fourtysixandtwo/src/cargo-vendor-filterer-vendored-sources-0.5.11-1.tar.xz" +MD5SUM="2dd470af105d06ca9b69be84198a31d3 \ + 744904c9e84722e3fba88e9280cf2d65" +DOWNLOAD_x86_64="" +MD5SUM_x86_64="" +REQUIRES="rust16" +MAINTAINER="fourtysixandtwo" +EMAIL="fourtysixandtwo@sliderr.net" diff --git a/development/cargo-vendor-filterer/slack-desc b/development/cargo-vendor-filterer/slack-desc new file mode 100644 index 0000000000..1c8d67c1ef --- /dev/null +++ b/development/cargo-vendor-filterer/slack-desc @@ -0,0 +1,19 @@ +# HOW TO EDIT THIS FILE: +# The "handy ruler" below makes it easier to edit a package description. +# Line up the first '|' above the ':' following the base package name, and +# the '|' on the right side marks the last column you can put a character in. +# You must make exactly 11 lines for the formatting to be correct. It's also +# customary to leave one space after the ':' except on otherwise blank lines. + + |-----handy-ruler------------------------------------------------------| +cargo-vendor-filterer: cargo-vendor-filterer (Vendor rust libraries based on filters) +cargo-vendor-filterer: +cargo-vendor-filterer: cargo-vendor-filterer works like "cargo vendor", but supports filters +cargo-vendor-filterer: that allow excluding libraries one isn't interested in, like +cargo-vendor-filterer: libraries only needed on other platforms, etc. +cargo-vendor-filterer: +cargo-vendor-filterer: Homepage: https://github.com/coreos/cargo-vendor-filterer +cargo-vendor-filterer: +cargo-vendor-filterer: +cargo-vendor-filterer: +cargo-vendor-filterer: |