Skip to content

Commit

Permalink
New attempt
Browse files Browse the repository at this point in the history
  • Loading branch information
kingosticks committed Sep 12, 2023
1 parent 2c6cc62 commit 15763b0
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 79 deletions.
89 changes: 58 additions & 31 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,65 @@ jobs:
strategy:
fail-fast: false
runs-on: ubuntu-20.04
container: ghcr.io/mopidy/gst-plugin-spotify-deb:latest
container: ghcr.io/mopidy/gst-plugin-spotify-build:latest
env:
GST_PLUGIN: gst-plugin-spotify
RUST_TARGET: arm-unknown-linux-gnueabihf
LINKER_TARGET: arm-linux-gnueabihf
steps:
- name: Install sudo package
run: apt update && apt install sudo
- name: Checkout repo
uses: actions/checkout@v4

- name: add armhf
run: sudo dpkg --add-architecture armhf
- name: Install Rust
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable
targets: ${{ env.RUST_TARGET }}

- name: install deps
run: >
sudo apt-get update &&
DEBIAN_FRONTEND=noninteractive
apt-get install --no-install-recommends
clang curl ca-certificates debhelper git pkg-config
gcc-arm-linux-gnueabihf
libgstreamer-plugins-base1.0-dev:armhf &&
rm -rf /var/lib/apt/lists/*
- name: Install cargo deb
run: cargo install cargo-deb

- name: Checkout repo
uses: actions/checkout@v3

- name: Copy home stuff to stupid github home
run: cp -rT /root $HOME

- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2

- name: Build deb
run: ./entrypoint.sh armhf

- name: Upload deb
uses: actions/upload-artifact@v3
with:
name: gst-plugin-spotify.deb
path: /release/*.deb
- name: Checkout gst-plugins-rs
run: |
GST_GIT_REPO=https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
GST_GIT_BRANCH=main
git clone --depth 1 -b $GST_GIT_BRANCH $GST_GIT_REPO
GST_SRC=$(basename $GST_GIT_REPO .git)
cp $GST_SRC/audio/spotify/Cargo.toml Cargo.toml.orig
echo "GST_SRC=$GST_SRC"
echo "GST_SRC=$GST_SRC" >> $GITHUB_ENV
- name: Build gst-plugins-rs
run: |
export PKG_CONFIG_ALLOW_CROSS=1
export PKG_CONFIG_PATH="/usr/lib/${{ env.LINKER_TARGET }}/pkgconfig"
RPI_STUFF="/rpi-tools/arm-bcm2708/${{ env.LINKER_TARGET }}"
RPI_SYSROOT="$RPI_STUFF/${{ env.LINKER_TARGET }}/sysroot"
RPI_LINKER="$RPI_STUFF/bin/${{ env.LINKER_TARGET }}-gcc"
export RUSTFLAGS="-C linker=$RPI_LINKER -L$RPI_SYSROOT/lib -L$RPI_SYSROOT/usr/lib"
cd ${{ env.GST_SRC }}
cargo build --target=${{ env.RUST_TARGET }} --package ${{ env.GST_PLUGIN }} --release --config 'profile.release.strip = true'
- name: Prep deb control
run: |
export PKG_CONFIG_PATH="/usr/lib/${{ env.LINKER_TARGET }}/pkgconfig"
GST_PLUGINS_DIR=$(pkg-config --variable=pluginsdir gstreamer-1.0)
cat Cargo.toml.orig Cargo.toml.deb | sed "s@%GST_PLUGINS_DIR%@$GST_PLUGINS_DIR@" > ${{ env.GST_SRC }}/audio/spotify/Cargo.toml
- name: Build deb
run: |
cd ${{ env.GST_SRC }}
cargo deb --target=${{ env.RUST_TARGET }} --package ${{ env.GST_PLUGIN }} --no-build
DEB_FILE=${{ env.GST_SRC }}/$(find target/${{ env.RUST_TARGET }}/debian/gst-plugin-spotify_*.deb)
DEB_NAME=$(basename $DEB_FILE .deb)
echo "DEB_FILE=$DEB_FILE" >> $GITHUB_ENV
echo "DEB_NAME=$DEB_NAME" >> $GITHUB_ENV
- name: Check deb
run: dpkg-deb --field ${{ env.DEB_FILE }} Package Architecture Version Installed-Size

- name: Upload deb
uses: actions/upload-artifact@v3
with:
name: ${{ env.DEB_NAME }}
path: ${{ env.DEB_FILE }}
File renamed without changes.
8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM debian:bullseye-slim

LABEL org.opencontainers.image.source https://github.com/mopidy/gst-plugin-spotify-build

RUN dpkg --add-architecture armhf

RUN apt-get update \
Expand All @@ -9,13 +11,17 @@ RUN apt-get update \
debhelper \
git \
pkg-config \
# Rpi
gcc-arm-linux-gnueabihf \
libgstreamer-plugins-base1.0-dev:armhf \
&& rm -rf /var/lib/apt/lists/*

ENV RPI_TOOLS_DIR=/rpi-tools
RUN git clone --depth=1 https://github.com/raspberrypi/tools $RPI_TOOLS_DIR && rm -rf $RPI_TOOLS_DIR/.git
ARG RPI_TOOLS=$RPI_TOOLS_DIR/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf

RUN ln -s /gst-plugins-rs/target /target
RUN mkdir -p ~/.cargo/
RUN touch ~/.cargo/config
RUN echo "[target.arm-unknown-linux-gnueabihf]\nobjcopy = { path = \"$RPI_TOOLS-objcopy\" }\nstrip = { path = \"$RPI_TOOLS-strip\" }" > ~/.cargo/config

COPY VERSION /
9 changes: 3 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
REPO = ghcr.io/mopidy
IMAGE = gst-plugins-rs-build
IMAGE = gst-plugin-spotify-build
VERSION = $(shell cat VERSION)

.PHONY: build release git-release docker-release

build: docker-build build-armhf build-x86_64

build-armhf:
docker run -v $(pwd)/../gst-plugins-rs:/gst-plugins-rs:z -v $(pwd):/gst-plugins-rs-build:z ${REPO}/${IMAGE}:${VERSION} /bin/bash /gst-plugins-rs-build/entrypoint.sh armhf
docker run -v ./../gst-plugins-rs:/gst-plugins-rs:z -v .:/gst-plugin-spotify-build:z ${REPO}/${IMAGE}:${VERSION} /bin/bash /gst-plugin-spotify-build/entrypoint.sh armhf

build-x86_64:
docker build -tag ${REPO}/cross-rs-gst:x86_64 --file docker/x86_64/Dockerfile .

docker-build:
docker build --tag ${REPO}/${IMAGE} --file Dockerfile .
docker build --tag ${REPO}/${IMAGE}:${VERSION} --file Dockerfile .

release: git-release docker-release

Expand Down
73 changes: 32 additions & 41 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
#!/bin/sh

BUILD_SRC=/gst-plugin-spotify-build
GST_PLUGIN=gst-plugin-spotify

arch="${1}"

# 1. Install Rust stuff
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
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.

case $arch in
armhf)
export BUILD_TARGET=arm-unknown-linux-gnueabihf
export RUST_TARGET=arm-unknown-linux-gnueabihf
export LINKER_TARGET=arm-linux-gnueabihf

export PKG_CONFIG_ALLOW_CROSS=1
export PKG_CONFIG_PATH=/usr/lib/$LINKER_TARGET/pkgconfig
RPI_SYSROOT="$RPI_TOOLS_DIR/arm-bcm2708/$LINKER_TARGET/$LINKER_TARGET/sysroot"
TARGET_TOOLS="$RPI_TOOLS_DIR/arm-bcm2708/$LINKER_TARGET/bin"
TARGET_SYSROOT="$RPI_TOOLS_DIR/arm-bcm2708/$LINKER_TARGET/$LINKER_TARGET/sysroot"
export RUSTFLAGS="-C linker=$TARGET_TOOLS/$LINKER_TARGET-gcc -L$TARGET_SYSROOT/lib -L$TARGET_SYSROOT/usr/lib"
export RUSTFLAGS="-C linker=$TARGET_TOOLS/$LINKER_TARGET-gcc -L$RPI_SYSROOT/lib -L$RPI_SYSROOT/usr/lib"
;;
x86_64)
export BUILD_TARGET=x86_64-unknown-linux-gnu
export RUST_TARGET=x86_64-unknown-linux-gnu
export LINKER_TARGET=x86_64-linux-gnu
TARGET_TOOLS=/usr/bin
;;
Expand All @@ -23,55 +36,33 @@ case $arch in
exit 1
;;
esac

export GST_GIT_REPO=https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
export GST_GIT_BRANCH=main
export GST_PLUGIN=gst-plugin-spotify

## 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.

# 1. Install Rust stuff
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"
rustup target add $BUILD_TARGET
cargo install cargo-deb

mkdir -p .cargo
cat >"${HOME}"/.cargo/config <<EOF
[target.$BUILD_TARGET]
#linker = '$TARGET_TOOLS/$LINKER_TARGET-gcc'
strip = { path = '$TARGET_TOOLS/$LINKER_TARGET-strip' }
objcopy = { path = '$TARGET_TOOLS/$LINKER_TARGET-objcopy' }
EOF
rustup target add $RUST_TARGET

# 2. Checkout source if required
[ ! -d "/gst-plugins-rs" ] && git clone --depth 1 -b $GST_GIT_BRANCH $GST_GIT_REPO
cd gst-plugins-rs
GST_GIT_REPO=https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
GST_GIT_BRANCH=main
GST_SRC=$(basename $GST_GIT_REPO .git)
[ ! -d "/$GST_SRC" ] && git clone --depth 1 -b $GST_GIT_BRANCH $GST_GIT_REPO

# 3. Backup the original .toml file
[ ! -f "audio/spotify/Cargo.toml.orig" ] && cp audio/spotify/Cargo.toml audio/spotify/Cargo.toml.orig
[ ! -f "Cargo.toml.orig" ] && cp $GST_SRC/audio/spotify/Cargo.toml Cargo.toml.orig

# 4. Build GStreamer plugin
cargo build --target=$BUILD_TARGET --package $GST_PLUGIN --release --config 'profile.release.strip = true'
cd $GST_SRC
cargo build --target=$RUST_TARGET --package $GST_PLUGIN --release --config 'profile.release.strip = true'

# 5. Create Debian package
LIB_FILE=/target/$BUILD_TARGET/release/libgstspotify.so

cat audio/spotify/Cargo.toml.orig /gst-plugins-rs-build/Cargo-deb.toml > audio/spotify/Cargo.toml
#from gettext-base package ?
#envsubst <audio/spotify/Cargo.toml >audio/spotify/Cargo.toml

sed -i "s@%GST_PLUGINS_DIR%@$(pkg-config --variable=pluginsdir gstreamer-1.0)@" audio/spotify/Cargo.toml
cd $BUILD_SRC
export GST_PLUGINS_DIR=$(pkg-config --variable=pluginsdir gstreamer-1.0)
cat Cargo.toml.orig Cargo-deb.toml | \
sed "s@%GST_PLUGINS_DIR%@$GST_PLUGINS_DIR@" > $GST_SRC/audio/spotify/Cargo.toml

# Got to specify target despite no-build else cargo-deb looks in the workspace for the asset, see comment at top.

#WITH_DEBUG=" --separate-debug-symbols"
cargo deb --target=$BUILD_TARGET -p $GST_PLUGIN --no-build $WITH_DEBUG -v
cd $GST_SRC
cargo deb --target=$RUST_TARGET -p $GST_PLUGIN --no-build $WITH_DEBUG -v

# Sanity check
DEB_FILE=$(find /target/$BUILD_TARGET/debian/gst-plugin-spotify_*.deb)
DEB_FILE=$(find target/$RUST_TARGET/debian/gst-plugin-spotify_*.deb)
dpkg-deb --field $DEB_FILE Package Architecture Version Installed-Size
#echo "DEB_FILE=$DEB_FILE" >> $GITHUB_OUTPUT

0 comments on commit 15763b0

Please sign in to comment.