From 22d3dd1525f55d5dcbbda8fee179aed4005110e3 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Tue, 3 Sep 2024 17:22:57 -0700 Subject: [PATCH] Build releases for more targets (#540) --- .github/workflows/build.yaml | 109 +++++++++++++++++++++----------- bin/package | 74 +++++++++++----------- justfile | 6 ++ src/common.rs | 1 - src/error.rs | 2 +- src/subcommand/torrent/stats.rs | 2 +- src/torrent_summary.rs | 2 +- 7 files changed, 120 insertions(+), 76 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index f093055..4a3a451 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -14,50 +14,56 @@ defaults: run: shell: bash +env: + RUSTFLAGS: --deny warnings + jobs: all: name: All strategy: matrix: - os: - - macos-latest - - ubuntu-latest - - windows-latest + target: + - aarch64-apple-darwin + - aarch64-pc-windows-msvc + - aarch64-unknown-linux-musl + - arm-unknown-linux-musleabihf + - armv7-unknown-linux-musleabihf + - x86_64-apple-darwin + - x86_64-pc-windows-msvc + - x86_64-unknown-linux-musl include: - - os: ubuntu-latest - target: x86_64-unknown-linux-musl - - os: macos-latest - target: x86_64-apple-darwin - - os: windows-latest - target: x86_64-pc-windows-msvc + - target: aarch64-apple-darwin + os: macos-latest + target_rustflags: '' + - target: aarch64-pc-windows-msvc + os: windows-latest + target_rustflags: '' + - target: aarch64-unknown-linux-musl + os: ubuntu-latest + target_rustflags: '--codegen linker=aarch64-linux-gnu-gcc' + - target: arm-unknown-linux-musleabihf + os: ubuntu-latest + target_rustflags: '--codegen linker=arm-linux-gnueabihf-gcc' + - target: armv7-unknown-linux-musleabihf + os: ubuntu-latest + target_rustflags: '--codegen linker=arm-linux-gnueabihf-gcc' + - target: x86_64-apple-darwin + os: macos-latest + target_rustflags: '' + - target: x86_64-pc-windows-msvc + os: windows-latest + - target: x86_64-unknown-linux-musl + os: ubuntu-latest + target_rustflags: '' runs-on: ${{matrix.os}} - env: - RUSTFLAGS: --deny warnings - steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 with: fetch-depth: 0 - # An issue with BSD Tar causes sporadic failures on macOS. - # c.f https://github.com/actions/cache/issues/403 - - name: Install GNU Tar - if: matrix.os == 'macos-latest' - run: | - brew install gnu-tar - echo /usr/local/opt/gnu-tar/libexec/gnubin > $GITHUB_PATH - - - name: Install Rust Toolchain Components - uses: actions-rs/toolchain@v1 - with: - components: clippy, rustfmt - override: true - target: ${{ matrix.target }} - toolchain: stable - - uses: Swatinem/rust-cache@v2 - name: Info @@ -76,7 +82,7 @@ jobs: run: cargo clippy --all-targets --all-features - name: Lint - if: matrix.os == 'macos-latest' + if: matrix.target == 'x86_64-apple-darwin' run: | brew install ripgrep ./bin/lint @@ -104,28 +110,59 @@ jobs: mdbook build book --dest-dir ../www/book - name: Record Git Revision - if: github.ref == 'refs/heads/master' && matrix.os == 'ubuntu-latest' + if: github.ref == 'refs/heads/master' && matrix.os == 'x86_64-unknown-linux-musl' run: git rev-parse --verify HEAD > www/head.txt - name: Deploy Pages uses: peaceiris/actions-gh-pages@v3 - if: github.ref == 'refs/heads/master' && matrix.os == 'ubuntu-latest' + if: github.ref == 'refs/heads/master' && matrix.os == 'x86_64-unknown-linux-musl' with: github_token: ${{secrets.GITHUB_TOKEN}} publish_branch: gh-pages publish_dir: ./www + - name: Install AArch64 Toolchain + if: ${{ matrix.target == 'aarch64-unknown-linux-musl' }} + run: | + sudo apt-get update + sudo apt-get install gcc-aarch64-linux-gnu libc6-dev-i386 + + - name: Install ARM Toolchain + if: ${{ matrix.target == 'arm-unknown-linux-musleabihf' || matrix.target == 'armv7-unknown-linux-musleabihf' }} + run: | + sudo apt-get update + sudo apt-get install gcc-arm-linux-gnueabihf + + - name: Install AArch64 Toolchain (Windows) + if: ${{ matrix.target == 'aarch64-pc-windows-msvc' }} + run: | + rustup target add aarch64-pc-windows-msvc + + - name: Release Type + id: release-type + run: | + if [[ ${{ github.ref }} =~ ^refs/tags/v[0-9]+[.][0-9]+[.][0-9]+$ ]]; then + echo value=release >> $GITHUB_OUTPUT + else + echo value=prerelease >> $GITHUB_OUTPUT + fi + - name: Package id: package if: startsWith(github.ref, 'refs/tags/') - run: ./bin/package ${{github.ref}} ${{matrix.os}} ${{matrix.target}} + env: + TARGET: ${{ matrix.target }} + REF: ${{ github.ref }} + OS: ${{ matrix.os }} + TARGET_RUSTFLAGS: ${{ matrix.target_rustflags }} + run: ./bin/package - name: Publish Release Archive - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2.0.8 if: startsWith(github.ref, 'refs/tags/') with: draft: false files: ${{steps.package.outputs.archive}} - prerelease: ${{ ! startsWith(github.ref, 'refs/tags/v') }} + prerelease: ${{ steps.release-type.outputs.value == 'prerelease' }} env: GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/bin/package b/bin/package index 78e6b07..523244a 100755 --- a/bin/package +++ b/bin/package @@ -2,77 +2,79 @@ set -euxo pipefail -version=${1#"refs/tags/"} -os=$2 -target=$3 -src=`pwd` -dist=$src/target/dist -bin=imdl +VERSION=${REF#"refs/tags/"} +DIST=`pwd`/target/dist -echo "Packaging $bin $version for $target..." +echo "Packaging imdl $VERSION for $TARGET..." test -f Cargo.lock || cargo generate-lockfile -echo "Building $bin..." +echo "Installing rust toolchain for $TARGET..." +rustup target add $TARGET -case $os in +echo "Building imdl..." + +case $OS in ubuntu-latest) sudo apt install help2man musl-tools ;; - macos-latest) - brew install help2man - ;; - windows-latest) - ;; esac -RUSTFLAGS='--deny warnings --codegen target-feature=+crt-static' \ - cargo build --bin $bin --target $target --release -executable=target/$target/release/$bin +RUSTFLAGS="--deny warnings --codegen target-feature=+crt-static $TARGET_RUSTFLAGS" \ + cargo build --bin imdl --target $TARGET --release +EXECUTABLE=target/$TARGET/release/imdl + +if [[ $OS == windows-2016 ]]; then + EXECUTABLE=$EXECUTABLE.exe +fi + +echo "Building debug build" +cargo build +DEBUG_EXECUTABLE=target/debug/imdl -if [[ $os == windows-2016 ]]; then - executable=$executable.exe +if [[ $OS == windows-2016 ]]; then + DEBUG_EXECUTABLE=$DEBUG_EXECUTABLE.exe fi echo "Building completions..." -cargo run --package gen -- --bin $executable completion-scripts +cargo run --package gen -- --bin $DEBUG_EXECUTABLE completion-scripts echo "Generating readme..." -cargo run --package gen -- --bin $executable readme +cargo run --package gen -- --bin $DEBUG_EXECUTABLE readme echo "Copying static files..." -mkdir $dist +mkdir -p $DIST cp -r \ - $executable \ + $EXECUTABLE \ CONTRIBUTING \ Cargo.lock \ Cargo.toml \ LICENSE \ - $dist + $DIST echo "Copying generated files..." cp -r \ target/gen/README.md \ target/gen/completions \ - $dist + $DIST -if [[ $os != windows-latest ]]; then +if [[ $OS != windows-latest ]]; then echo "Building man pages..." - cargo run --package gen -- --bin $executable man - cp -r target/gen/man $dist/man + cargo run --package gen -- --bin $DEBUG_EXECUTABLE man + cp -r target/gen/man $DIST/man fi -cd $dist +cd $DIST echo "Creating release archive..." -case $os in +case $OS in ubuntu-latest | macos-latest) - archive=$dist/$bin-$version-$target.tar.gz - tar czf $archive * - echo "::set-output name=archive::$archive" + ARCHIVE=$DIST/imdl-$VERSION-$TARGET.tar.gz + tar czf $ARCHIVE * + echo "archive=$ARCHIVE" >> $GITHUB_OUTPUT ;; windows-latest) - archive=$dist/$bin-$version-$target.zip - 7z a $archive * - echo "::set-output name=archive::`pwd -W`/$bin-$version-$target.zip" + ARCHIVE=$DIST/imdl-$VERSION-$TARGET.zip + 7z a $ARCHIVE * + echo "archive=`pwd -W`/imdl-$VERSION-$TARGET.zip" >> $GITHUB_OUTPUT ;; esac diff --git a/justfile b/justfile index 5fbd040..450e737 100644 --- a/justfile +++ b/justfile @@ -138,3 +138,9 @@ get-beps: build-image: podman build -t imdl . podman run imdl + +test-release: + -git tag -d test-release + -git push origin :test-release + git tag test-release + git push origin test-release diff --git a/src/common.rs b/src/common.rs index 23c2b78..0f1e193 100644 --- a/src/common.rs +++ b/src/common.rs @@ -20,7 +20,6 @@ pub(crate) use std::{ string::FromUtf8Error, sync::{mpsc::channel, Once}, time::{Duration, SystemTime, SystemTimeError}, - usize, }; // dependencies diff --git a/src/error.rs b/src/error.rs index c783aea..3136fcb 100644 --- a/src/error.rs +++ b/src/error.rs @@ -102,7 +102,7 @@ pub(crate) enum Error { #[snafu(display( "Piece length `{}` too large. The maximum supported piece length is {}.", bytes, - Bytes(u32::max_value().into()) + Bytes(u32::MAX.into()) ))] PieceLengthTooLarge { bytes: Bytes, diff --git a/src/subcommand/torrent/stats.rs b/src/subcommand/torrent/stats.rs index ce90e55..ae68326 100644 --- a/src/subcommand/torrent/stats.rs +++ b/src/subcommand/torrent/stats.rs @@ -59,7 +59,7 @@ impl Stats { .sort_by_file_name(Ord::cmp) .build() { - if extractor.torrents >= self.limit.unwrap_or(u64::max_value()) { + if extractor.torrents >= self.limit.unwrap_or(u64::MAX) { break; } diff --git a/src/torrent_summary.rs b/src/torrent_summary.rs index acf654b..ddbf746 100644 --- a/src/torrent_summary.rs +++ b/src/torrent_summary.rs @@ -85,7 +85,7 @@ impl TorrentSummary { Utc .timestamp_opt( creation_date - .min(i64::max_value() as u64) + .min(i64::MAX as u64) .try_into() .invariant_unwrap("min with i64 is always valid i64"), 0,