Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add musl linux build targets #759

Merged
merged 4 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions .github/workflows/cachix.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Publish the Nix flake outputs to Cachix
name: Cachix
on:
push:
Expand All @@ -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
122 changes: 88 additions & 34 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ on:
- "v[0-9]+.[0-9]+.[0-9]+"

jobs:
release:
permissions:
contents: write
build-unix:
strategy:
matrix:
include:
Expand All @@ -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
Expand All @@ -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
34 changes: 20 additions & 14 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -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"