From 61e9baab530356ade1c78585c17b3bc45ee8e492 Mon Sep 17 00:00:00 2001 From: George Hilliard Date: Wed, 9 Dec 2020 00:33:35 -0600 Subject: [PATCH] Unify cross-build workflows using a matrix --- .cargo/config | 10 +++ .github/workflows/build.yaml | 162 +++++++++-------------------------- 2 files changed, 52 insertions(+), 120 deletions(-) diff --git a/.cargo/config b/.cargo/config index ac2b23f..2282ebe 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,2 +1,12 @@ [target.x86_64-pc-windows-msvc] rustflags = ["-C", "target-feature=+crt-static"] + +# TODO not good as a default +[target.armv7-unknown-linux-gnueabihf] +linker = "arm-linux-gnueabihf-gcc" + +[target.aarch64-unknown-linux-gnu] +linker = "aarch64-linux-gnu-gcc" + +[target.i686-unknown-linux-gnu] +linker = "i686-linux-gnu-gcc" diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 18e8b84..25e36a5 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -3,7 +3,7 @@ name: CI on: [push, pull_request] jobs: - builds: + native: name: build runs-on: ${{ matrix.os }} strategy: @@ -55,143 +55,65 @@ jobs: with: name: release-${{ matrix.os }} path: "target/release/neolink*" - armhfbuild: - name: build-armhf + cross: + name: cross runs-on: ubuntu-latest container: "node:current-buster-slim" - steps: - - uses: actions/checkout@v2 - - name: Install basic tools - run: | - apt-get update - apt-get install --assume-yes --no-install-recommends sudo curl ca-certificates build-essential - - name: Add armhf as a foreign architecture - run: | - sudo dpkg --add-architecture armhf - - name: Install cross compile tools - run: | - sudo apt-get update - sudo apt-get install --assume-yes --no-install-recommends gcc-arm-linux-gnueabihf - - name: Install armhf gstreamer - run: | - sudo apt-get update - sudo apt-get install --assume-yes --no-install-recommends \ - libgstrtspserver-1.0-dev:armhf \ - libgstreamer1.0-dev:armhf \ - libgtk2.0-dev:armhf - - name: Install rustup armv7 - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true + strategy: + fail-fast: false + matrix: + # Everyone has a slightly different screwball naming scheme; + # Rust uses the target triple, GCC generally targets a family + # with a specific prefix, and dpkg's arch does its own thing + include: + - arch: armhf target: armv7-unknown-linux-gnueabihf - - name: Build armfh - uses: actions-rs/cargo@v1 - with: - command: build - args: --release --all-features --target=armv7-unknown-linux-gnueabihf - env: - CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER: arm-linux-gnueabihf-gcc - CC_armv7_unknown_linux_gnueabihf: arm-linux-gnueabihf-gcc - CXX_armv7_unknown_linux_gnueabihf: arm-linux-gnueabihf-g++ - PKG_CONFIG_ALLOW_CROSS: 1 - PKG_CONFIG_PATH: /usr/lib/arm-linux-gnueabihf/pkgconfig:/usr/share/pkgconfig/ - PKG_CONFIG_LIBDIR: /usr/lib/arm-linux-gnueabihf/pkgconfig:/usr/share/pkgconfig/ - - uses: actions/upload-artifact@v2 - with: - name: release-armhf-buster - path: "target/armv7-unknown-linux-gnueabihf/release/neolink*" - - arm64build: - name: build-arm64 - runs-on: ubuntu-latest - container: "node:current-buster-slim" - steps: - - uses: actions/checkout@v2 - - name: Install basic tools - run: | - apt-get update - apt-get install --assume-yes --no-install-recommends sudo curl ca-certificates build-essential - - name: Add arm64 as a foreign architecture - run: | - sudo dpkg --add-architecture arm64 - - name: Install cross compile tools - run: | - sudo apt-get update - sudo apt-get install --assume-yes --no-install-recommends gcc-aarch64-linux-gnu - - name: Install arm64 gstreamer - run: | - sudo apt-get update - sudo apt-get install --assume-yes --no-install-recommends \ - libgstrtspserver-1.0-dev:arm64 \ - libgstreamer1.0-dev:arm64 \ - libgtk2.0-dev:arm64 - - name: Install rustup arm64 - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true + gcc: arm-linux-gnueabihf + pkgconfig: arm-linux-gnueabihf + - arch: arm64 target: aarch64-unknown-linux-gnu - - name: Build arm64 - uses: actions-rs/cargo@v1 - with: - command: build - args: --release --all-features --target=aarch64-unknown-linux-gnu - env: - CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc - CC_aarch64_unknown_linux_gnu: aarch64-linux-gnu-gcc - CXX_aarch64_unknown_linux_gnu: aarch64-linux-gnu-g++ - PKG_CONFIG_ALLOW_CROSS: 1 - PKG_CONFIG_PATH: /usr/lib/aarch64-linux-gnu/pkgconfig:/usr/share/pkgconfig/ - PKG_CONFIG_LIBDIR: /usr/lib/aarch64-linux-gnu/pkgconfig:/usr/share/pkgconfig/ - - uses: actions/upload-artifact@v2 - with: - name: release-arm64-buster - path: "target/aarch64-unknown-linux-gnu/release/neolink*" - - i386build: - name: build-i386 - runs-on: ubuntu-latest - container: "node:current-buster-slim" + gcc: aarch64-linux-gnu + pkgconfig: aarch64-linux-gnu + - arch: i386 + target: i686-unknown-linux-gnu + gcc: i686-linux-gnu + # on i686, the pkgconfig path doesn't match the prefix! + pkgconfig: i386-linux-gnu steps: - uses: actions/checkout@v2 - name: Install basic tools run: | apt-get update - apt-get install --assume-yes --no-install-recommends sudo curl ca-certificates build-essential - - name: Add arm64 as a foreign architecture + apt-get install --assume-yes --no-install-recommends curl ca-certificates + - name: Install ${{ matrix.arch }} cross compiler and gstreamer + id: setup run: | - sudo dpkg --add-architecture i386 - - name: Install cross compile tools - run: | - sudo apt-get update - sudo apt-get install --assume-yes --no-install-recommends gcc-i686-linux-gnu - - name: Install i386 gstreamer - run: | - sudo apt-get update - sudo apt-get install --assume-yes --no-install-recommends \ - libgstrtspserver-1.0-dev:i386 \ - libgstreamer1.0-dev:i386 \ - libgtk2.0-dev:i386 - - name: Install rustup i386 + dpkg --add-architecture ${{ matrix.arch }} + apt-get update + apt-get install --assume-yes --no-install-recommends \ + build-essential \ + gcc-${{ matrix.gcc }} \ + libgstrtspserver-1.0-dev:${{ matrix.arch }} \ + libgstreamer1.0-dev:${{ matrix.arch }} \ + libgtk2.0-dev:${{ matrix.arch }} \ + libglib2.0-dev:${{ matrix.arch }} + - name: Install ${{ matrix.arch }} Rust toolchain uses: actions-rs/toolchain@v1 with: toolchain: stable override: true - target: i686-unknown-linux-gnu - - name: Build i386 + target: ${{ matrix.target }} + profile: minimal + - name: Build uses: actions-rs/cargo@v1 with: command: build - args: --release --all-features --target=i686-unknown-linux-gnu + args: --release --all-features --target=${{ matrix.target }} env: - CARGO_TARGET_I686_UNKNOWN_LINUX_GNU_LINKER: i686-linux-gnu-gcc - CC_i686_unknown_linux_gnu: i686-linux-gnu-gcc - CXX_i686_unknown_linux_gnu: i686-linux-gnu-g++ + # Retarget pkg-config as described in https://www.freedesktop.org/wiki/Software/pkg-config/CrossCompileProposal/ PKG_CONFIG_ALLOW_CROSS: 1 - PKG_CONFIG_PATH: /usr/lib/i386-linux-gnu/pkgconfig:/usr/share/pkgconfig/ - PKG_CONFIG_LIBDIR: /usr/lib/i386-linux-gnu/pkgconfig:/usr/share/pkgconfig/ + PKG_CONFIG_LIBDIR: /usr/lib/${{ matrix.pkgconfig }}/pkgconfig - uses: actions/upload-artifact@v2 with: - name: release-i386-buster - path: "target/i686-unknown-linux-gnu/release/neolink*" + name: release-${{ matrix.arch }}-buster + path: "target/${{ matrix.target }}/release/neolink*"