-
-
Notifications
You must be signed in to change notification settings - Fork 10
436 lines (408 loc) · 16.6 KB
/
Copy pathchecks.yaml
File metadata and controls
436 lines (408 loc) · 16.6 KB
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
name: checks
permissions:
contents: read
on:
push:
branches:
- main
- 'release/**'
pull_request:
branches-ignore:
- 'release/**'
schedule:
- cron: '0 4 * * *'
merge_group:
branches:
- main
jobs:
build:
name: Build and test
runs-on: "${{ matrix.os }}"
env:
RUST_BACKTRACE: 1
# NOTE: tests that configure a custom runner must add that runner to
# the `runner` function in tests/quick.rs and tests/recover.rs.
# i686-unknown-linux-gnu
CARGO_TARGET_I686_UNKNOWN_LINUX_GNU_LINKER: i686-linux-gnu-gcc
# s390x-unknown-linux-gnu
CARGO_TARGET_S390X_UNKNOWN_LINUX_GNU_LINKER: s390x-linux-gnu-gcc
CARGO_TARGET_S390X_UNKNOWN_LINUX_GNU_RUNNER: qemu-s390x -L /usr/s390x-linux-gnu
CARGO_TARGET_S390X_UNKNOWN_LINUX_GNU_RUSTFLAGS: "-C target-feature=+crt-static"
# wasm32-wasip1 (std for wasip2 is unstable)
WASI_SDK_PATH: /tmp/wasi-sdk-24.0-x86_64-linux
CC_wasm32_wasip1: /tmp/wasi-sdk-24.0-x86_64-linux/bin/clang
AR_wasm32_wasip1: /tmp/wasi-sdk-24.0-x86_64-linux/bin/llvm-ar
CARGO_TARGET_WASM32_WASIP1_RUNNER: "wasmtime --dir ../tests"
CARGO_TARGET_WASM32_WASIP1_RUSTFLAGS: "-Ctarget-feature=+simd128"
strategy:
matrix:
include:
- rust: stable
target: "x86_64-unknown-linux-gnu"
os: ubuntu-latest
codecov: true
- rust: msrv
target: "x86_64-unknown-linux-gnu"
os: ubuntu-latest
codecov: false
- rust: beta
target: "x86_64-unknown-linux-gnu"
os: ubuntu-latest
codecov: false
- target: "aarch64-unknown-linux-gnu"
os: ubuntu-24.04-arm
codecov: true
- target: "i686-unknown-linux-gnu"
os: ubuntu-latest
codecov: true
apt-packages: gcc-i686-linux-gnu
- target: "s390x-unknown-linux-gnu"
os: ubuntu-latest
codecov: false
apt-packages: qemu-user qemu-user-static libc6-dev-s390x-cross gcc-s390x-linux-gnu
- target: "wasm32-wasip1"
os: ubuntu-latest
packages: "-p libbz2-rs-sys -p test-libbz2-rs-sys"
codecov: false
- target: "x86_64-apple-darwin"
os: macos-latest
codecov: true
- target: "aarch64-apple-darwin"
os: macos-14
codecov: true
- target: "x86_64-pc-windows-gnu"
os: windows-2022
codecov: false
- target: "aarch64-pc-windows-msvc"
os: windows-11-arm
codecov: false
steps:
- name: Checkout sources
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
persist-credentials: false
submodules: true
# Install the correct rust toolchain/version
- name: Set target rust version
run: echo "MSRV=$(grep rust-version Cargo.toml | grep MSRV | awk -F '\"' '{print $2}')" >> $GITHUB_ENV
if: ${{ matrix.rust == 'msrv' }}
- name: Install toolchain
uses: dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248
with:
toolchain: ${{ env.MSRV || matrix.rust || 'stable' }}
targets: "${{ matrix.target }}"
# Install dependencies
- name: Install cargo-llvm-cov & cargo-nextest
uses: taiki-e/install-action@d12e869b89167df346dd0ff65da342d1fb1202fb # v2.53.2
with:
tool: cargo-llvm-cov,cargo-nextest
- name: Cache apt packages
if: matrix.apt-packages != ''
uses: awalsh128/cache-apt-pkgs-action@v1
with:
packages: "${{ matrix.apt-packages }}"
version: 2
- name: Download wasmtime & wasi-sdk
if: ${{ contains(matrix.target, 'wasm') }}
run: |
curl https://wasmtime.dev/install.sh -sSf | bash
echo "$HOME/.wasmtime/bin" >> $GITHUB_PATH
curl -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-24/wasi-sdk-24.0-x86_64-linux.tar.gz | tar xz --directory /tmp
- name: cargo build
run: cargo build --target ${{matrix.target}} ${{ matrix.packages || '--workspace' }}
if: ${{ matrix.target == 's390x-unknown-linux-gnu' }}
- name: cargo build (no_std)
run: cargo rustc --target ${{matrix.target}} -p libbz2-rs-sys --lib --no-default-features --crate-type rlib
env:
RUSTFLAGS: -Aunused_variables -Aunused_assignments
- name: cargo build (no_std + rust_allocator)
run: cargo rustc --target ${{matrix.target}} -p libbz2-rs-sys --lib --no-default-features --features rust-allocator --crate-type rlib
env:
RUSTFLAGS: -Aunused_variables -Aunused_assignments
- name: cargo llvm-cov nextest
if: matrix.codecov
run: cargo llvm-cov nextest --lcov --output-path lcov.info --ignore-filename-regex "test-libz|dynamic-libz" --target ${{matrix.target}} ${{ matrix.packages || '--workspace' }} --no-fail-fast
- name: cargo nextest
if: matrix.codecov == false
run: cargo nextest run --target ${{matrix.target}} ${{ matrix.packages || '--workspace' }} --no-fail-fast
- name: Upload coverage to Codecov
uses: codecov/codecov-action@0565863a31f2c772f9f0395002a31e3f06189574 # v5.4.0
if: matrix.codecov
with:
files: ./lcov.info
fail_ci_if_error: false
flags: test-${{matrix.target}}
token: ${{ secrets.CODECOV_TOKEN }}
name: test
verbose: true
clippy:
name: Clippy
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
features:
- ""
- '--no-default-features --features="c-allocator"'
- '--no-default-features --features="std,rust-allocator"'
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
persist-credentials: false
submodules: true
- name: Install rust toolchain
uses: dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248
with:
toolchain: stable
components: clippy
targets: ${{matrix.target}}
- name: Rust cache
uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8
with:
shared-key: "stable-${{matrix.target}}"
- name: Run clippy
run: cargo clippy --target ${{matrix.target}} ${{matrix.features}} --workspace --all-targets -- -D warnings
fuzz:
name: Smoke-test fuzzing targets
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-latest
features: default
- os: ubuntu-latest
features: c-allocator
- os: ubuntu-latest
features: rust-allocator
- os: macos-14
features: ""
steps:
- name: Checkout sources
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
persist-credentials: false
submodules: true
- name: Install nightly toolchain
uses: dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248
with:
toolchain: nightly
- name: Install cargo fuzz
run: cargo install cargo-fuzz
- name: Smoke-test fuzz targets
run: |
cargo fuzz build --no-default-features --features="${{ matrix.features }}"
for target in $(cargo fuzz list); do
if [ "$target" = "decompress_chunked" ]; then
features="${{ matrix.features }} disable-checksum"
else
features="${{ matrix.features }}"
fi
RUST_BACKTRACE=1 cargo fuzz run --jobs 4 --no-default-features --features="$features" $target -- -max_total_time=10
done
fuzz-code-coverage:
name: Fuzz with code coverage
runs-on: ubuntu-latest
strategy:
matrix:
include:
- fuzz_target: decompress_chunked
corpus: "bzip2-files/compressed"
features: '--no-default-features --features="disable-checksum"'
- fuzz_target: compress_then_decompress
corpus: ""
features: ''
steps:
- name: Checkout sources
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
persist-credentials: false
- name: Install nightly toolchain
uses: dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248
with:
toolchain: nightly
components: llvm-tools-preview
- name: Install rustfilt
uses: taiki-e/install-action@a27ef18d36cfa66b0af3a360104621793b41c036 # v2.54.3
with:
tool: rustfilt
- name: Install cargo fuzz
run: cargo install cargo-fuzz
- name: Download custom decompression corpus
if: ${{ contains(matrix.corpus, 'bzip2-files') }}
run: |
wget https://github.com/trifectatechfoundation/compression-corpus/releases/download/2025-04-24-180855/bzip2-files.zip
unzip bzip2-files.zip -d bzip2-files
- name: Run `cargo fuzz`
env:
RUST_BACKTRACE: "1"
# prevents `cargo fuzz coverage` from rebuilding everything
RUSTFLAGS: "-C instrument-coverage"
run: |
cargo fuzz run --jobs 4 ${{matrix.features}} ${{matrix.fuzz_target}} ${{matrix.corpus}} -- -max_total_time=20
- name: Fuzz codecov
run: |
cargo fuzz coverage ${{matrix.features}} ${{matrix.fuzz_target}} ${{matrix.corpus}}
$(rustc --print sysroot)/lib/rustlib/$(rustc --print host-tuple)/bin/llvm-cov export -Xdemangler=rustfilt \
target/$(rustc --print host-tuple)/coverage/$(rustc --print host-tuple)/release/${{matrix.fuzz_target}} \
-instr-profile=fuzz/coverage/${{matrix.fuzz_target}}/coverage.profdata \
--format=lcov \
-ignore-filename-regex="\.cargo|\.rustup|fuzz_targets|test-libbz2" > lcov.info
- name: List the corpus
if: ${{ contains(matrix.corpus, 'bzip2-files') }}
run: |
ls ${{matrix.corpus}}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d
with:
files: ./lcov.info
fail_ci_if_error: false
flags: fuzz-${{ matrix.fuzz_target }}
token: ${{ secrets.CODECOV_TOKEN }}
name: fuzz
miri:
name: "Miri"
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
persist-credentials: false
submodules: true
- name: Install Miri
run: |
rustup toolchain install nightly --component miri
cargo +nightly miri setup
- name: Install cargo-nextest
uses: taiki-e/install-action@d12e869b89167df346dd0ff65da342d1fb1202fb # v2.53.2
with:
tool: cargo-nextest
- name: Test public C api with miri
run: |
cargo +nightly miri nextest run -j4 -p test-libbz2-rs-sys miri_
- name: Run unit tests with miri
run: "cargo +nightly miri nextest run -j4 -p libbz2-rs-sys"
link-c-dynamic-library:
name: vanilla dynamic library
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
features:
- ''
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
persist-credentials: false
- name: Install rust toolchain
uses: dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248
with:
toolchain: stable
targets: ${{matrix.target}}
- name: "cdylib: default settings"
working-directory: libbz2-rs-sys-cdylib
env:
LD_LIBRARY_PATH: "target/${{matrix.target}}/release/deps"
run: |
cargo build --release --target ${{matrix.target}}
cc -o bzpipe bzpipe.c target/${{matrix.target}}/release/deps/libbz2_rs.so -I ../
./bzpipe < Cargo.toml | ./bzpipe -d > out.txt
cmp -s Cargo.toml out.txt
- name: "cdylib: no stdio"
env:
LD_LIBRARY_PATH: "target/${{matrix.target}}/release/deps"
working-directory: libbz2-rs-sys-cdylib
run: |
cargo build --release --target ${{matrix.target}} --no-default-features
cc -DNO_STD -o bzpipe bzpipe.c target/${{matrix.target}}/release/deps/libbz2_rs.so -I ../
./bzpipe < Cargo.toml | ./bzpipe -d > out.txt
cmp -s Cargo.toml out.txt
- name: "staticlib: no stdio"
env:
LD_LIBRARY_PATH: "target/${{matrix.target}}/release/deps"
working-directory: libbz2-rs-sys-cdylib
run: |
cargo build --release --target ${{matrix.target}} --no-default-features
cc -o bzpipe bzpipe.c target/${{matrix.target}}/release/deps/libbz2_rs.so -I ../
./bzpipe < Cargo.toml | ./bzpipe -d > out.txt
cmp -s Cargo.toml out.txt
- name: "cdylib: custom-prefix"
working-directory: libbz2-rs-sys-cdylib
env:
LIBBZ2_RS_SYS_PREFIX: "MY_CUSTOM_PREFIX_"
run: |
cargo build --release --target ${{matrix.target}} --features=custom-prefix
objdump -tT target/${{matrix.target}}/release/deps/libbz2_rs.so | grep -q "MY_CUSTOM_PREFIX_BZ2_bzCompressInit" || (echo "symbol not found!" && exit 1)
- name: "cdylib: semver-prefix"
working-directory: libbz2-rs-sys-cdylib
run: |
cargo build --release --target ${{matrix.target}} --features=semver-prefix
objdump -tT target/${{matrix.target}}/release/deps/libbz2_rs.so | grep -q -E "LIBBZ2_RS_SYS_v0.[0-9]+.x_BZ2_bzCompressInit" || (echo "symbol not found!" && exit 1)
cargo-c-dynamic-library:
name: cargo-c dynamic library
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
features:
- ''
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
persist-credentials: false
- name: Install rust toolchain
uses: dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248
with:
toolchain: stable
targets: ${{matrix.target}}
- name: Install cargo-c
env:
LINK: https://github.com/lu-zero/cargo-c/releases/download/v0.10.5
run: |
curl -L "$LINK/cargo-c-x86_64-unknown-linux-musl.tar.gz" |
tar xz -C $HOME/.cargo/bin
- name: build with and test the result of cargo-c
working-directory: libbz2-rs-sys-cdylib
run: |
# build using cargo-c this time
cargo cinstall --release --destdir=/tmp/cargo-cbuild-libbzip2-rs # somehow --offline does not work here
tree /tmp/cargo-cbuild-libbzip2-rs
# verify that the SONAME is set and includes a version
objdump -p target/x86_64-unknown-linux-gnu/release/libbz2_rs.so | awk '/SONAME/{print $2}' | grep -E 'libbz2_rs\.so\.1'
# build bzpipe with our library
cc -o bzpipe bzpipe.c -L/tmp/cargo-cbuild-libbzip2-rs/usr/local/lib/x86_64-linux-gnu -lbz2_rs -I ../
export LD_LIBRARY_PATH=/tmp/cargo-cbuild-libbzip2-rs/usr/local/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH
./bzpipe < Cargo.toml | ./bzpipe -d > out.txt
cmp -s Cargo.toml out.txt
- name: verify api surface with abigail
run: |
sudo apt install libbz2-dev abigail-tools
LIBBZ2_PATH=$(ldconfig -p | grep "x86_64-linux-gnu/libbz2.so" | head -n 1 | awk '{print $4}')
LIBBZ2_FILENAME=$(basename "$LIBBZ2_PATH")
abidw $LIBBZ2_PATH > /tmp/$LIBBZ2_FILENAME.abi
abidw /tmp/cargo-cbuild-libbzip2-rs/usr/local/lib/x86_64-linux-gnu/libbz2_rs.so > /tmp/liblibz_rs_sys.so.abi
abidiff --no-unreferenced-symbols --ignore-soname /tmp/$LIBBZ2_FILENAME.abi /tmp/liblibz_rs_sys.so.abi
run-bzip2-rs-test-suite:
name: run bzip2-rs test suite
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
persist-credentials: false
- name: run
run: |
cd ..
git clone https://github.com/trifectatechfoundation/bzip2-rs.git
cd bzip2-rs
sed -i '/^\[dependencies\.libbz2-rs-sys\]/,/^$/ s/^version = .*/path = "..\/libbzip2-rs\/libbz2-rs-sys"/' Cargo.toml
cargo test # libbz2-rs-sys is the default now