Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add plugins API V4 #21

Merged
merged 10 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
256 changes: 87 additions & 169 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,23 @@ env:
CARGO_TERM_COLOR: always

jobs:
test_plugins_linux_v1:
name: Build and Test Plugins API v1 (Linux)
test_plugins_linux:
name: Build and Test Plugins API v${{ matrix.version }} (Linux)
runs-on: ubuntu-latest
container: ubuntu:24.04
strategy:
matrix:
include:
- version: 1
commit: fb691b8cbabf5bde7d25a7f720d5ec7d5b1341e1
- version: 2
commit: fba3b490a26cb278dfa183d7fcc375746e312980
- version: 3
commit: 7de77d37880d7267a491cb32a1b2232017d1e545
- version: 4
commit: cfa3a6c54511374e9ccee26d9c38ac1698fc7af2
env:
# Hash of v1
QEMU_COMMIT_HASH: fb691b8cbabf5bde7d25a7f720d5ec7d5b1341e1
QEMU_COMMIT_HASH: ${{ matrix.commit }}
steps:
- name: Set up Sources List
run: |
Expand Down Expand Up @@ -45,98 +55,43 @@ jobs:
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
EOF
- name: Install QEMU Build Dependencies
run: |
apt -y update && \
apt -y install git curl build-essential && \
apt -y source qemu && \
apt -y build-dep qemu

# Clone without history
- name: Clone QEMU
run: |
git clone https://github.com/qemu/qemu qemu-upstream
cd qemu-upstream
git checkout "${QEMU_COMMIT_HASH}"

- name: Build QEMU
run: |
cd qemu-upstream
./configure --enable-plugins
cd build
make -j$(nproc)
make install
cd ../..

- uses: dtolnay/rust-toolchain@nightly
- uses: actions/checkout@v4
- name: Test QEMU Install
run: |
qemu-x86_64 --help
- name: Build and Test Tracer
run: |
cd plugins/tracer
cargo build -r --features=plugin-api-v1 --no-default-features || exit 0
cargo build -r --features=plugin-api-v1 --no-default-features
cargo run --features=plugin-api-v1 --no-default-features -r --bin tracer -- -a /bin/ls -- -lah
cd ../..
- name: Build and Test Tiny
run: |
cd plugins/tiny
cargo build -r --features=plugin-api-v1 --no-default-features
qemu-x86_64 -plugin ../../target/release/libtiny.so /bin/ls -lah
cd ../..

test_plugins_linux_v2:
name: Build and Test Plugins API v2 (Linux)
runs-on: ubuntu-latest
container: ubuntu:24.04
env:
# Hash of v2
QEMU_COMMIT_HASH: fba3b490a26cb278dfa183d7fcc375746e312980
steps:
- name: Set up Sources List
run: |
cat <<EOF > /etc/apt/sources.list.d/ubuntu.sources
Types: deb
URIs: http://archive.ubuntu.com/ubuntu/
Suites: noble noble-updates noble-backports
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

Types: deb-src
URIs: http://archive.ubuntu.com/ubuntu/
Suites: noble noble-updates noble-backports
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
# Cache apt packages
- name: Cache APT packages
id: apt-cache
uses: actions/cache@v3
with:
path: /var/cache/apt/archives
key: ${{ runner.os }}-apt-${{ hashFiles('/etc/apt/sources.list.d/ubuntu.sources') }}

Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
EOF
- name: Install QEMU Build Dependencies
run: |
apt -y update && \
apt -y install git curl build-essential && \
apt -y source qemu && \
apt -y update
apt -y install git curl build-essential
apt -y source qemu
apt -y build-dep qemu

# Clone without history
# Cache QEMU source and build
- name: Cache QEMU
id: qemu-cache
uses: actions/cache@v3
with:
path: |
qemu-upstream
qemu-upstream/build
key: ${{ runner.os }}-qemu-v${{ matrix.version }}-${{ matrix.commit }}

# Clone only if cache miss
- name: Clone QEMU
if: steps.qemu-cache.outputs.cache-hit != 'true'
run: |
git clone https://github.com/qemu/qemu qemu-upstream
git clone https://gitlab.com/qemu/qemu qemu-upstream
cd qemu-upstream
git checkout "${QEMU_COMMIT_HASH}"

