diff options
Diffstat (limited to 'development/cargo-vendor-filterer')
-rw-r--r-- | development/cargo-vendor-filterer/README | 10 | ||||
-rw-r--r-- | development/cargo-vendor-filterer/cargo-mkvendored.sh | 139 | ||||
-rw-r--r-- | development/cargo-vendor-filterer/cargo-vendor-filterer.SlackBuild | 132 | ||||
-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, 312 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..2664e9eec4 --- /dev/null +++ b/development/cargo-vendor-filterer/cargo-mkvendored.sh @@ -0,0 +1,139 @@ +#!/bin/bash + +# Create $PRGNAM-vendored-sources-$VERSION-$VSBUILD.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. +# +# Variables to use in your SlackBuild: +# VSBUILD # same use as BUILD but for vendored sources +# VSDIR=/sub/dir/ # (optional) alternate location in src for vendor dir +# +# Vendors sources for the following targets +# i686-unknown-linux-gnu +# x86_64-unknown-linux-gnu +# arm-unknown-linux-gnueabihf +# aarch64-unknown-linux-gnu + +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=|^VSBUILD=|^VSDIR=|^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/$VSDIR || exit 1 + +if [ ! -e "Cargo.toml" ]; then + echo "No Cargo.toml file in $SRCNAM-$VERSION dir" 1>&2 + exit 1 +elif [ -e "$CWD/Cargo-toml.patch" ]; then + echo "INFO: Applying Cargo.toml patch" + patch -Np1 < $CWD/Cargo-toml.patch +fi + +if [ -z "$ARCH" ]; then + case "$( uname -m )" in + i?86) ARCH=i686 ;; + 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", "aarch64-unknown-linux-gnu", "arm-unknown-linux-gnueabihf"] +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-$VSBUILD.tar.xz \ + $SRCNAM-$VERSION/$VSDIR/{vendor,.cargo} +md5sum $CWD/$SRCNAM-vendored-sources-$VERSION-$VSBUILD.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..6cec63b571 --- /dev/null +++ b/development/cargo-vendor-filterer/cargo-vendor-filterer.SlackBuild @@ -0,0 +1,132 @@ +#!/bin/bash + +# Copyright 2023-2024 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. + +# 20230925 46and2: Bump build, changes to mkvendored script. +# 20230927 46and2: 32-bit fix thanks to Eugene Carlson. Min ARCH=i686. +# 20240102 46and2: modify to use VSBUILD instead of BUILD for vendored sources +# above requested by Andrew Clemons to avoid CI issues +# -also added VSDIR option to included script, see cargo-mkvendored.sh +# 20240213 46and2: Fix FTB on arm + +cd $(dirname $0) ; CWD=$(pwd) + +PRGNAM=cargo-vendor-filterer +VERSION=${VERSION:-0.5.14} +BUILD=${BUILD:-1} +TAG=${TAG:-_SBo} +PKGTYPE=${PKGTYPE:-tgz} +VSBUILD=${VSBUILD:-1} + +if [ -z "$ARCH" ]; then + case "$( uname -m )" in + i?86) ARCH=i686 ;; + 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 + +if [ "$ARCH" = "arm" ]; then + TRIPLET="$ARCH-unknown-linux-gnueabihf" +else + TRIPLET="$ARCH-unknown-linux-gnu" +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-$VSBUILD.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 $TRIPLET + +mkdir -p $PKG/usr/bin +install -m 755 target/$TRIPLET/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..4169ba09d6 --- /dev/null +++ b/development/cargo-vendor-filterer/cargo-vendor-filterer.info @@ -0,0 +1,12 @@ +PRGNAM="cargo-vendor-filterer" +VERSION="0.5.14" +HOMEPAGE="https://github.com/coreos/cargo-vendor-filterer" +DOWNLOAD="https://github.com/coreos/cargo-vendor-filterer/archive/v0.5.14/cargo-vendor-filterer-0.5.14.tar.gz \ + https://slackware.uk/~fourtysixandtwo/src/cargo-vendor-filterer-vendored-sources-0.5.14-1.tar.xz" +MD5SUM="f5b9df9adc3c9d05c5ad62529fe354f7 \ + ca7986322b63d02809d7acb48fca3f2c" +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: |