Skip to content

Commit

Permalink
chore: Update Rust workflow to build the project with x86_64-unknown-…
Browse files Browse the repository at this point in the history
…linux-musl target
  • Loading branch information
edgarburgues committed May 17, 2024
1 parent 4b2d5a9 commit 636e987
Showing 1 changed file with 11 additions and 103 deletions.
114 changes: 11 additions & 103 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
name: Rust Build, Test, and Publish

on:
push:
branches:
- main
pull_request:
branches:
- main
release:
types: [created]

jobs:
build:
release:
name: release ${{ matrix.target }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand All @@ -20,100 +13,15 @@ jobs:
- target: x86_64-pc-windows-gnu
archive: zip
- target: x86_64-unknown-linux-musl
archive: tar.gz
archive: tar.gz tar.xz tar.zst
- target: x86_64-apple-darwin
archive: zip

steps:
- name: Check out the repository
uses: actions/checkout@v3

- name: Install Rust toolchain
run: rustup target add ${{ matrix.target }}

- name: Set up Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.target }}
override: true

- name: Install dependencies for Windows target
if: matrix.target == 'x86_64-pc-windows-gnu'
run: sudo apt-get install mingw-w64 -y

- name: Install dependencies for Linux target
if: matrix.target == 'x86_64-unknown-linux-musl'
run: |
sudo apt-get update
sudo apt-get install -y pkg-config libssl-dev musl-tools
rustup target add x86_64-unknown-linux-musl
sudo mkdir -p /usr/local/musl
sudo ln -s /usr/include /usr/local/musl/include
export PKG_CONFIG_ALLOW_CROSS=1
export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig
- name: Build the project
run: |
if [ "${{ matrix.target }}" == "x86_64-unknown-linux-musl" ]; then
OPENSSL_DIR=/usr \
PKG_CONFIG_ALLOW_CROSS=1 \
PKG_CONFIG_SYSROOT_DIR=/ \
cargo build --release --target ${{ matrix.target }}
else
cargo build --release --target ${{ matrix.target }}
fi
- name: Package the build
run: |
mkdir -p dist
if [ "${{ matrix.archive }}" == "zip" ]; then
zip -j dist/ml2pdf-${{ matrix.target }}.zip target/${{ matrix.target }}/release/ml2pdf*
else
tar -czvf dist/ml2pdf-${{ matrix.target }}.tar.gz -C target/${{ matrix.target }}/release ml2pdf*
fi
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: rust-app-${{ matrix.target }}
path: dist/

publish:
runs-on: ubuntu-latest
needs: build

steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: rust-app-${{ matrix.target }}
path: dist/

- name: Get current date
id: get_date
run: echo "DATE=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV

- name: Publish release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ env.DATE }}
release_name: Release ${{ env.DATE }}
draft: false
prerelease: false

- name: Upload artifacts to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: dist/ml2pdf-${{ matrix.target }}.${{ matrix.archive }}
asset_name: ml2pdf-${{ matrix.target }}.${{ matrix.archive }}
asset_content_type: application/octet-stream

- name: Clean up artifacts
run: rm -rf dist/
- uses: actions/checkout@master
- name: Compile and release
uses: rust-build/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GB_TOKEN }}
with:
RUSTTARGET: ${{ matrix.target }}
ARCHIVE_TYPES: ${{ matrix.archive }}

0 comments on commit 636e987

Please sign in to comment.