diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1f7418f..9d4a9ec 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,73 +11,57 @@ 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 - with: - target: ${{ matrix.target }} - rustflags: - - name: build - run: cargo build --verbose + uses: houseabsolute/actions-rust-cross@v0 + with: + command: build + target: ${{ matrix.platform.target }} + args: "--release --verbose" + strip: true - 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/${{ env.PROJECT_NAME }} + target/${{ matrix.platform.target }}/release/${{ env.PROJECT_NAME }}.exe diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..acdde1e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,89 @@ +# 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" + + cp -a ../config "$ARCHIVE_NAME/config" + + 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 diff --git a/Cross.toml b/Cross.toml new file mode 100644 index 0000000..2896af4 --- /dev/null +++ b/Cross.toml @@ -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" +]