Skip to content

Commit f157719

Browse files
bjorn3folkertdev
authored andcommitted
Add CI
1 parent bbfa8ae commit f157719

File tree

3 files changed

+386
-0
lines changed

3 files changed

+386
-0
lines changed

.github/workflows/checks.yaml

Lines changed: 374 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,374 @@
1+
name: checks
2+
3+
permissions:
4+
contents: read
5+
6+
on:
7+
push:
8+
branches:
9+
- main
10+
- 'release/**'
11+
pull_request:
12+
branches-ignore:
13+
- 'release/**'
14+
schedule:
15+
- cron: '0 4 * * *'
16+
merge_group:
17+
branches:
18+
- main
19+
20+
jobs:
21+
build:
22+
name: Build and test
23+
runs-on: "${{ matrix.os }}"
24+
strategy:
25+
matrix:
26+
include:
27+
- rust: stable
28+
os: ubuntu-latest
29+
features: ""
30+
target: "x86_64-unknown-linux-gnu"
31+
- rust: msrv
32+
os: ubuntu-latest
33+
features: ""
34+
target: "x86_64-unknown-linux-gnu"
35+
- rust: beta
36+
os: ubuntu-latest
37+
features: ""
38+
target: "x86_64-unknown-linux-gnu"
39+
# - rust: "stable"
40+
# os: macos-latest
41+
# features: ""
42+
# target: "x86_64-apple-darwin"
43+
# - rust: "stable"
44+
# os: macos-14
45+
# features: ""
46+
# target: "aarch64-apple-darwin"
47+
# - rust: stable-x86_64-gnu
48+
# os: windows-2022
49+
# features: ""
50+
# target: "x86_64-pc-windows-gnu"
51+
steps:
52+
- name: Checkout sources
53+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
54+
with:
55+
persist-credentials: false
56+
submodules: true
57+
- name: Set target rust version
58+
run: echo "TARGET_RUST_VERSION=$(if [ "${{matrix.rust}}" = "msrv" ]; then grep rust-version Cargo.toml | grep MSRV | cut -d'"' -f2; else echo "${{matrix.rust}}"; fi)" >> $GITHUB_ENV
59+
if: matrix.os != 'windows-2022'
60+
- name: Install toolchain
61+
uses: dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248
62+
with:
63+
toolchain: "${TARGET_RUST_VERSION}"
64+
targets: "${{ matrix.target }}"
65+
if: matrix.os != 'windows-2022'
66+
- name: Install toolchain
67+
uses: dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248
68+
with:
69+
toolchain: "${{matrix.rust}}"
70+
targets: "${{ matrix.target }}"
71+
if: matrix.os == 'windows-2022'
72+
- name: target
73+
run: "rustc -vV | sed -n 's|host: ||p'"
74+
if: matrix.os != 'windows-2022'
75+
- name: Install cargo-llvm-cov
76+
uses: taiki-e/install-action@56ab7930c591507f833cbaed864d201386d518a8
77+
with:
78+
tool: cargo-llvm-cov
79+
- name: Install cargo-nextest
80+
uses: taiki-e/install-action@56ab7930c591507f833cbaed864d201386d518a8
81+
with:
82+
tool: cargo-nextest
83+
- name: cargo build
84+
run: cargo build --target ${{matrix.target}} ${{ matrix.features }}
85+
- name: cargo nextest # reports segfaults in a helpful way
86+
run: cargo nextest run --target ${{matrix.target}} ${{ matrix.features }} --no-fail-fast
87+
env:
88+
RUST_BACKTRACE: 1
89+
- name: cargo test with llvm-cov
90+
run: cargo llvm-cov --target ${{matrix.target}} ${{ matrix.features }} --lcov --output-path lcov.info
91+
env:
92+
RUST_BACKTRACE: 1
93+
if: matrix.os != 'windows-2022'
94+
- name: Upload coverage to Codecov
95+
uses: codecov/codecov-action@eaaf4bedf32dbdc6b720b63067d99c4d77d6047d
96+
if: matrix.os != 'windows-2022'
97+
with:
98+
files: lcov.info
99+
fail_ci_if_error: false
100+
token: ${{ secrets.CODECOV_TOKEN }}
101+
slug: codecov/codecov-demo
102+
103+
build-qemu:
104+
name: QEMU build & test
105+
runs-on: "${{ matrix.os }}"
106+
strategy:
107+
matrix:
108+
include:
109+
- rust: stable
110+
os: ubuntu-latest
111+
features: ""
112+
target: "s390x-unknown-linux-gnu"
113+
gcc: "s390x-linux-gnu-gcc"
114+
runner: "qemu-s390x -L /usr/s390x-linux-gnu"
115+
- rust: stable
116+
os: ubuntu-latest
117+
features: ""
118+
target: "i686-unknown-linux-gnu"
119+
gcc: "i686-linux-gnu-gcc"
120+
steps:
121+
- name: Checkout sources
122+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
123+
with:
124+
persist-credentials: false
125+
submodules: true
126+
- uses: awalsh128/cache-apt-pkgs-action@latest
127+
with:
128+
packages: qemu-user qemu-user-static qemu-system-s390x gcc-s390x-linux-gnu gcc-i686-linux-gnu g++-s390x-linux-gnu
129+
version: 1.0
130+
- name: Copy QEMU Cargo Config
131+
run: |
132+
mkdir -p .cargo
133+
cp qemu-cargo-config.toml .cargo/config.toml
134+
- name: Install toolchain
135+
uses: dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248
136+
with:
137+
toolchain: "stable"
138+
targets: "${{ matrix.target }}"
139+
- name: target
140+
run: "rustc -vV | sed -n 's|host: ||p'"
141+
- name: Install cargo-nextest
142+
uses: taiki-e/install-action@56ab7930c591507f833cbaed864d201386d518a8
143+
with:
144+
tool: cargo-nextest
145+
- name: cargo build
146+
run: cargo build --target ${{matrix.target}} ${{ matrix.features }}
147+
- name: cargo nextest # reports segfaults in a helpful way
148+
run: RUNNER="${{ matrix.runner }}" cargo nextest run --target ${{matrix.target}} ${{ matrix.features }}
149+
env:
150+
RUST_BACKTRACE: 1
151+
CC: ${{matrix.gcc}}
152+
153+
clippy:
154+
name: Clippy
155+
strategy:
156+
matrix:
157+
include:
158+
- target: x86_64-unknown-linux-gnu
159+
features:
160+
- ""
161+
- '--no-default-features --features="c-allocator"'
162+
- '--no-default-features --features="rust-allocator"'
163+
runs-on: ubuntu-latest
164+
steps:
165+
- name: Checkout sources
166+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
167+
with:
168+
persist-credentials: false
169+
submodules: true
170+
- name: Install rust toolchain
171+
uses: dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248
172+
with:
173+
toolchain: stable
174+
components: clippy
175+
targets: ${{matrix.target}}
176+
- name: Rust cache
177+
uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8
178+
with:
179+
shared-key: "stable-${{matrix.target}}"
180+
181+
- name: Run clippy
182+
run: cargo clippy --target ${{matrix.target}} --workspace --all-targets -- -D warnings
183+
- name: Run clippy (fuzzers)
184+
run: cargo clippy --target ${{matrix.target}} --manifest-path ./fuzz/Cargo.toml --all-targets -- -D warnings
185+
if: ${{matrix.fuzzer}}
186+
187+
# fuzz:
188+
# name: Smoke-test fuzzing targets
189+
# runs-on: ubuntu-20.04
190+
# strategy:
191+
# matrix:
192+
# features:
193+
# - 'default'
194+
# - 'c-allocator'
195+
# - 'rust-allocator'
196+
# steps:
197+
# - name: Checkout sources
198+
# uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
199+
# with:
200+
# persist-credentials: false
201+
# submodules: true
202+
# - name: Install nightly toolchain
203+
# uses: dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248
204+
# with:
205+
# toolchain: nightly
206+
# - name: Install cargo fuzz
207+
# uses: taiki-e/install-action@56ab7930c591507f833cbaed864d201386d518a8
208+
# with:
209+
# tool: cargo-fuzz
210+
# - name: Smoke-test fuzz targets
211+
# run: |
212+
# cargo fuzz build --no-default-features --features="${{ matrix.features }}"
213+
# for target in $(cargo fuzz list); do
214+
# if [ "$target" = "uncompress2" ]; then
215+
# features="${{ matrix.features }} disable-checksum"
216+
# else
217+
# features="${{ matrix.features }}"
218+
# fi
219+
# RUST_BACKTRACE=1 cargo fuzz run --no-default-features --features="$features" $target -- -max_total_time=10
220+
# done
221+
222+
# fuzz-aarch64:
223+
# name: Smoke-test fuzzing targets
224+
# runs-on: macos-14
225+
# strategy:
226+
# matrix:
227+
# include:
228+
# - rust: "stable"
229+
# os: macos-14
230+
# features: ""
231+
# target: "aarch64-apple-darwin"
232+
# steps:
233+
# - name: Checkout sources
234+
# uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
235+
# with:
236+
# persist-credentials: false
237+
# submodules: true
238+
# - name: Install nightly toolchain
239+
# uses: dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248
240+
# with:
241+
# toolchain: nightly
242+
# - name: Install cargo fuzz
243+
# uses: taiki-e/install-action@56ab7930c591507f833cbaed864d201386d518a8
244+
# with:
245+
# tool: cargo-fuzz
246+
# - name: Smoke-test fuzz targets
247+
# run: |
248+
# cargo fuzz build --no-default-features --features="${{ matrix.features }}"
249+
# for target in $(cargo fuzz list); do
250+
# if [ "$target" = "uncompress2" ]; then
251+
# features="${{ matrix.features }} disable-checksum"
252+
# else
253+
# features="${{ matrix.features }}"
254+
# fi
255+
# RUST_BACKTRACE=1 cargo fuzz run --no-default-features --features="$features" $target -- -max_total_time=10
256+
# done
257+
#
258+
# link-c-dynamic-library:
259+
# name: dynamic library
260+
# strategy:
261+
# matrix:
262+
# include:
263+
# - target: x86_64-unknown-linux-gnu
264+
# features:
265+
# - ''
266+
# runs-on: ubuntu-latest
267+
# steps:
268+
# - name: Checkout sources
269+
# uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
270+
# with:
271+
# persist-credentials: false
272+
# submodules: true
273+
# - name: Install rust toolchain
274+
# uses: dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248
275+
# with:
276+
# toolchain: stable
277+
# targets: ${{matrix.target}}
278+
# - name: "cdylib: default settings"
279+
# working-directory: libz-rs-sys-cdylib
280+
# env:
281+
# LD_LIBRARY_PATH: "target/${{matrix.target}}/release/deps"
282+
# run: |
283+
# cargo build --release --target ${{matrix.target}}
284+
# cc -o zpipe zpipe.c target/${{matrix.target}}/release/deps/libz_rs.so
285+
# ./zpipe < Cargo.toml | ./zpipe -d > out.txt
286+
# cmp -s Cargo.toml out.txt
287+
# - name: "cdylib: rust-allocator"
288+
# env:
289+
# LD_LIBRARY_PATH: "target/${{matrix.target}}/release/deps"
290+
# working-directory: libz-rs-sys-cdylib
291+
# run: |
292+
# cargo build --release --target ${{matrix.target}} --no-default-features --features="rust-allocator"
293+
# cc -o zpipe zpipe.c target/${{matrix.target}}/release/deps/libz_rs.so
294+
# ./zpipe < Cargo.toml | ./zpipe -d > out.txt
295+
# cmp -s Cargo.toml out.txt
296+
# - name: "cdylib: no_std"
297+
# env:
298+
# LD_LIBRARY_PATH: "target/${{matrix.target}}/release/deps"
299+
# working-directory: libz-rs-sys-cdylib
300+
# run: |
301+
# cargo build --release --target ${{matrix.target}} --no-default-features
302+
# cc -o zpipe_no_std zpipe_no_std.c target/${{matrix.target}}/release/deps/libz_rs.so
303+
# ./zpipe_no_std < Cargo.toml | ./zpipe_no_std -d > out.txt
304+
# cmp -s Cargo.toml out.txt
305+
# - name: "cdylib: custom-prefix"
306+
# working-directory: libz-rs-sys-cdylib
307+
# env:
308+
# LIBZ_RS_SYS_PREFIX: "MY_CUSTOM_PREFIX_"
309+
# run: |
310+
# cargo build --release --target ${{matrix.target}} --features=custom-prefix
311+
# objdump -tT target/${{matrix.target}}/release/deps/libz_rs.so | grep -q "MY_CUSTOM_PREFIX_uncompress" || (echo "symbol not found!" && exit 1)
312+
313+
wasm32:
314+
name: "wasm32"
315+
runs-on: ubuntu-latest
316+
steps:
317+
- name: Checkout sources
318+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
319+
with:
320+
persist-credentials: false
321+
submodules: true
322+
- name: Install wasmtime
323+
run: curl https://wasmtime.dev/install.sh -sSf | bash
324+
- name: Copy .cargo/config.toml
325+
run: |
326+
mkdir -p .cargo
327+
cp qemu-cargo-config.toml .cargo/config.toml
328+
- name: Install toolchain
329+
uses: dtolnay/rust-toolchain@be73d7920c329f220ce78e0234b8f96b7ae60248
330+
with:
331+
toolchain: "stable"
332+
targets: "wasm32-wasip1"
333+
- name: target
334+
run: "rustc -vV | sed -n 's|host: ||p'"
335+
- name: Install cargo-nextest
336+
uses: taiki-e/install-action@56ab7930c591507f833cbaed864d201386d518a8
337+
with:
338+
tool: cargo-nextest
339+
- name: Download wasi-sdk
340+
run: |
341+
curl -L https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-24/wasi-sdk-24.0-x86_64-linux.tar.gz | tar xz
342+
- name: cargo nextest (without SIMD)
343+
run: |
344+
export CC="$(pwd)/wasi-sdk-24.0-x86_64-linux/bin/clang"
345+
export CFLAGS="-target wasm32-wasip1"
346+
cargo nextest run -p libbzip2-rs-sys -p test-libbzip2-rs-sys --target wasm32-wasip1 \
347+
-- --skip high_level_write --skip open_and_close # These tests use temp_dir
348+
env:
349+
RUST_BACKTRACE: 1
350+
RUSTFLAGS: ""
351+
352+
miri:
353+
name: "Miri"
354+
runs-on: ubuntu-latest
355+
steps:
356+
- name: Checkout sources
357+
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
358+
with:
359+
persist-credentials: false
360+
submodules: true
361+
- name: Install Miri
362+
run: |
363+
rustup toolchain install nightly --component miri
364+
cargo +nightly miri setup
365+
- name: Install cargo-nextest
366+
uses: taiki-e/install-action@56ab7930c591507f833cbaed864d201386d518a8
367+
with:
368+
tool: cargo-nextest
369+
- name: Test public C api with NULL arguments
370+
run: "cargo +nightly miri nextest run -j4 -p test-libbzip2-rs-sys null::"
371+
env:
372+
RUSTFLAGS: "-Ctarget-feature=+avx2"
373+
- name: Test allocator with miri
374+
run: "cargo +nightly miri nextest run -j4 -p libbzip2-rs-sys allocate::"

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ authors = ["C2Rust"]
1212
version = "0.0.0"
1313
publish = false
1414
edition = "2021"
15+
rust-version = "1.82" # MSRV
1516

1617
[[bin]]
1718
name = "bzip2"

qemu-cargo-config.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# gets copied to .cargo/config.toml on CI, meant to run tests under qemu
2+
3+
[target.s390x-unknown-linux-gnu]
4+
runner = "qemu-s390x -L /usr/s390x-linux-gnu"
5+
linker = "s390x-linux-gnu-gcc"
6+
7+
[target.i686-unknown-linux-gnu]
8+
linker = "i686-linux-gnu-gcc"
9+
10+
[target.wasm32-wasip1]
11+
runner = "/home/runner/.wasmtime/bin/wasmtime run --dir ../tests"

0 commit comments

Comments
 (0)