# Build only if cache miss
- name: Build QEMU
if: steps.qemu-cache.outputs.cache-hit != 'true'
run: |
cd qemu-upstream
./configure --enable-plugins
Expand All @@ -147,110 +102,45 @@ jobs:

- uses: dtolnay/rust-toolchain@nightly
- uses: actions/checkout@v4
- name: Test QEMU Install
run: |
qemu-x86_64 --help
- name: Build and Test Tracer
run: |
cd plugins/tracer
cargo build -r --features=plugin-api-v2 --no-default-features || exit 0
cargo build -r --features=plugin-api-v2 --no-default-features
cargo run --features=plugin-api-v2 --no-default-features -r --bin tracer -- -a /bin/ls -- -lah
cd ../..
- name: Build and Test Tiny
run: |
cd plugins/tiny
cargo build -r --features=plugin-api-v2 --no-default-features
qemu-x86_64 -plugin ../../target/release/libtiny.so /bin/ls -lah
cd ../..

test_plugins_linux_v3:
name: Build and Test Plugins API V3 (Linux)
runs-on: ubuntu-latest
container: ubuntu:24.04
env:
# Hash of v3
QEMU_COMMIT_HASH: 7de77d37880d7267a491cb32a1b2232017d1e545
steps:
- name: Set up Sources List
run: |
cat <<EOF > /etc/apt/sources.list.d/ubuntu.sources
Types: deb
URIs: http://archive.ubuntu.com/ubuntu/
Suites: noble noble-updates noble-backports
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

Types: deb-src
URIs: http://archive.ubuntu.com/ubuntu/
Suites: noble noble-updates noble-backports
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg

Types: deb
URIs: http://security.ubuntu.com/ubuntu/
Suites: noble-security
Components: main universe restricted multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
EOF
- name: Install QEMU Build Dependencies
run: |
apt -y update && \
apt -y install git curl build-essential && \
apt -y source qemu && \
apt -y build-dep qemu

# Clone without history
- name: Clone QEMU
run: |
git clone https://github.com/qemu/qemu qemu-upstream
cd qemu-upstream
git checkout "${QEMU_COMMIT_HASH}"

