-
Notifications
You must be signed in to change notification settings - Fork 2
125 lines (107 loc) · 3.52 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
name: CI
on:
push:
branches: ["master"]
pull_request:
branches: ["master"]
workflow_call:
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
RUSTUP_MAX_RETRIES: 10
RUST_BACKTRACE: short
PKG_CONFIG_ALLOW_CROSS: 1
jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y libudev-dev pkg-config
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Cache cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Check formatting
run: cargo fmt --all -- --check
- name: Check clippy
run: cargo clippy -- -D warnings
- name: Run tests
run: cargo test --all-features
build-linux:
name: Build Linux
needs: check
runs-on: ubuntu-latest
strategy:
matrix:
target:
- x86_64-unknown-linux-gnu
- aarch64-unknown-linux-gnu
- armv7-unknown-linux-gnueabihf
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross
uses: taiki-e/install-action@cross
- name: Cache cargo
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-${{ matrix.target }}-
- name: Cache cross
uses: actions/cache@v3
if: matrix.target != 'x86_64-unknown-linux-gnu'
with:
path: ~/.cargo/.cross
key: ${{ runner.os }}-cross-${{ matrix.target }}-${{ hashFiles('Cross.toml') }}
restore-keys: |
${{ runner.os }}-cross-${{ matrix.target }}-
- name: Install target specific dependencies
if: matrix.target == 'x86_64-unknown-linux-gnu'
run: |
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: Build
env:
PKG_CONFIG_ALLOW_CROSS: "1"
run: |
if [ "${{ matrix.target }}" = "x86_64-unknown-linux-gnu" ]; then
# Native build uses standard system paths
cargo build --release --target ${{ matrix.target }}
else
# Cross compilation requires special paths
if [ "${{ matrix.target }}" = "armv7-unknown-linux-gnueabihf" ]; then
PKG_PATH="/usr/lib/arm-linux-gnueabihf/pkgconfig"
elif [ "${{ matrix.target }}" = "aarch64-unknown-linux-gnu" ]; then
PKG_PATH="/usr/lib/aarch64-linux-gnu/pkgconfig"
fi
PKG_CONFIG_PATH="$PKG_PATH" \
PKG_CONFIG_SYSROOT_DIR="/usr" \
PKG_CONFIG_LIBDIR="$PKG_PATH" \
cross build --release --target ${{ matrix.target }}
fi