Skip to content

Commit

Permalink
Merge pull request #244 from Wenzel/fix/ci
Browse files Browse the repository at this point in the history
build.rs: fix println
  • Loading branch information
Wenzel authored Feb 21, 2024
2 parents 5d9f543 + ddce5a9 commit 76735de
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 94 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,10 @@ jobs:
toolchain: stable
components: clippy

- name: Set up Python 3.7 🐍
- name: Set up Python 3.8 🐍
uses: actions/setup-python@v1
with:
python-version: '3.7'
python-version: '3.8'

- uses: actions/checkout@v1

Expand Down Expand Up @@ -328,10 +328,6 @@ jobs:
- name: smoke test
run: python3 -c 'from microvmi import Microvmi, DriverType, CommonInitParamsPy, DriverInitParamsPy, KVMInitParamsPy'

# setup docker cache to speedup rest of the job
- name: Docker Layer Caching
uses: satackey/action-docker-layer-caching@v0.0.11

- name: Build Wheels with manylinux
run: nox -r -s generate_wheels -- --features xen,kvm,virtualbox,mflow --release
working-directory: python
Expand Down
98 changes: 93 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 29 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ crate-type = ["cdylib", "lib"]

[features]
# Xen driver
xen = ["xenctrl", "xenstore-rs", "xenforeignmemory", "xenevtchn", "xenvmevent-sys", "libc"]
xen = [
"xenctrl",
"xenstore-rs",
"xenforeignmemory",
"xenevtchn",
"xenvmevent-sys",
"libc",
]
# KVM driver
kvm = ["kvmi"]
# VirtualBox driver
Expand All @@ -34,17 +41,24 @@ nix = "^0.23.0"
enum-iterator = "0.7.0"
thiserror = "1.0"
libc = { version = "0.2.58", optional = true }
xenctrl = { version = "=0.4.7", optional = true }
xenctrl = { version = "=0.6.0", optional = true }
xenstore-rs = { version = "=0.3.2", optional = true }
xenforeignmemory = { version = "=0.2.3", optional = true }
xenevtchn = { version = "=0.1.6", optional = true }
xenvmevent-sys = { version = "=0.1.3", optional = true }
kvmi = { version = "0.4.0", optional = true }
fdp = { version = "=0.2.5", optional = true }
winapi = { version = "0.3", features = ["tlhelp32", "winnt", "handleapi", "securitybaseapi"], optional = true }
winapi = { version = "0.3", features = [
"tlhelp32",
"winnt",
"handleapi",
"securitybaseapi",
], optional = true }
widestring = { version = "0.4", optional = true }
ntapi = { version = "0.3", optional = true }
vid-sys = { version = "=0.3.0", features = ["deprecated-apis"], optional = true }
vid-sys = { version = "=0.3.0", features = [
"deprecated-apis",
], optional = true }
memflow = { version = "0.1.5", optional = true }

[dev-dependencies]
Expand Down Expand Up @@ -78,8 +92,16 @@ section = "libs"
priority = "optional"
# add generated libmicrovmi.h header
assets = [
["target/release/libmicrovmi.so", "usr/lib/libmicrovmi.so", "644"],
["target/release/capi/libmicrovmi.h", "usr/include/libmicrovmi.h", "644"],
[
"target/release/libmicrovmi.so",
"usr/lib/libmicrovmi.so",
"644",
],
[
"target/release/capi/libmicrovmi.h",
"usr/include/libmicrovmi.h",
"644",
],
]

