Skip to content

Commit

Permalink
Add support for armv6 (raspberry pi) to CD
Browse files Browse the repository at this point in the history
  • Loading branch information
jonkerj committed Jul 16, 2022
1 parent c1124ac commit ca4a85b
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 44 deletions.
59 changes: 39 additions & 20 deletions .github/scripts/install-dependencies.sh
Original file line number Diff line number Diff line change
@@ -1,64 +1,83 @@
#!/bin/bash

set -e
set -x

ARCH=${1} # arm, aarch64, i386, x86_64
ABI=${2} # gnu, gnueabihf
DEBARCH=${3} # i386, amd64, armhf, arm64
BUILD_TYPE=${4} # slim, default, full
ARCH=${1} # armv6, armhf, arm64
BINARCH=${2} # arm, aarch64, i386, x86_64
ABI=${3} # gnu, gnueabihf
DEBARCH=${4} # i386, amd64, armhf, arm64
BUILD_TYPE=${5} # slim, default, full

export DEBIAN_FRONTEND=noninteractive

# Native sources
cat > /etc/apt/sources.list << EOT_NATIVE
cat | sudo tee /etc/apt/sources.list > /dev/null << EOT_NATIVE
deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ focal main restricted universe multiverse
deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ focal-updates main restricted universe multiverse
deb [arch=amd64] http://security.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
EOT_NATIVE

# If building cross, cross sources
if [ "${ARCH}" != "$(uname -m)" ]; then
cat > /etc/apt/sources.list.d/cross.list << EOT_CROSS
if [ "${BINARCH}" != "$(uname -m)" ]; then
cat | sudo tee /etc/apt/sources.list.d/cross.list > /dev/null << EOT_CROSS
deb [arch=$DEBARCH] http://ports.ubuntu.com/ focal main restricted universe multiverse
deb [arch=$DEBARCH] http://ports.ubuntu.com/ focal-updates main restricted universe multiverse
deb [arch=$DEBARCH] http://ports.ubuntu.com/ focal-security main restricted universe multiverse
EOT_CROSS
else
rm -f /etc/apt/sources.list.d/cross.list
sudo rm -f /etc/apt/sources.list.d/cross.list
fi

dpkg --add-architecture ${DEBARCH}
apt-get update

# Setup magic vars for foreign packages
if [ "${ARCH}" != "$(uname -m)" ]; then
if [ "${BINARCH}" != "$(uname -m)" ]; then
if [ "${ARCH}" != "armv6" ]; then
BUILD_PKGS="gcc-${BINARCH}-linux-${ABI} libc6-${DEBARCH}-cross libc6-dev-${DEBARCH}-cross pkg-config"
else
BUILD_PKGS="curl libc6-${DEBARCH}-cross libc6-dev-${DEBARCH}-cross pkg-config"
fi
CROSS=":${DEBARCH}"
BUILD_PKGS="gcc-${ARCH}-linux-${ABI} libc6-${DEBARCH}-cross libc6-dev-${DEBARCH}-cross pkg-config"
dpkg --add-architecture ${DEBARCH}
sudo dpkg --add-architecture ${DEBARCH}
else
CROSS=""
BUILD_PKGS="gcc libc6 libc6-dev pkg-config"
fi

sudo apt-get update

# Always install all dependencies, even if we are building default or even slim
BUILDDEP_SLIM="libasound2-dev${CROSS} libssl-dev${CROSS} libpulse-dev${CROSS} libdbus-1-dev${CROSS} libssl1.1${CROSS}"
BUILDDEP_DEFAULT="libdbus-1-dev${CROSS} libdbus-1-3${CROSS} libsystemd0${CROSS} libgcrypt20${CROSS} liblzma5${CROSS} liblz4-1${CROSS} libgpg-error0${CROSS}"
BUILDDEP_DEFAULT="libdbus-1-dev${CROSS} libdbus-1-3${CROSS} libsystemd0${CROSS} libsystemd-dev${CROSS} libgcrypt20${CROSS} libgcrypt20-dev${CROSS} liblzma5${CROSS} liblzma-dev${CROSS} liblz4-1${CROSS} liblz4-dev${CROSS} libgpg-error0${CROSS} libgpg-error-dev${CROSS}"
BUILDDEP_FULL="libpulse-dev${CROSS}"

apt-get install -y \
sudo apt-get install -y \
build-essential \
${BUILD_PKGS} \
${BUILDDEP_SLIM} \
${BUILDDEP_DEFAULT} \
${BUILDDEP_FULL}

if [ "${ARCH}" == "armv6" ]; then
curl -L -o /tmp/toolchain.tar.bz2 https://toolchains.bootlin.com/downloads/releases/toolchains/armv6-eabihf/tarballs/armv6-eabihf--glibc--stable-2020.08-1.tar.bz2
sudo mkdir /opt/toolchain
sudo chown $(whoami) /opt/toolchain
tar -C /opt/toolchain --strip-components=1 -jxf /tmp/toolchain.tar.bz2
echo "/opt/toolchain/bin" >> $GITHUB_PATH
fi

# Tell rust to cross-compile
if [ "${ARCH}" != "$(uname -m)" ]; then
if [ "${BINARCH}" != "$(uname -m)" ]; then
mkdir -p ~/.cargo
if [ "${ARCH}" != "armv6" ]; then
LINKER="${BINARCH}-linux-${ABI}-gcc"
else
LINKER="arm-buildroot-linux-gnueabihf-gcc"
fi
cat >> ~/.cargo/config << EOT_CARGO
[target.${ARCH}-unknown-linux-${ABI}]
linker = "${ARCH}-linux-${ABI}-gcc"
[target.${BINARCH}-unknown-linux-${ABI}]
linker = "${LINKER}"
[target.${ARCH}-unknown-linux-${ABI}.dbus]
[target.${BINARCH}-unknown-linux-${ABI}.dbus]
rustc-link-lib = ["dbus-1", "gcrypt", "gpg-error", "lz4", "lzma", "systemd"]
EOT_CARGO
fi
8 changes: 7 additions & 1 deletion .github/scripts/setup-vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ fi

