diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3f86f1e..342ff64 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,8 +9,8 @@ defaults: env: GST_GIT_REPO: https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git GST_GIT_BRANCH: main - RPI_SYSROOT: /rpi-tools/arm-bcm2708/arm-linux-gnueabihf/arm-linux-gnueabihf/sysroot - RPI_BIN: /rpi-tools/arm-bcm2708/arm-linux-gnueabihf/bin + GST_SRC_DIR: gst-plugins-rs/audio/spotify +# $RPI_BIN and $RPI_SYSROOT are defined in the docker images jobs: # This job must run on the runner because hashFiles() operates on the runner @@ -44,15 +44,15 @@ jobs: include: - target: arm-unknown-linux-gnueabihf linker: arm-linux-gnueabihf - linker_path: ${RPI_BIN} + linker_path: $RPI_BIN/ extra_rust_flags: -L$RPI_SYSROOT/lib -L$RPI_SYSROOT/usr/lib - target: aarch64-unknown-linux-gnu linker: aarch64-linux-gnu + - target: x86_64-unknown-linux-gnu + linker: x86_64-linux-gnu runs-on: ubuntu-20.04 container: ghcr.io/mopidy/gst-plugin-spotify-build:latest needs: bust-cache - env: - GST_PLUGIN: gst-plugin-spotify steps: - name: Checkout repo uses: actions/checkout@v4 @@ -66,6 +66,9 @@ jobs: - name: Checkout gst-plugins-rs run: | git clone --depth 1 -b ${{ env.GST_GIT_BRANCH }} ${{ env.GST_GIT_REPO }} + + - name: Backup original plugin Cargo.toml file + run: | cp gst-plugins-rs/audio/spotify/Cargo.toml Cargo.toml.orig - name: Cache cargo stuff @@ -87,34 +90,27 @@ jobs: run: | TARGET=${{ matrix.target }} LINKER=${{ matrix.linker }} + LINKER_PATH=$(eval "echo ${{ matrix.linker_path }}") + EXTRA_RUSTFLAGS=$(eval "echo ${{ matrix.extra_rust_flags }}") - PKG_CONFIG_ALLOW_CROSS=1 + [ $(gcc -dumpmachine) != "{$LINKER}" ] && PKG_CONFIG_ALLOW_CROSS=1 export PKG_CONFIG_PATH=/usr/lib/${LINKER}/pkgconfig - GST_PLUGINS_DIR=$(pkg-config --variable=pluginsdir gstreamer-1.0) + export PATH="${LINKER_PATH}:$PATH" + export RUSTFLAGS="-C linker=${LINKER}-gcc $EXTRA_RUSTFLAGS" echo "PKG_CONFIG_ALLOW_CROSS=$PKG_CONFIG_ALLOW_CROSS" >> $GITHUB_ENV echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH" >> $GITHUB_ENV - echo "GST_PLUGINS_DIR=$GST_PLUGINS_DIR" >> $GITHUB_ENV + echo "PATH=$PATH" >> $GITHUB_ENV + echo "RUSTFLAGS=$RUSTFLAGS" >> $GITHUB_ENV echo "TARGET=$TARGET" >> $GITHUB_ENV echo "LINKER=$LINKER" >> $GITHUB_ENV + echo "LINKER=$LINKER" >> $GITHUB_ENV - - name: Add linker tools to path - if: matrix.linker_path != '' - run: | - LINKER_PATH=$(eval "echo ${{ matrix.linker_path }}") - echo "PATH=$LINKER_PATH:$PATH" >> $GITHUB_ENV - which $LINKER - - - name: Configure RUSTFLAGS - run: | - RUSTFLAGS=$(eval "echo -C linker=${LINKER}-gcc ${{ matrix.extra_rust_flags }}") - echo "RUSTFLAGS=$RUSTFLAGS" >> $GITHUB_ENV - - name: Build gst-plugins-rs run: | env | sort - cd gst-plugins-rs - cargo build --target=${TARGET} --package ${GST_PLUGIN} --release + pushd ${GST_SRC_DIR} + cargo build --target=${TARGET} --release - name: Strip binary run: | @@ -132,22 +128,24 @@ jobs: - name: Prepare deb package run: | echo "Append package metadata to Cargo.toml" - cat Cargo.toml.orig Cargo.toml.deb > gst-plugins-rs/audio/spotify/Cargo.toml + cat Cargo.toml.orig Cargo.toml.deb > ${GST_SRC_DIR}/Cargo.toml echo "Fixup target-specific library install path" - sed -i "s@%GST_PLUGINS_DIR%@$GST_PLUGINS_DIR@" gst-plugins-rs/audio/spotify/Cargo.toml + TARGET_PLUGINS_DIR=$(pkg-config --variable=pluginsdir gstreamer-1.0) + sed -i "s@%GST_PLUGINS_DIR%@$TARGET_PLUGINS_DIR@" ${GST_SRC_DIR}/Cargo.toml - name: Create deb package run: | - cd gst-plugins-rs - cargo deb -v --target=${TARGET} --package ${GST_PLUGIN} --no-build - DEB_PATH=$(readlink -m $(find target/${TARGET}/debian/*.deb)) - echo "DEB_PATH=$DEB_PATH" >> $GITHUB_ENV + pushd ${GST_SRC_DIR} + cargo deb -v --target=${TARGET} --no-build - name: Check deb - run: dpkg-deb --field $DEB_PATH Package Architecture Version Installed-Size + run: | + DEB_FILE=$(find gst-plugins-rs/target/${TARGET}/debian/*.deb) + dpkg-deb --field $DEB_FILE Package Architecture Version Installed-Size + echo "DEB_FILE=$DEB_FILE" >> $GITHUB_ENV - name: Upload deb uses: actions/upload-artifact@v3 with: name: ${{ matrix.target }} Debian Package - path: ${{ env.DEB_PATH }} + path: ${{ env.DEB_FILE }} diff --git a/Makefile b/Makefile index 34774b9..10d12ef 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,15 @@ REPO = ghcr.io/mopidy -IMAGE = gst-plugin-rs-build +IMAGE = gst-plugin-spotify-build VERSION = $(shell cat VERSION) +WORKDIR = /gst-plugin-spotify-build .PHONY: build release git-release docker-release build: docker-build build-armhf build-x86_64 build-armhf: - docker run -v ./../gst-plugins-rs:/gst-plugins-rs:z -v .:/gst-plugin-rs-build:z ${REPO}/${IMAGE}:${VERSION} /bin/bash /gst-rs-spotify-build/entrypoint.sh armhf + [ -v GST_PLUGINS_RS_SRC ] && export GST_PLUGINS_RS_MOUNT="-v ${GST_PLUGINS_RS_SRC}:${WORKDIR}/gst-plugins-rs:z" + docker run ${GST_PLUGINS_RS_MOUNT} -v .:${WORKDIR}:z --workdir ${WORKDIR} ${REPO}/${IMAGE}:${VERSION} /bin/bash entrypoint.sh armhf docker-build: docker build --tag ${REPO}/${IMAGE}:${VERSION} --file Dockerfile . diff --git a/entrypoint.sh b/entrypoint.sh index e5c7c5c..4d11e52 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,32 +2,18 @@ GST_GIT_REPO=https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git GST_GIT_BRANCH=main -GST_PLUGIN=gst-plugin-spotify - -cd gst-plugins-rs-build - -# 1. Install Rust stuff -curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal -source "$HOME/.cargo/env" -cargo install cargo-deb - -## We need to do the build ourselves as cargo-deb doesn't understand the asset target -## is from our package (because the name was mangled by adding "lib" and ".so") and -## so will build the whole workspace (all packages) which is slow and requires -## more deps. +GST_SRC_DIR=gst-plugins-rs/audio/spotify case $1 in armhf) export TARGET=arm-unknown-linux-gnueabihf export LINKER=arm-linux-gnueabihf export LINKER_PATH=$RPI_BIN - export PKG_CONFIG_ALLOW_CROSS=1 export EXTRA_RUSTFLAGS="-L$RPI_SYSROOT/lib -L$RPI_SYSROOT/usr/lib" ;; arm64) export TARGET=aarch64-unknown-linux-gnu export LINKER=aarch64-linux-gnu - export PKG_CONFIG_ALLOW_CROSS=1 ;; x86_64) export TARGET=x86_64-unknown-linux-gnu @@ -39,43 +25,50 @@ x86_64) ;; esac +# Install Rust stuff +curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal --target $TARGET +source "$HOME/.cargo/env" +cargo install cargo-deb + +# Configure environment +[ $(gcc -dumpmachine) != "${LINKER}" ] && export PKG_CONFIG_ALLOW_CROSS=1 +export PKG_CONFIG_PATH=/usr/lib/${LINKER}/pkgconfig export PATH="${LINKER_PATH}:$PATH" export RUSTFLAGS="-C linker=${LINKER}-gcc $EXTRA_RUSTFLAGS" -export PKG_CONFIG_PATH=/usr/lib/${LINKER}/pkgconfig -export GST_PLUGINS_DIR=$(pkg-config --variable=pluginsdir gstreamer-1.0) - env | sort -rustup target add $TARGET - -# 2. Checkout source if required +# Checkout source if required [ ! -d "gst-plugins-rs" ] && git clone --depth 1 -b $GST_GIT_BRANCH $GST_GIT_REPO -# 3. Backup the original .toml file -[ ! -f "Cargo.toml.orig" ] && cp gst-plugins-rs/audio/spotify/Cargo.toml Cargo.toml.orig +# Backup original .toml file +[ ! -f "Cargo.toml.orig" ] && cp ${GST_SRC_DIR}/Cargo.toml Cargo.toml.orig -# 4. Build GStreamer plugin -pushd gst-plugins-rs -cargo build --target=$TARGET --package $GST_PLUGIN --release -v +# Build GStreamer plugin +## We need to do the build ourselves as cargo-deb doesn't understand the asset target +## is from our package (because the asset name had "lib" and ".so" added) and +## so will build the whole workspace (all packages) which is slow and requires more deps. +pushd ${GST_SRC_DIR} +cargo build --target=$TARGET --release -v popd -# 5. Strip the binary +# Strip the binary SO_FILE=$(find gst-plugins-rs/target/$TARGET/release/*.so) ls -l $SO_FILE ${LINKER}-strip $SO_FILE ls -l $SO_FILE -# 6. Repare Debian package -cat Cargo.toml.orig Cargo.toml.deb > gst-plugins-rs/audio/spotify/Cargo.toml -sed -i "s@%GST_PLUGINS_DIR%@$GST_PLUGINS_DIR@" gst-plugins-rs/audio/spotify/Cargo.toml +# Prepare Debian package +cat Cargo.toml.orig Cargo.toml.deb > ${GST_SRC_DIR}/Cargo.toml +TARGET_PLUGINS_DIR=$(pkg-config --variable=pluginsdir gstreamer-1.0) +sed -i "s@%GST_PLUGINS_DIR%@$TARGET_PLUGINS_DIR@" ${GST_SRC_DIR}/Cargo.toml -# 7. Build Debian package -# Got to specify target despite no-build else cargo-deb looks in the workspace for the asset, see comment at top. +# Build Debian package +# Must specify target despite no-build else cargo-deb looks in the workspace for the asset, see comment at top. #WITH_DEBUG=" --separate-debug-symbols" -pushd gst-plugins-rs -cargo deb --target=$TARGET --package $GST_PLUGIN --no-build $WITH_DEBUG -v +pushd ${GST_SRC_DIR} +cargo deb --target=$TARGET --no-build $WITH_DEBUG -v popd # Sanity check -DEB_FILE=$(find gst-plugins-rs/target/$TARGET/debian/gst-plugin-spotify_*.deb) +DEB_FILE=$(find gst-plugins-rs/target/$TARGET/debian/*.deb) dpkg-deb --field $DEB_FILE Package Architecture Version Installed-Size