[package.metadata.release]
Expand All @@ -89,6 +111,4 @@ assets = [
disable-publish = true

[workspace]
members = [
"python"
]
members = ["python"]
5 changes: 1 addition & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,5 @@ fn main() {

println!("cargo:rerun-if-changed=src/capi.rs");
// if it has been removed
println!(
"{}",
format!("cargo:rerun-if-changed={}", &out_path.display())
);
println!("cargo:rerun-if-changed={}", &out_path.display());
}
4 changes: 2 additions & 2 deletions python/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
CUR_DIR = Path(__file__).parent

# default sessions for nox
nox.options.sessions = ["fmt", "lint", "type", "test"]
nox.options.sessions = ["fmt", "lint", "test"]


@nox.session
def fmt(session):
session.install("black==20.8b1")
session.install("black==24.2.0")
# note: black doesn't support setup.cfg
# so we hardcode the config here
session.run("black", "--line-length", "120", ".")
Expand Down
4 changes: 2 additions & 2 deletions python/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
setuptools-rust
setuptools==65.5.1
setuptools-rust==1.1.2
setuptools==59.6.0
wheel
toml==0.10.2
4 changes: 2 additions & 2 deletions python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ impl MicrovmiExt {
size: usize,
) -> PyResult<(&'p PyBytes, u64)> {
let mut bytes_read: u64 = 0;
let pybuffer: &PyBytes = PyBytes::new_with(py, size, |mut buffer| {
let pybuffer: &PyBytes = PyBytes::new_with(py, size, |buffer| {
self.driver
.read_physical(paddr, &mut buffer, &mut bytes_read)
.read_physical(paddr, buffer, &mut bytes_read)
.ok();
Ok(())
})?;
Expand Down
24 changes: 14 additions & 10 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ pub mod events;
pub mod params;
pub mod registers;

bitflags! {
pub struct Access: u32 {
const R=0b00000001;
const W=0b00000010;
const X=0b00000100;
const NIL=0b00000000;
const RW=Self::R.bits | Self::W.bits;
const WX=Self::W.bits | Self::X.bits;
const RX=Self::R.bits | Self::X.bits;
const RWX=Self::R.bits | Self::W.bits | Self::X.bits;
#[allow(clippy::bad_bit_mask)]
mod flags {
bitflags! {
pub struct Access: u32 {
const NIL=0b00000000;
const R=0b00000001;
const W=0b00000010;
const X=0b00000100;
const RW=Self::R.bits | Self::W.bits;
const WX=Self::W.bits | Self::X.bits;
const RX=Self::R.bits | Self::X.bits;
const RWX=Self::R.bits | Self::W.bits | Self::X.bits;
}
}
}
pub use flags::Access;

///Represents the available hypervisor VMI drivers supported by libmicrovmi
#[repr(C)]
Expand Down
13 changes: 5 additions & 8 deletions src/driver/kvm.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use std::convert::From;
use std::convert::TryFrom;
use std::convert::TryInto;
use std::error::Error;
use std::mem;
use std::vec::Vec;

use kvmi::constants::PAGE_SIZE;
#[cfg(test)] // only needed for tests
Expand Down Expand Up @@ -130,7 +127,7 @@ impl<T: KVMIntrospectable> Kvm<T> {

// set vec_events size
let vcpu_count = kvm.get_vcpu_count()?;
kvm.vec_events.resize_with(vcpu_count.try_into()?, || None);
kvm.vec_events.resize_with(vcpu_count.into(), || None);

// enable CR event intercept by default
// (interception will take place when CR register will be specified)
Expand Down Expand Up @@ -323,7 +320,7 @@ impl<T: KVMIntrospectable> Introspectable for Kvm<T> {
};

let vcpu = kvmi_event.vcpu;
let vcpu_index: usize = vcpu.try_into()?;
let vcpu_index: usize = vcpu.into();
self.vec_events[vcpu_index] = Some(kvmi_event);

Ok(Some(Event {
Expand All @@ -343,9 +340,9 @@ impl<T: KVMIntrospectable> Introspectable for Kvm<T> {
EventReplyType::Continue => KVMiEventReply::Continue,
};
// get KVMiEvent associated with this VCPU
let vcpu_index: usize = event.vcpu.try_into()?;
let kvmi_event = mem::replace(&mut self.vec_events[vcpu_index], None).unwrap();
Ok(self.kvmi.reply(&kvmi_event, kvm_reply_type)?)
let vcpu_index: usize = event.vcpu.into();
let kvmi_event = &mut self.vec_events[vcpu_index].take().unwrap();
Ok(self.kvmi.reply(kvmi_event, kvm_reply_type)?)
}

fn get_driver_type(&self) -> DriverType {
Expand Down
Loading

0 comments on commit 76735de

Please sign in to comment.