Skip to content

Commit 8d8e362

Browse files
mtjhrcslp
authored andcommitted
CI: Refactor CI, drop actions-rs/toolchain@v1
Drop the usage of 'actions-rs/toolchain@v1` which doesn't seem to be maintained anymore (the repository is archived). Instead let's follow the official guide by GitHub on building Rust projects[1]. In order to not duplicate the code, introduce a custom GitHub Action to set up our build env, including native libraries and rust toolchain. Split the github workflows into 4 files: - formatting.yml - Linux only - rustfmt nor clang-format shall be be effected by target platform, they don't process conditional compilation (previously was checked on multiple platforms) - intergation-tests.yml - runs integration tests (Linux x86_64 only, because of GitHub limitations) - unit-tests.yml - still x86_64 Linux only for now - code-quality.yml - runs `cargo clippy` on Linux (x86_64, aarch64) and macOS with respective supported features [1]: https://docs.github.com/en/actions/tutorials/build-and-test-code/rust Signed-off-by: Matej Hrica <[email protected]>
1 parent 186c220 commit 8d8e362

File tree

8 files changed

+178
-167
lines changed

8 files changed

+178
-167
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: 'Setup Build Environment'
2+
description: 'Common setup for Rust builds with all required packages (Linux & macOS)'
3+
runs:
4+
using: 'composite'
5+
steps:
6+
- name: Install Rust toolchain
7+
shell: bash
8+
run: |
9+
rustup update stable
10+
rustup default stable
11+
rustup component add rustfmt clippy
12+
13+
- name: Cache Cargo dependencies
14+
uses: actions/cache@v4
15+
with:
16+
path: |
17+
~/.cargo/registry
18+
~/.cargo/git
19+
target
20+
key: ${{ runner.os }}-${{ runner.arch }}-cargo-${{ hashFiles('**/Cargo.lock') }}
21+
22+
- name: Set up Homebrew (macOS)
23+
if: runner.os == 'macOS'
24+
uses: Homebrew/actions/setup-homebrew@master
25+
26+
- name: Install packages (macOS)
27+
if: runner.os == 'macOS'
28+
shell: bash
29+
run: brew tap slp/krunkit && brew install virglrenderer clang-format llvm
30+
31+
- name: Install packages (Linux)
32+
if: runner.os == 'Linux'
33+
shell: bash
34+
run: |
35+
sudo apt-get update
36+
sudo apt-get install -y \
37+
libvirglrenderer-dev \
38+
libepoxy-dev \
39+
libdrm-dev \
40+
libpipewire-0.3-dev \
41+
clang-format \
42+
libclang-dev

.github/workflows/code-quality.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Code Quality
2+
on: [pull_request]
3+
4+
jobs:
5+
code-quality-linux-x86_64:
6+
name: Linux x86_64
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
11+
- name: Setup build environment
12+
uses: ./.github/actions/setup-build-env
13+
14+
- name: Create a fake init
15+
run: touch init/init
16+
17+
- name: Clippy (default)
18+
run: cargo clippy -- -D warnings
19+
20+
- name: Clippy (amd-sev)
21+
run: cargo clippy --features amd-sev -- -D warnings
22+
23+
- name: Clippy (tdx)
24+
run: cargo clippy --features tdx -- -D warnings
25+
26+
- name: Clippy (net+blk+gpu+snd)
27+
run: cargo clippy --features net,blk,gpu,snd -- -D warnings
28+
29+
code-quality-linux-aarch64:
30+
name: Linux aarch64
31+
runs-on: ubuntu-24.04-arm
32+
steps:
33+
- uses: actions/checkout@v4
34+
35+
- name: Setup build environment
36+
uses: ./.github/actions/setup-build-env
37+
38+
- name: Create a fake init
39+
run: touch init/init
40+
41+
- name: Clippy (default)
42+
run: cargo clippy -- -D warnings
43+
44+
- name: Clippy (net+blk+gpu+snd)
45+
run: cargo clippy --features net,blk,gpu,snd -- -D warnings
46+
47+
code-quality-macos:
48+
name: macOS aarch64
49+
runs-on: macos-latest
50+
steps:
51+
- uses: actions/checkout@v4
52+
53+
- name: Setup build environment
54+
uses: ./.github/actions/setup-build-env
55+
56+
- name: Create a fake init
57+
run: touch init/init
58+
59+
- name: Clippy (efi+gpu)
60+
run: cargo clippy --features efi,gpu -- -D warnings

.github/workflows/code_quality-aarch64-darwin.yml

Lines changed: 0 additions & 35 deletions
This file was deleted.

.github/workflows/code_quality-aarch64.yml

Lines changed: 0 additions & 34 deletions
This file was deleted.

.github/workflows/code_quality-x86_64.yml

Lines changed: 0 additions & 98 deletions
This file was deleted.

.github/workflows/formatting.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Code Formatting
2+
on: [pull_request]
3+
4+
jobs:
5+
formatting:
6+
name: clang-format + cargo fmt
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
11+
- name: Setup build environment
12+
uses: ./.github/actions/setup-build-env
13+
14+
- name: C code formatting
15+
run: find init -iname '*.h' -o -iname '*.c' | xargs clang-format -n -Werror
16+
17+
- name: Rust code formatting
18+
run: cargo fmt -- --check
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Integration tests
2+
on: [pull_request]
3+
4+
jobs:
5+
# x86_64 only due to virtualization limitations of GitHub Actions
6+
integration-tests:
7+
name: Integration Tests (Linux x86_64)
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v4
11+
12+
- name: Setup build environment
13+
uses: ./.github/actions/setup-build-env
14+
15+
- name: Add musl target
16+
run: rustup target add x86_64-unknown-linux-musl
17+
18+
- name: Enable KVM group perms
19+
run: |
20+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
21+
sudo udevadm control --reload-rules
22+
sudo udevadm trigger --name-match=kvm
23+
sudo usermod -a -G kvm $USER
24+
25+
- name: Install additional packages
26+
run: sudo apt-get install -y --no-install-recommends build-essential patchelf pkg-config net-tools
27+
28+
- name: Install libkrunfw
29+
run: curl -L -o /tmp/libkrunfw-4.9.0-x86_64.tgz https://github.com/containers/libkrunfw/releases/download/v4.9.0/libkrunfw-4.9.0-x86_64.tgz && mkdir tmp && tar xf /tmp/libkrunfw-4.9.0-x86_64.tgz -C tmp && sudo mv tmp/lib64/* /lib/x86_64-linux-gnu
30+
31+
- name: Integration tests
32+
run: RUST_LOG=trace KRUN_ENOMEM_WORKAROUND=1 KRUN_NO_UNSHARE=1 make test

.github/workflows/unit_tests.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Tests
2+
on: [pull_request]
3+
4+
jobs:
5+
unit-tests:
6+
name: Unit tests (${{ matrix.name }})
7+
runner: ubuntu-latest
8+
runs-on: ${{ matrix.runner }}
9+
steps:
10+
- uses: actions/checkout@v4
11+
12+
- name: Setup build environment
13+
uses: ./.github/actions/setup-build-env
14+
15+
- name: Create a fake init
16+
run: touch init/init
17+
18+
- name: Enable KVM group perms
19+
run: |
20+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
21+
sudo udevadm control --reload-rules
22+
sudo udevadm trigger --name-match=kvm
23+
sudo usermod -a -G kvm $USER
24+
25+
- name: Unit tests
26+
run: cargo test

0 commit comments

Comments
 (0)