From cc54205cc7a9679c1b90fe052b419c48a4f2572f Mon Sep 17 00:00:00 2001 From: Konrad Baran <65494005+uznog@users.noreply.github.com> Date: Sun, 3 Mar 2024 08:36:49 +0100 Subject: [PATCH] feat: add musl linux build targets (#759) --- .github/workflows/cachix.yml | 22 +++--- .github/workflows/release.yml | 122 ++++++++++++++++++++++++---------- scripts/build.sh | 34 ++++++---- 3 files changed, 118 insertions(+), 60 deletions(-) diff --git a/.github/workflows/cachix.yml b/.github/workflows/cachix.yml index ab0c4a4f..0f9e8db3 100644 --- a/.github/workflows/cachix.yml +++ b/.github/workflows/cachix.yml @@ -1,4 +1,3 @@ -# Publish the Nix flake outputs to Cachix name: Cachix on: push: @@ -13,17 +12,16 @@ jobs: os: [ubuntu-latest, macos-latest] runs-on: ${{ matrix.os }} steps: - - name: Checkout sources - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - - name: Install nix - uses: cachix/install-nix-action@v25 + - name: Install Nix + uses: cachix/install-nix-action@v25 - - name: Authenticate with Cachix - uses: cachix/cachix-action@v14 - with: - name: yazi - authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + - name: Authenticate with Cachix + uses: cachix/cachix-action@v14 + with: + name: yazi + authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}" - - name: Build nix flake - run: nix build -L + - name: Build Flake + run: nix build -L diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f638bca7..ce64d31e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,9 +6,7 @@ on: - "v[0-9]+.[0-9]+.[0-9]+" jobs: - release: - permissions: - contents: write + build-unix: strategy: matrix: include: @@ -20,6 +18,27 @@ jobs: target: x86_64-apple-darwin - os: macos-latest target: aarch64-apple-darwin + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + + - name: Install gcc-aarch64-linux-gnu + if: matrix.target == 'aarch64-unknown-linux-gnu' + run: sudo apt-get update && sudo apt-get install -yq gcc-aarch64-linux-gnu + + - name: Build + run: ./scripts/build.sh ${{ matrix.target }} + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: yazi-${{ matrix.target }}.zip + path: yazi-${{ matrix.target }}.zip + + build-windows: + strategy: + matrix: + include: - os: windows-latest target: x86_64-pc-windows-msvc - os: windows-latest @@ -31,57 +50,92 @@ jobs: - name: Setup Rust toolchain run: rustup toolchain install stable --profile minimal - - name: Add aarch64 target - if: contains(fromJson('["aarch64-unknown-linux-gnu", "aarch64-apple-darwin", "aarch64-pc-windows-msvc"]'), matrix.target) + - name: Add target run: rustup target add ${{ matrix.target }} - - name: Install gcc-aarch64-linux-gnu - if: matrix.target == 'aarch64-unknown-linux-gnu' - run: | - sudo apt-get update - sudo apt-get install -yq gcc-aarch64-linux-gnu - - - name: Setup Rust cache - uses: Swatinem/rust-cache@v2 - - name: Build env: YAZI_GEN_COMPLETIONS: true - CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: /usr/bin/aarch64-linux-gnu-gcc run: cargo build --release --locked --target ${{ matrix.target }} - - name: Build snap - if: matrix.target == 'x86_64-unknown-linux-gnu' - uses: snapcore/action-build@v1 - - - name: Pack artifacts [Linux & macOS] - if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest' - env: - TARGET_NAME: yazi-${{ matrix.target }} - run: | - mkdir $TARGET_NAME - cp target/${{ matrix.target }}/release/yazi $TARGET_NAME - cp -r yazi-config/completions $TARGET_NAME - cp README.md LICENSE $TARGET_NAME - zip -r $TARGET_NAME.zip $TARGET_NAME - - - name: Pack artifacts [Windows] + - name: Pack artifact if: matrix.os == 'windows-latest' env: TARGET_NAME: yazi-${{ matrix.target }} run: | New-Item -ItemType Directory -Path ${env:TARGET_NAME} Copy-Item -Path "target\${{ matrix.target }}\release\yazi.exe" -Destination ${env:TARGET_NAME} - Copy-Item -Path "yazi-config\completions" -Destination ${env:TARGET_NAME} -Recurse + Copy-Item -Path "yazi-boot\completions" -Destination ${env:TARGET_NAME} -Recurse Copy-Item -Path "README.md", "LICENSE" -Destination ${env:TARGET_NAME} Compress-Archive -Path ${env:TARGET_NAME} -DestinationPath "${env:TARGET_NAME}.zip" + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: yazi-${{ matrix.target }}.zip + path: yazi-${{ matrix.target }}.zip + + build-musl: + runs-on: ubuntu-latest + strategy: + matrix: + include: + - target: x86_64-unknown-linux-musl + image: rust-musl-cross:x86_64-musl + - target: aarch64-unknown-linux-musl + image: rust-musl-cross:aarch64-musl + container: + image: docker://ghcr.io/rust-cross/${{ matrix.image }} + steps: + - uses: actions/checkout@v4 + + - name: Build + run: ./scripts/build.sh ${{ matrix.target }} + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: yazi-${{ matrix.target }}.zip + path: yazi-${{ matrix.target }}.zip + + build-snap: + strategy: + matrix: + include: + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + + - name: Build snap + uses: snapcore/action-build@v1 + + - name: Build + run: mv yazi_*.snap yazi-${{ matrix.target }}.snap + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: yazi-${{ matrix.target }}.snap + path: yazi-${{ matrix.target }}.snap + + release: + permissions: + contents: write + runs-on: ubuntu-latest + needs: [build-unix, build-windows, build-musl, build-snap] + steps: + - uses: actions/download-artifact@v4 + with: + merge-multiple: true + - name: Release uses: softprops/action-gh-release@v1 if: startsWith(github.ref, 'refs/tags/') with: draft: true files: | - yazi-${{ matrix.target }}.zip - yazi*.snap + yazi-*.zip + yazi-*.snap generate_release_notes: true diff --git a/scripts/build.sh b/scripts/build.sh index 43c06423..d3f9a934 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,20 +1,26 @@ #!/bin/bash set -euo pipefail -SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -cd $SCRIPT_DIR/.. +export ARTIFACT_NAME="yazi-$1" +export YAZI_GEN_COMPLETIONS=1 +export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=/usr/bin/aarch64-linux-gnu-gcc -cargo +stable build --release --target aarch64-apple-darwin -cargo +stable build --release --target x86_64-apple-darwin -cargo +stable build --release --target x86_64-unknown-linux-gnu -cargo +stable build --release --target x86_64-pc-windows-gnu +# Setup Rust toolchain +rustup toolchain install stable --profile minimal +rustup target add "$1" -mv target/aarch64-apple-darwin/release/yazi yazi-aarch64-apple-darwin -mv target/x86_64-apple-darwin/release/yazi yazi-x86_64-apple-darwin -mv target/x86_64-unknown-linux-gnu/release/yazi yazi-x86_64-unknown-linux-gnu -mv target/x86_64-pc-windows-gnu/release/yazi.exe yazi-x86_64-pc-windows-gnu.exe +# Build for the target +cargo build --release --locked --target "$1" -zip -j yazi-aarch64-apple-darwin.zip yazi-aarch64-apple-darwin -zip -j yazi-x86_64-apple-darwin.zip yazi-x86_64-apple-darwin -zip -j yazi-x86_64-unknown-linux-gnu.zip yazi-x86_64-unknown-linux-gnu -zip -j yazi-x86_64-pc-windows-gnu.zip yazi-x86_64-pc-windows-gnu.exe +# Create the artifact +mkdir "$ARTIFACT_NAME" +cp "target/$1/release/yazi" "$ARTIFACT_NAME" +cp -r yazi-boot/completions "$ARTIFACT_NAME" +cp README.md LICENSE "$ARTIFACT_NAME" + +# Zip the artifact +if ! command -v zip &> /dev/null +then + sudo apt-get update && sudo apt-get install -yq zip +fi +zip -r "$ARTIFACT_NAME.zip" "$ARTIFACT_NAME"