-
Notifications
You must be signed in to change notification settings - Fork 138
245 lines (232 loc) · 8.18 KB
/
test.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
name: Test
on:
push:
branches:
- '**'
- '!dependabot/**'
pull_request:
branches: [ master ]
workflow_call:
jobs:
test:
name: Test [${{ matrix.rust }}, ${{ matrix.profile }}]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rust: [stable, nightly]
profile: [dev]
include:
- rust: stable
profile: release
# Anything nightly is treated as informational-only.
continue-on-error: ${{ matrix.rust == 'nightly' }}
steps:
- name: "Set environmental variables"
shell: bash
run: |
RUST_BACKTRACE_nightly='1'
CFLAGS_nightly='-fsanitize=leak'
CXXFLAGS_nightly='-fsanitize=leak'
RUSTFLAGS_nightly='-Zsanitizer=leak'
# A function for defining a variable conditional on the toolchain in
# use.
tc_var() {
# Replace any dots in the toolchain name with underscores. Necessary
# due to shell imposed variable naming restrictions.
var="${1}_$(echo ${{ matrix.rust }} | tr . _)"
echo "${1}=${!var}" >> ${GITHUB_ENV}
}
tc_var RUST_BACKTRACE
tc_var RUSTFLAGS
tc_var CFLAGS
tc_var CXXFLAGS
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
components: rustfmt
- name: Install deps
run: |
sudo apt-get install -y clang-14 libelf-dev zlib1g-dev linux-headers-$(uname -r)
sudo ln -s /usr/include/asm-generic /usr/include/asm
sudo rm -f /bin/clang && sudo ln -s /usr/bin/clang-14 /bin/clang
- uses: Swatinem/rust-cache@v2
- name: Build
run: cargo build --profile=${{ matrix.profile }} --locked --verbose --workspace --exclude runqslower
- name: Run tests
# Skip tests which require sudo
run: cargo test --profile=${{ matrix.profile }} --locked --verbose --workspace --exclude runqslower -- --skip ':root:' --include-ignored
- name: Run root tests
run: cd libbpf-rs && cargo test --profile=${{ matrix.profile }} --locked --verbose -- ':root:'
run-tcp-ca:
name: Run tcp_ca example
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install deps
run: sudo apt-get install -y libelf-dev
- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt
- uses: Swatinem/rust-cache@v2
- name: Run tcp_ca
env:
CFLAGS: '-fsanitize=leak'
CXXFLAGS: '-fsanitize=leak'
RUSTFLAGS: '-Zsanitizer=leak'
run: |
cargo build --package tcp_ca
sudo target/debug/tcp_ca
build-features:
name: Build [${{ matrix.args }}]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- args: "features = ['vendored']"
- args: "features = ['static']"
# TODO: Should build without features, but that requires system
# libbpf and ubuntu 22.04 only has 0.5 (..?)
#- args: "default-features = false"
steps:
- uses: actions/checkout@v4
- name: Install deps
run: sudo apt-get install -y libelf-dev autopoint
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Build libbpf-rs sample
run: |
cargo init --bin libbpf-rs-test-project
cd libbpf-rs-test-project
cat >> Cargo.toml <<EOF
libbpf-rs = { path = "../libbpf-rs", ${{ matrix.args }} }
EOF
cat > src/main.rs <<EOF
fn main() {
// Use *some* libbpf API so that we actually link against the library.
let _linker = libbpf_rs::Linker::new("/tmp/foobar").unwrap();
}
EOF
RUSTFLAGS="$RUSTFLAGS -L /usr/lib/x86_64-linux-gnu" cargo build
build-minimum:
name: Build using minimum versions of dependencies
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install deps
run: sudo apt-get install -y libelf-dev
- name: Install Nightly Rust
uses: dtolnay/rust-toolchain@nightly
- run: cargo +nightly -Z minimal-versions update
- name: Install minimum Rust
uses: dtolnay/rust-toolchain@master
with:
# Please adjust README and rust-version field in Cargo.toml files when
# bumping version.
toolchain: 1.71.0
components: rustfmt
- uses: Swatinem/rust-cache@v2
- name: Build
run: cargo build --verbose --workspace --exclude runqslower
build-capable:
name: Build capable example with static libelf and libz
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install deps
run: sudo apt-get install -y libelf-dev
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- run: RUSTFLAGS="$RUSTFLAGS -L /usr/lib/x86_64-linux-gnu" cargo build --locked --package capable --features=static
build-aarch64:
name: Build for aarch64
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Add apt sources for arm64
run: |
dpkg --add-architecture arm64
release=$(. /etc/os-release && echo "$UBUNTU_CODENAME")
sed -i 's/^deb /deb [arch=amd64] /' /etc/apt/sources.list
printf 'deb [arch=arm64] http://ports.ubuntu.com/ %s main restricted\n' \
$release $release-updates $release-security \
>> /etc/apt/sources.list
shell: sudo sh -e {0}
- uses: dtolnay/rust-toolchain@stable
with:
targets: aarch64-unknown-linux-gnu
- name: Install deps
run: |
sudo apt-get update
sudo apt-get install -y libelf-dev:arm64 zlib1g-dev:arm64 gcc-aarch64-linux-gnu
- uses: Swatinem/rust-cache@v2
- name: Build
env:
CARGO_BUILD_TARGET: aarch64-unknown-linux-gnu
RUSTFLAGS: -C linker=/usr/bin/aarch64-linux-gnu-gcc
run: cargo build --lib
build-armhf:
name: Build for aarch32
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Add apt sources for armhf
run: |
dpkg --add-architecture armhf
release=$(. /etc/os-release && echo "$UBUNTU_CODENAME")
sed -i 's/^deb /deb [arch=amd64] /' /etc/apt/sources.list
printf 'deb [arch=armhf] http://ports.ubuntu.com/ %s main restricted\n' \
$release $release-updates $release-security \
>> /etc/apt/sources.list
shell: sudo sh -e {0}
- uses: dtolnay/rust-toolchain@stable
with:
targets: armv7-unknown-linux-gnueabihf
- name: Install deps
run: |
sudo apt-get update
sudo apt-get install -y libelf-dev:armhf zlib1g-dev:armhf gcc-arm-linux-gnueabihf
- uses: Swatinem/rust-cache@v2
- name: Build
env:
CARGO_BUILD_TARGET: armv7-unknown-linux-gnueabihf
RUSTFLAGS: -C linker=/usr/bin/armhf-linux-gnu-gcc
run: cargo build --lib
clippy:
name: Lint with clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install deps
run: sudo apt-get install -y libelf-dev
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- uses: Swatinem/rust-cache@v2
- run: |
# We want the old resolver here as it has more suitable feature
# unification logic for this invocation.
sed -i 's@resolver = "2"@resolver = "1"@' Cargo.toml
cargo clippy --locked --no-deps --all-targets --tests --features=dont-generate-test-files -- -D warnings -D clippy::absolute_paths
rustfmt:
name: Check code formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt
- run: cargo fmt -- --check
cargo-doc:
name: Check documentation
runs-on: ubuntu-latest
env:
RUSTDOCFLAGS: '-D warnings'
steps:
- uses: actions/checkout@v4
- name: Install deps
run: sudo apt-get install -y libelf-dev
- uses: dtolnay/rust-toolchain@stable
- run: cargo doc --locked --no-deps