# only when cross-building on linux
if [ "${BUILD_TARGET}" == "linux" ] && [ "${ARCH}" != "$(uname -m)" ]; then
echo "RUSTFLAGS=-C linker=${BINARCH}-linux-${ABI}-gcc"
echo "PKG_CONFIG_ALLOW_CROSS=1"
echo "PKG_CONFIG_LIBDIR=/usr/lib/${BINARCH}-linux-${ABI}/pkgconfig/"
fi

# raspberry pi toolchain doesn't search in the right places automatically
if [ "${ARCH}" == "armv6" ]; then
echo "CC=arm-buildroot-linux-gnueabihf-gcc"
echo "CFLAGS=-march=armv6 -I/usr/include -I/usr/include/arm-linux-gnueabihf -L/usr/lib/arm-linux-gnueabihf" # needed for cc crate in rust-openssl's build main.rs (expando)
echo "RUSTFLAGS=-Clinker=arm-buildroot-linux-gnueabihf-gcc -L/usr/lib/arm-linux-gnueabihf"
fi
61 changes: 38 additions & 23 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,31 @@ jobs:
matrix:
build_target: [linux, macos]
artifact_type: [slim, default, full]
arch: [x86_64, armhf, arm64] # "our" name of the arch. How debian, rust and gcc call them will be set later
arch: [x86_64, armv6, armhf, arm64] # "our" name of the arch. How debian, rust and gcc call them will be set later
# remove unwanted combinations. Arm64 macos is not supported by GH right now
exclude:
- build_target: macos
arch: armv6
- build_target: macos
arch: armhf
- build_target: macos
arch: arm64
- build_target: linux
arch: armv6
artifact_type: default
- build_target: linux
arch: armv6
artifact_type: full
include:
# Setup Arch-specific defaults. Different systems use different names
- arch: x86_64
abi: gnu
binarch: x86_64
debarch: amd64
- arch: armv6
abi: gnueabihf
binarch: arm
debarch: armhf
- arch: armhf
abi: gnueabihf
binarch: arm
Expand All @@ -43,9 +55,9 @@ jobs:
- artifact_type: slim
features: '' # Slim version has no features enabled by default.
- artifact_type: 'default'
feature: 'dbus_keyring,dbus_mpris' # Default version has all extra features enabled
features: 'dbus_keyring,dbus_mpris' # Default version has all extra features enabled
- artifact_type: 'full'
feature: 'dbus_keyring,dbus_mpris' # Full version has all extra features and audio backends enabled
features: 'dbus_keyring,dbus_mpris' # Full version has all extra features and audio backends enabled
## Setup audio backends
# MacOS
- build_target: macos
Expand Down Expand Up @@ -84,24 +96,27 @@ jobs:
run: brew install awk dbus pkg-config portaudio
- name: Installing needed Ubuntu dependencies
if: matrix.build_target == 'linux'
run: sudo bash .github/scripts/install-dependencies.sh ${{ matrix.binarch }} ${{ matrix.abi }} ${{ matrix.debarch }} ${{ matrix.artifact_type }}
- name: Running cargo build
uses: actions-rs/cargo@v1
with:
command: build
toolchain: ${{ matrix.rust }}
args: --locked --release --target ${{ env.RUST_TARGET }} --no-default-features --features "${{ matrix.feature }},${{ matrix.audio_backend }}"
- name: Packaging final binary
shell: bash
run: |
cd target/${{ env.RUST_TARGET }}/release
tar czvf ${{ env.ARTIFACT_NAME}}.tar.gz spotifyd
shasum -a 512 ${{ env.ARTIFACT_NAME }}.tar.gz > ${{ env.ARTIFACT_NAME }}.sha512
- name: Releasing assets
uses: softprops/action-gh-release@v1
with:
files: |
target/${{ env.RUST_TARGET }}/release/${{ env.ARTIFACT_NAME }}.tar.gz
target/${{ env.RUST_TARGET }}/release/${{ env.ARTIFACT_NAME }}.sha512
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
.github/scripts/install-dependencies.sh ${{ matrix.arch }} ${{ matrix.binarch }} ${{ matrix.abi }} ${{ matrix.debarch }} ${{ matrix.artifact_type }}
- name: debug
uses: mxschmitt/action-tmate@v3
# - name: Running cargo build
# uses: actions-rs/cargo@v1
# with:
# command: build
# toolchain: ${{ matrix.rust }}
# args: --locked --release --target ${{ env.RUST_TARGET }} --no-default-features --features "${{ matrix.features }},${{ matrix.audio_backend }}"
# - name: Packaging final binary
# shell: bash
# run: |
# cd target/${{ env.RUST_TARGET }}/release
# tar czvf ${{ env.ARTIFACT_NAME}}.tar.gz spotifyd
# shasum -a 512 ${{ env.ARTIFACT_NAME }}.tar.gz > ${{ env.ARTIFACT_NAME }}.sha512
# - name: Releasing assets
# uses: softprops/action-gh-release@v1
# with:
# files: |
# target/${{ env.RUST_TARGET }}/release/${{ env.ARTIFACT_NAME }}.tar.gz
# target/${{ env.RUST_TARGET }}/release/${{ env.ARTIFACT_NAME }}.sha512
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit ca4a85b

Please sign in to comment.