Skip to content

Commit

Permalink
Build releases for more targets (#540)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Sep 4, 2024
1 parent e2a4815 commit 22d3dd1
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 76 deletions.
109 changes: 73 additions & 36 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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}}
74 changes: 38 additions & 36 deletions bin/package
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub(crate) use std::{
string::FromUtf8Error,
sync::{mpsc::channel, Once},
time::{Duration, SystemTime, SystemTimeError},
usize,
};

// dependencies
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/torrent/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/torrent_summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 22d3dd1

Please sign in to comment.