- name: Build QEMU
run: |
cd qemu-upstream
./configure --enable-plugins
cd build
make -j$(nproc)
make install
cd ../..
# Cache Rust dependencies
- name: Cache Rust dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-rust-v${{ matrix.version }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-rust-v${{ matrix.version }}-

- uses: dtolnay/rust-toolchain@nightly
- uses: actions/checkout@v4
- name: Test QEMU Install
run: |
qemu-x86_64 --help

- name: Build and Test Tracer
run: |
cd plugins/tracer
cargo build -r --features=plugin-api-v3 --no-default-features || exit 0
cargo build -r --features=plugin-api-v3 --no-default-features
cargo run --features=plugin-api-v3 --no-default-features -r --bin tracer -- -a /bin/ls -- -lah
cargo build -r --features=plugin-api-v${{ matrix.version }} --no-default-features || exit 0
cargo build -r --features=plugin-api-v${{ matrix.version }} --no-default-features
cargo run --features=plugin-api-v${{ matrix.version }} --no-default-features -r --bin tracer -- -a /bin/ls -- -lah
cd ../..

- name: Build and Test Tiny
run: |
cd plugins/tiny
cargo build -r --features=plugin-api-v3 --no-default-features
cargo build -r --features=plugin-api-v${{ matrix.version }} --no-default-features
qemu-x86_64 -plugin ../../target/release/libtiny.so /bin/ls -lah
cd ../..

test_plugins_windows:
name: Build and Test Plugins (Windows)
runs-on: windows-latest
env:
# QEMU 9.0.0
# NOTE: This installer does not work headless
# QEMU_URL: "https://qemu.weilnetz.de/w64/2023/qemu-w64-setup-20231224.exe"
QEMU_VERSION: 9.1.2-1
RUSTUP_URL: "https://win.rustup.rs/x86_64"
FEDORA_CLOUDIMG_URL: "https://download.fedoraproject.org/pub/fedora/linux/releases/39/Cloud/x86_64/images/Fedora-Cloud-Base-39-1.5.x86_64.qcow2"

steps:
- uses: msys2/setup-msys2@v2
with:
Expand All @@ -259,6 +149,13 @@ jobs:
install: git mingw-w64-ucrt-x86_64-gcc
location: C:\msys-custom

# Cache MSYS2 packages
- name: Cache MSYS2 packages
uses: actions/cache@v3
with:
path: C:\msys-custom\msys64\var\cache\pacman\pkg
key: ${{ runner.os }}-msys2-${{ env.QEMU_VERSION }}

- name: Download and Install Rust
run: |
$ProgressPreference = 'SilentlyContinue'
Expand All @@ -269,20 +166,41 @@ jobs:
shell: msys2 {0}
run: |
pacman -Syu --noconfirm
pacman -Sy mingw-w64-ucrt-x86_64-qemu --noconfirm
pacman -Sy mingw-w64-ucrt-x86_64-qemu=${QEMU_VERSION} --noconfirm

- name: Test QEMU
run: |
C:\msys-custom\msys64\ucrt64\bin\qemu-system-x86_64.exe --version

- uses: actions/checkout@v4

# Cache downloaded Fedora image
- name: Cache Fedora Cloud Image
id: fedora-cache
uses: actions/cache@v3
with:
path: Fedora-Cloud-Base-39-1.5.x86_64.qcow2
key: fedora-cloud-39-1.5

- name: Download Cloud Image
if: steps.fedora-cache.outputs.cache-hit != 'true'
run: |
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri ${{ env.FEDORA_CLOUDIMG_URL }} -OutFile Fedora-Cloud-Base-39-1.5.x86_64.qcow2
ls

# Cache Rust dependencies for Windows
- name: Cache Rust dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-rust-

- name: Build and Test Tiny
run: |
cd plugins/tiny-system
Expand All @@ -294,4 +212,4 @@ jobs:
echo "Stopping process"
Stop-Process -Id $process.id -ErrorAction SilentlyContinue
cat out.txt
cat err.txt
cat err.txt
10 changes: 4 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ categories = ["virtualization", "emulator", "qemu"]
description = "Rust bindings and binary installers for QEMU"
edition = "2021"
homepage = "https://github.com/novafacing/qemu-rs"
license = "GPL-2.0-only"
license = "GPL-2.0-or-later"
publish = true
readme = "README.md"
repository = "https://github.com/novafacing/qemu-rs"
version = "9.0.0-v0"
version = "9.2.0-v0"

[workspace]
resolver = "2"
members = [
"qemu",
"qemu-plugin",
"qemu-plugin-sys",
"plugins/tiny",
Expand All @@ -23,6 +22,5 @@ members = [
default-members = ["qemu-plugin", "qemu-plugin-sys"]

[workspace.dependencies]
qemu-plugin-sys = { version = "9.0.0-v0", path = "qemu-plugin-sys", default-features = false }
qemu-plugin = { version = "9.0.0-v0", path = "qemu-plugin", default-features = false }
qemu = { version = "9.0.0-v0", path = "qemu" }
qemu-plugin-sys = { version = "9.2.0-v0", path = "qemu-plugin-sys", default-features = false }
qemu-plugin = { version = "9.2.0-v0", path = "qemu-plugin", default-features = false }
18 changes: 1 addition & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,4 @@ and instructions) of a program like:

```sh
cargo run -r --bin tracer -- -a /bin/ls -- -lah
```

## Installing QEMU

This repository also provides a crate (`qemu`) which builds QEMU from source and
installs Rust wrappers for QEMU as binaries.

You can install QEMU with (add any additional features you need, e.g. `plugins`):

```sh
cargo install [email protected] --features=binaries
```

On some systems, particularly BTRFS systems, `/tmp` may not be large enough for the
temporary build directory (QEMU is quite large to build). In this case, create a
directory on your root filesystem (e.g. `$HOME/.cargo/tmp`) and set
`CARGO_TARGET_DIR=$HOME/.cargo/tmp` when running the install command.
```
Loading
Loading