diff --git a/.github/scripts/install-dependencies.sh b/.github/scripts/install-dependencies.sh index d5325347..b41d6082 100755 --- a/.github/scripts/install-dependencies.sh +++ b/.github/scripts/install-dependencies.sh @@ -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 diff --git a/.github/scripts/setup-vars.sh b/.github/scripts/setup-vars.sh index 408ab165..3ca973b9 100755 --- a/.github/scripts/setup-vars.sh +++ b/.github/scripts/setup-vars.sh @@ -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 diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index a4ed07cd..5e92ccc0 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -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 @@ -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 @@ -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 }}