Skip to content

Commit

Permalink
CI: build for many platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
ahihi committed Aug 2, 2024
1 parent 11d2f9e commit c40ca4e
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 36 deletions.
61 changes: 25 additions & 36 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,73 +11,62 @@ jobs:
build:
name: build

runs-on: ${{ matrix.os }}
runs-on: ${{ matrix.platform.os }}

strategy:
fail-fast: false
matrix:
target:
- x86_64-unknown-linux-gnu
# - x86_64-unknown-linux-musl
# - aarch64-unknown-linux-gnu
# - aarch64-unknown-linux-musl
- x86_64-pc-windows-msvc
# - i686-pc-windows-msvc
- x86_64-apple-darwin
# - aarch64-apple-darwin

include:
platform:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
target-apt-arch: amd64
# - target: x86_64-unknown-linux-musl
# os: ubuntu-latest
# target-apt-arch: amd64
# - target: aarch64-unknown-linux-gnu
# os: ubuntu-latest
# target-apt-arch: arm64
# - target: aarch64-unknown-linux-musl
# os: ubuntu-latest
# target-apt-arch: arm64
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
target-apt-arch: arm64
- target: x86_64-pc-windows-msvc
os: windows-latest
# - target: i686-pc-windows-msvc
# os: windows-latest
- target: i686-pc-windows-msvc
os: windows-latest
- target: x86_64-apple-darwin
os: macos-latest
# - target: aarch64-apple-darwin
# os: macos-latest
- target: aarch64-apple-darwin
os: macos-latest

env:
PROJECT_NAME: autocrap
CARGO_BUILD_TARGET: ${{ matrix.target }}
CARGO_BUILD_TARGET: ${{ matrix.platform.target }}
CARGO_TERM_COLOR: always
MACOSX_DEPLOYMENT_TARGET: 10.12
RUSTFLAGS:

steps:
- name: checkout
uses: actions/checkout@v4

- name: cache apt packages
if: startsWith(matrix.os, 'ubuntu')
if: startsWith(matrix.platform.os, 'ubuntu')
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: libasound2-dev
version: 1.0

- name: setup rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: build
uses: houseabsolute/actions-rust-cross@v0
with:
target: ${{ matrix.target }}
rustflags:
command: build
target: ${{ matrix.platform.target }}
args: "--release --verbose"
strip: true

- name: build
run: cargo build --verbose
- name: prepare artifact
run: |
cp -av config 'target/${{ matrix.platform.target }}/release/config'
- name: upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.PROJECT_NAME }}-${{ matrix.target }}
name: ${{ env.PROJECT_NAME }}-${{ matrix.platform.target }}
path: |
target/${{ matrix.target }}/debug/${{ env.PROJECT_NAME }}
target/${{ matrix.target }}/debug/${{ env.PROJECT_NAME }}.exe
target/${{ matrix.platform.target }}/release/config
target/${{ matrix.platform.target }}/release/${{ env.PROJECT_NAME }}
target/${{ matrix.platform.target }}/release/${{ env.PROJECT_NAME }}.exe
87 changes: 87 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# inspired by https://github.com/shssoichiro/oxipng/blob/15ecc9ed00199f1fbfe0989d67a43ff3e6faff6a/.github/workflows/deploy.yml
name: release

on:
push:
tags:
- 'v*.*.*'

permissions:
actions: read
contents: write

jobs:
release:
name: release

runs-on: ubuntu-latest

# Prevent job from running on forks
if: ${{ !github.event.repository.fork }}

strategy:
matrix:
platform:
- target: x86_64-unknown-linux-gnu
name: linux-x86_64
- target: aarch64-unknown-linux-gnu
name: linux-aarch64
- target: x86_64-pc-windows-msvc
name: windows-x86_64
- target: i686-pc-windows-msvc
name: windows-i686
- target: x86_64-apple-darwin
name: macos-x86_64
- target: aarch64-apple-darwin
name: macos-aarch64

env:
PROJECT_NAME: autocrap

steps:
- name: Checkout source
uses: actions/checkout@v4

- name: get version
id: meta
run: |
version=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.name == "'"$PROJECT_NAME"'").version')
echo "version=$version" >> "$GITHUB_OUTPUT"
- name: retrieve ${{ matrix.platform.target }} binary
uses: dawidd6/action-download-artifact@v6
with:
workflow: build.yml
commit: ${{ env.GITHUB_SHA }}
name: ${{ env.PROJECT_NAME }}-${{ matrix.platform.target }}
path: target

- name: build archives
working-directory: target
run: |
ARCHIVE_NAME='${{ env.PROJECT_NAME }}-${{ steps.meta.outputs.version }}-${{ matrix.platform.name }}'
echo "ARCHIVE_NAME=$ARCHIVE_NAME"
mkdir "$ARCHIVE_NAME"
case '${{ matrix.platform.target }}' in
*-windows-*)
cp -a "${PROJECT_NAME}.exe" "$ARCHIVE_NAME"
zip "${ARCHIVE_NAME}.zip" "$ARCHIVE_NAME"/*
;;
*)
cp -a "$PROJECT_NAME" "$ARCHIVE_NAME"
# fix permissions https://github.com/actions/toolkit/issues/1722
chmod ugo+x "$ARCHIVE_NAME"/"$PROJECT_NAME"
tar czvf "${ARCHIVE_NAME}.tar.gz" "$ARCHIVE_NAME"/*
;;
esac
- name: create release
uses: softprops/action-gh-release@v2
with:
name: v${{ steps.meta.outputs.version }}
# body_path: RELEASE_NOTES.txt
files: |
target/*.zip
target/*.tar.gz
13 changes: 13 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[target.x86_64-unknown-linux-gnu]
pre-build = [
"export PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu=/usr/lib/x86_64-linux-gnu/pkgconfig",
"dpkg --add-architecture $CROSS_DEB_ARCH",
"apt-get update && apt-get install --assume-yes libasound2-dev:$CROSS_DEB_ARCH"
]

[target.aarch64-unknown-linux-gnu]
pre-build = [
"export PKG_CONFIG_LIBDIR_aarch64_unknown_linux_gnu=/usr/lib/aarch64-linux-gnu/pkgconfig",
"dpkg --add-architecture $CROSS_DEB_ARCH",
"apt-get update && apt-get install --assume-yes libasound2-dev:$CROSS_DEB_ARCH"
]

0 comments on commit c40ca4e

Please sign in to comment.