From 0dc645e005e56286dd408d41f2a6bfb09c0c7a1a Mon Sep 17 00:00:00 2001 From: Michael Herger Date: Mon, 17 Oct 2022 14:23:01 +0200 Subject: [PATCH] Rework build workflow * Add Cargo caching * add experimental support for cross compilation * update some actions * fix the macOS runner version --- .github/actions/xbuild-spotty/action.yml | 56 +++++++++++++++++ .github/workflows/build-spotty.yml | 76 +++++++++++++++++++++--- Cargo.toml | 1 + 3 files changed, 125 insertions(+), 8 deletions(-) create mode 100644 .github/actions/xbuild-spotty/action.yml diff --git a/.github/actions/xbuild-spotty/action.yml b/.github/actions/xbuild-spotty/action.yml new file mode 100644 index 000000000..20dbfb0a1 --- /dev/null +++ b/.github/actions/xbuild-spotty/action.yml @@ -0,0 +1,56 @@ +name: 'Cross-Build Spotty' +description: 'Build Spotty for any Linux platform' + +inputs: + binary-name: + description: 'The name of the resulting artifact' + default: 'spotty' + client-id: + description: 'The Client ID to bake in to the binary' + required: true + target-triple: + description: 'The Rust Target Triple' + required: true + +runs: + using: "composite" + + steps: + - name: Write Build Configuration File + uses: DamianReeves/write-file-action@v1.0 + with: + path: ./src/client_id.txt + contents: ${{ inputs.client-id }} + write-mode: overwrite + + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + target: ${{ inputs.target-triple }} + override: true + + - name: Get Rustc version + id: get-rustc-version + run: echo "::set-output name=version::$(rustc -V)" + shell: bash + + - name: Cache Rust dependencies + uses: actions/cache@v3 + with: + path: | + ~/.cargo/registry/index + ~/.cargo/registry/cache + ~/.cargo/git + target + key: ${{ runner.os }}-${{ steps.get-rustc-version.outputs.version }}-${{ hashFiles('Cargo.lock') }} + + - uses: actions-rs/cargo@v1 + with: + use-cross: true + command: build + args: --release --target ${{ inputs.target-triple }} + + - uses: actions/upload-artifact@v3 + with: + name: ${{ inputs.binary-name }} + path: target/${{ inputs.target-triple }}/release/spotty diff --git a/.github/workflows/build-spotty.yml b/.github/workflows/build-spotty.yml index 2f2b62160..84fb1b142 100644 --- a/.github/workflows/build-spotty.yml +++ b/.github/workflows/build-spotty.yml @@ -11,7 +11,7 @@ env: jobs: macOS: - runs-on: macos-11.0 + runs-on: macos-11 steps: - name: Install Rust @@ -20,7 +20,7 @@ jobs: toolchain: stable - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Write Build Configuration File uses: DamianReeves/write-file-action@v1.0 @@ -29,6 +29,20 @@ jobs: contents: ${{ env.KEYMASTER_CLIENT_ID }} write-mode: overwrite + - name: Get Rustc version + id: get-rustc-version + run: echo "::set-output name=version::$(rustc -V)" + + - name: Cache Rust dependencies + uses: actions/cache@v3 + with: + path: | + ~/.cargo/registry/index + ~/.cargo/registry/cache + ~/.cargo/git + target + key: ${{ runner.os }}-${{ steps.get-rustc-version.outputs.version }}-${{ hashFiles('Cargo.lock') }} + - name: Install Rust support for ARM64 & prepare environment run: | rustup target add aarch64-apple-darwin @@ -51,17 +65,18 @@ jobs: -output releases/spotty - name: Upload artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: spotty-mac path: releases/ Linux: + if: false runs-on: ubuntu-20.04 steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v3 - name: Write Build Configuration File uses: DamianReeves/write-file-action@v1.0 @@ -79,17 +94,62 @@ jobs: docker run --rm -v $PWD/target:/build -v $PWD:/src spotty-cross - name: Upload artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: spotty-linux path: releases/ - windows: + Linux_x86_64: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - uses: ./.github/actions/xbuild-spotty + with: + binary-name: spotty-x86_64 + client-id: ${{ env.KEYMASTER_CLIENT_ID }} + target-triple: x86_64-unknown-linux-musl + + Linux_ARMv6: + if: false + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - uses: ./.github/actions/xbuild-spotty + with: + binary-name: spotty-arm + client-id: ${{ env.KEYMASTER_CLIENT_ID }} + target-triple: arm-unknown-linux-musleabi + + Linux_ARMv7: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - uses: ./.github/actions/xbuild-spotty + with: + binary-name: spotty-hf + client-id: ${{ env.KEYMASTER_CLIENT_ID }} + target-triple: armv7-unknown-linux-musleabihf + + Linux_ARMv8: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - uses: ./.github/actions/xbuild-spotty + with: + binary-name: spotty-aarch64 + client-id: ${{ env.KEYMASTER_CLIENT_ID }} + target-triple: aarch64-unknown-linux-musl + + Windows: runs-on: windows-2019 steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Write Build Configuration File uses: DamianReeves/write-file-action@v1.0 @@ -102,7 +162,7 @@ jobs: run: cargo build --release - name: Upload artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: spotty.exe path: target/release/spotty.exe \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index 67ccf0aef..593fbd404 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -71,3 +71,4 @@ default = ["passthrough-decoder"] [profile.release] lto = true panic = 'abort' +strip = true