Skip to content

Commit

Permalink
ci: improve cross-compilation and package building
Browse files Browse the repository at this point in the history
- Add pkg-config environment variables for cross-compilation
- Set proper library paths for x86_64 native build
- Install dpkg-dev for Debian package building
- Combine apt commands to reduce layers
- Update GitHub Actions to v4 for upload/download artifacts
- Format YAML files for better readability
  • Loading branch information
aljen committed Dec 1, 2024
1 parent 58f0e1d commit 5830312
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
41 changes: 26 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Release
on:
push:
tags:
- 'v*'
- "v*"

env:
CARGO_TERM_COLOR: always
Expand Down Expand Up @@ -39,7 +39,7 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Install common dependencies
run: |
sudo apt-get update
Expand All @@ -48,13 +48,20 @@ jobs:
- name: Install target specific dependencies
if: matrix.target == 'x86_64-unknown-linux-gnu'
run: |
sudo apt-get install -y libudev-dev
sudo apt-get update
sudo apt-get install -y libudev-dev dpkg-dev
- name: Set library path
if: matrix.target == 'x86_64-unknown-linux-gnu'
run: |
echo "LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH" >> $GITHUB_ENV
echo "LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LIBRARY_PATH" >> $GITHUB_ENV
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}

- name: Install cross
uses: taiki-e/install-action@cross

Expand Down Expand Up @@ -82,18 +89,22 @@ jobs:
run: cargo install cargo-deb

- name: Build
env:
PKG_CONFIG_ALLOW_CROSS: "1"
PKG_CONFIG_PATH: "/usr/lib/${{ matrix.target }}/pkgconfig"
PKG_CONFIG_SYSROOT_DIR: "/usr"
run: |
if [ "${{ matrix.target }}" = "x86_64-unknown-linux-gnu" ]; then
cargo build --release --target ${{ matrix.target }}
else
cross build --release --target ${{ matrix.target }}
fi
- name: Build deb package
run: cargo deb --target ${{ matrix.target }}

- name: Upload artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: deb-${{ matrix.arch }}
path: target/${{ matrix.target }}/debian/*.deb
Expand Down Expand Up @@ -122,12 +133,12 @@ jobs:

steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
# Update system
pacman -Syu --noconfirm
# Install common dependencies
pacman -S --noconfirm \
git \
Expand Down Expand Up @@ -187,7 +198,7 @@ jobs:
cp -r . "/tmp/modbus-relay"
cd /tmp
tar czf "modbus-relay.tar.gz" "modbus-relay"
- name: Build package
run: |
cd /tmp
Expand All @@ -196,9 +207,9 @@ jobs:
mv ../modbus-relay.tar.gz .
cp /tmp/modbus-relay/dist/arch/PKGBUILD .
CARCH=${{ matrix.arch }} makepkg -s --noconfirm
- name: Upload artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: pkg-${{ matrix.arch }}
path: /tmp/pkg/*.pkg.tar.zst
Expand All @@ -211,9 +222,9 @@ jobs:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3

- uses: actions/download-artifact@v4

- name: Create Release
uses: softprops/action-gh-release@v1
with:
Expand Down
16 changes: 10 additions & 6 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
[target.aarch64-unknown-linux-gnu]
pre-build = [
"dpkg --add-architecture arm64",
"apt-get update",
"apt-get install -y libudev-dev:arm64"
"dpkg --add-architecture arm64 && apt-get update && apt-get install -y libudev-dev:arm64",
]

[target.armv7-unknown-linux-gnueabihf]
pre-build = [
"dpkg --add-architecture armhf",
"apt-get update",
"apt-get install -y libudev-dev:armhf"
"dpkg --add-architecture armhf && apt-get update && apt-get install -y libudev-dev:armhf",
]

[build.env]
passthrough = [
"PKG_CONFIG_ALLOW_CROSS",
"PKG_CONFIG_PATH",
"PKG_CONFIG_SYSROOT_DIR",
"PKG_CONFIG_LIBDIR",
]

0 comments on commit 5830312

Please sign in to comment.