Skip to content

Commit

Permalink
working
Browse files Browse the repository at this point in the history
  • Loading branch information
kingosticks committed Nov 3, 2023
1 parent 588e12d commit caea4d6
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 67 deletions.
59 changes: 29 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -87,38 +90,33 @@ 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 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: |
SO_FILE=$(find gst-plugins-rs/target/${TARGET}/release/*.so)
SO_FILE=$(find gst-plugins-rs/target/$TARGET/release/*.so)
ls -l $SO_FILE
${LINKER}-strip $SO_FILE
ls -l $SO_FILE
Expand All @@ -132,22 +130,23 @@ 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
sed -i "s@%GST_PLUGINS_DIR%@$GST_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 }}
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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 .
Expand Down
63 changes: 28 additions & 35 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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_PLUGIN_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
Expand All @@ -39,43 +25,50 @@ x86_64)
;;
esac

export PATH="${LINKER_PATH}:$PATH"
export RUSTFLAGS="-C linker=${LINKER}-gcc $EXTRA_RUSTFLAGS"
# 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 GST_PLUGINS_DIR=$(pkg-config --variable=pluginsdir gstreamer-1.0)

export PATH="${LINKER_PATH}:$PATH"
export RUSTFLAGS="-C linker=${LINKER}-gcc $EXTRA_RUSTFLAGS"
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_PLUGIN_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_PLUGIN_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_PLUGIN_DIR}/Cargo.toml
sed -i "s@%GST_PLUGINS_DIR%@$GST_PLUGINS_DIR@" ${GST_PLUGIN_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_PLUGIN_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

0 comments on commit caea4d6

Please sign in to comment.