Skip to content

add cache

add cache #14

Workflow file for this run

name: Build and Release Rust Binary
on:
push:
# branches:
# - main
jobs:
build:
name: Build on ${{ matrix.target }}
runs-on: ${{ matrix.run_on }}
strategy:
matrix:
include:
# Linux
- target: x86_64-unknown-linux-gnu
os_name: linux-x86_64
run_on: ubuntu-latest
ext: ''
- target: aarch64-unknown-linux-gnu
os_name: linux-aarch64
run_on: ubuntu-latest
ext: ''
- target: armv7-unknown-linux-gnueabihf
os_name: linux-armv7
run_on: ubuntu-latest
ext: ''
# macOS (x86 and Apple Silicon)
- target: x86_64-apple-darwin
os_name: macos-x86_64
run_on: macos-latest
ext: ''
- target: aarch64-apple-darwin
os_name: macos-aarch64
run_on: macos-latest
ext: ''
# Windows (x86_64 only)
- target: x86_64-pc-windows-gnu
os_name: windows-x86_64
run_on: ubuntu-latest
ext: '.exe'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Cache Cargo registry
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os_name }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache Cargo build
uses: actions/cache@v3
with:
path: target
key: ${{ runner.os_name }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os_name }}-cargo-build-
- name: Install libudev development package
if: matrix.run_on == 'ubuntu-latest'
run: sudo apt-get update && sudo apt-get install -y libudev-dev
- name: Install cross-compilation tools for Windows
if: matrix.target == 'x86_64-pc-windows-gnu'
run: sudo apt-get update && sudo apt-get install -y mingw-w64
- name: Install cross-compilation tools for aarch64 Linux
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: sudo apt-get update && sudo apt-get install -y gcc-aarch64-linux-gnu libc6-dev-arm64-cross pkg-config
# Set environment variables for pkg-config cross compilation
- name: Set environment variables
if : matrix.target == 'aarch64-unknown-linux-gnu'
run: |
export PKG_CONFIG_SYSROOT_DIR=/usr/aarch64-linux-gnu
export PKG_CONFIG_PATH=$PKG_CONFIG_SYSROOT_DIR/usr/lib/pkgconfig:$PKG_CONFIG_SYSROOT_DIR/usr/share/pkgconfig
export PKG_CONFIG=pkg-config
# Check pkg-config finds libudev.pc for the target
pkg-config --print-variables libudev || echo "libudev.pc not found"
env:
PKG_CONFIG_SYSROOT_DIR: /usr/aarch64-linux-gnu
PKG_CONFIG_PATH: /usr/aarch64-linux-gnu/usr/lib/pkgconfig:/usr/aarch64-linux-gnu/usr/share/pkgconfig
PKG_CONFIG: pkg-config
- name: Install cross-compilation tools for armv7 Linux
if: matrix.target == 'armv7-unknown-linux-gnueabihf'
run: sudo apt-get update && sudo apt-get install -y gcc-arm-linux-gnueabihf libc6-dev-armhf-cross pkg-config
# Set environment variables for pkg-config cross compilation
- name: Set environment variables and build
if: matrix.target == 'armv7-unknown-linux-gnueabihf'
env:
PKG_CONFIG_SYSROOT_DIR: /usr/arm-linux-gnueabihf
PKG_CONFIG_PATH: /usr/arm-linux-gnueabihf/usr/lib/pkgconfig:/usr/arm-linux-gnueabihf/usr/share/pkgconfig
PKG_CONFIG: pkg-config
run: |
# Verify pkg-config can find target libraries
pkg-config --print-variables libudev || echo "libudev.pc not found"
- name: Set up Rust (nightly)
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly
- name: Install Rust target
run: rustup target add ${{ matrix.target }}
- name: Build binary
run: |
cargo build --release --target=${{ matrix.target }}
- name: Package binary
run: |
mkdir -p dist
BIN_NAME=datex_cli
TARGET_DIR=target/${{ matrix.target }}/release
OUTPUT_NAME=datex-${{ matrix.os_name }}${{ matrix.ext }}
cp ${TARGET_DIR}/${BIN_NAME}${{ matrix.ext }} dist/${OUTPUT_NAME}
cd dist && zip ${OUTPUT_NAME}.zip ${OUTPUT_NAME} && rm ${OUTPUT_NAME}
shell: bash
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os_name }}
path: dist/datex-${{ matrix.os_name }}.zip
continue-on-error: true
release:
name: Create GitHub Draft Release
needs: build
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: dist
- name: Create Draft Release
uses: softprops/action-gh-release@v2
with:
draft: true
tag_name: ${{ github.ref_name }}
files: dist/**/*.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}