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

xen: Gate xen behind cfg instead of feature #308

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
20 changes: 10 additions & 10 deletions .buildkite/custom-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"tests": [
{
"test_name": "build-gnu-mmap",
"command": "cargo build --release --features=xen",
"command": "XEN=ENABLE cargo build --release",
"platform": ["x86_64", "aarch64"]
},
{
Expand All @@ -12,7 +12,7 @@
},
{
"test_name": "build-musl-mmap",
"command": "cargo build --release --features=xen --target {target_platform}-unknown-linux-musl",
"command": "XEN=ENABLE cargo build --release --target {target_platform}-unknown-linux-musl",
"platform": ["x86_64", "aarch64"]
},
{
Expand All @@ -26,32 +26,32 @@
"platform": ["x86_64", "aarch64"]
},
{
"test_name": "unittests-gnu-no-xen",
"command": "cargo test --features 'backend-bitmap backend-mmap backend-atomic' --workspace",
"test_name": "unittests-gnu-xen",
"command": "XEN=ENABLE cargo test --workspace",
"platform": [
"x86_64",
"aarch64"
]
},
{
"test_name": "unittests-musl-no-xen",
"command": "cargo test --features 'backend-bitmap backend-mmap backend-atomic' --workspace --target {target_platform}-unknown-linux-musl",
"test_name": "unittests-musl-xen",
"command": "XEN=ENABLE cargo test --workspace --target {target_platform}-unknown-linux-musl",
"platform": [
"x86_64",
"aarch64"
]
},
{
"test_name": "clippy-no-xen",
"command": "cargo clippy --workspace --bins --examples --benches --features 'backend-bitmap backend-mmap backend-atomic' --all-targets -- -D warnings -D clippy::undocumented_unsafe_blocks",
"test_name": "clippy-xen",
"command": "XEN=ENABLE cargo clippy --workspace --bins --examples --benches --all-targets -- -D warnings -D clippy::undocumented_unsafe_blocks",
"platform": [
"x86_64",
"aarch64"
]
},
{
"test_name": "check-warnings-no-xen",
"command": "RUSTFLAGS=\"-D warnings\" cargo check --all-targets --features 'backend-bitmap backend-mmap backend-atomic' --workspace",
"test_name": "check-warnings-xen",
"command": "RUSTFLAGS=\"-D warnings\" XEN=ENABLE cargo check --all-targets --features 'backend-bitmap backend-mmap backend-atomic' --workspace",
"platform": [
"x86_64",
"aarch64"
Expand Down
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ default = []
backend-bitmap = []
backend-mmap = []
backend-atomic = ["arc-swap"]
xen = ["backend-mmap", "bitflags", "vmm-sys-util"]

[dependencies]
libc = "0.2.39"
arc-swap = { version = "1.0.0", optional = true }
bitflags = { version = "2.4.0", optional = true }
bitflags = { version = "2.4.0" }
thiserror = "1.0.40"
vmm-sys-util = { version = "0.12.1", optional = true }
vmm-sys-util = { version = "0.12.1" }

[target.'cfg(windows)'.dependencies.winapi]
version = "0.3"
Expand Down
8 changes: 4 additions & 4 deletions benches/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
extern crate criterion;

pub use criterion::{black_box, criterion_group, criterion_main, Criterion};
#[cfg(feature = "backend-mmap")]
#[cfg(any(feature = "backend-mmap", all(xen, unix)))]
use vm_memory::{GuestAddress, GuestMemoryMmap};

mod guest_memory;
Expand All @@ -14,7 +14,7 @@ mod volatile;

use volatile::benchmark_for_volatile;

#[cfg(feature = "backend-mmap")]
#[cfg(any(feature = "backend-mmap", all(xen, unix)))]
// Use this function with caution. It does not check against overflows
// and `GuestMemoryMmap::from_ranges` errors.
fn create_guest_memory_mmap(size: usize, count: u64) -> GuestMemoryMmap<()> {
Expand All @@ -27,12 +27,12 @@ fn create_guest_memory_mmap(size: usize, count: u64) -> GuestMemoryMmap<()> {
}

pub fn criterion_benchmark(_c: &mut Criterion) {
#[cfg(feature = "backend-mmap")]
#[cfg(any(feature = "backend-mmap", all(xen, unix)))]
mmap::benchmark_for_mmap(_c);
}

pub fn benchmark_guest_memory(_c: &mut Criterion) {
#[cfg(feature = "backend-mmap")]
#[cfg(any(feature = "backend-mmap", all(xen, unix)))]
guest_memory::benchmark_for_guest_memory(_c)
}

Expand Down
16 changes: 16 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
fn main() {
// Define a `xen` attribute, which is used for conditional
// compilation of "xen".
println!("cargo:rustc-check-cfg=cfg(xen)");
// `xen` would be enabled with `XEN=ENABLE`
if let Ok(xen) = std::env::var("XEN") {
match xen.as_str() {
"ENABLE" => {
println!("cargo:rustc-cfg=xen");
}
_ => {
eprintln!("XEN environment variable is provided but not enabled, if you want to compile with XEN please use `XEN=ENABLE`");
}
}
}
}
2 changes: 1 addition & 1 deletion src/atomic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl<M: GuestMemory> GuestMemoryExclusiveGuard<'_, M> {
}

#[cfg(test)]
#[cfg(feature = "backend-mmap")]
#[cfg(any(feature = "backend-mmap", all(xen, unix)))]
mod tests {
use super::*;
use crate::{GuestAddress, GuestMemory, GuestMemoryRegion, GuestUsize, MmapRegion};
Expand Down
4 changes: 2 additions & 2 deletions src/bitmap/backend/atomic_bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::sync::atomic::{AtomicU64, Ordering};

use crate::bitmap::{Bitmap, RefSlice, WithBitmapSlice};

#[cfg(feature = "backend-mmap")]
#[cfg(any(feature = "backend-mmap", all(xen, unix)))]
use crate::mmap::NewBitmap;

/// `AtomicBitmap` implements a simple bit map on the page level with test and set operations.
Expand Down Expand Up @@ -191,7 +191,7 @@ impl Default for AtomicBitmap {
}
}

#[cfg(feature = "backend-mmap")]
#[cfg(any(feature = "backend-mmap", all(xen, unix)))]
impl NewBitmap for AtomicBitmap {
fn with_len(len: usize) -> Self {
#[cfg(unix)]
Expand Down
4 changes: 2 additions & 2 deletions src/bitmap/backend/atomic_bitmap_arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::sync::Arc;

use crate::bitmap::{ArcSlice, AtomicBitmap, Bitmap, WithBitmapSlice};

#[cfg(feature = "backend-mmap")]
#[cfg(any(feature = "backend-mmap", all(xen, unix)))]
use crate::mmap::NewBitmap;

/// A `Bitmap` implementation that's based on an atomically reference counted handle to an
Expand Down Expand Up @@ -65,7 +65,7 @@ impl Default for AtomicBitmapArc {
}
}

#[cfg(feature = "backend-mmap")]
#[cfg(any(feature = "backend-mmap", all(xen, unix)))]
impl NewBitmap for AtomicBitmapArc {
fn with_len(len: usize) -> Self {
Self::new(AtomicBitmap::with_len(len))
Expand Down
6 changes: 3 additions & 3 deletions src/bitmap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ pub(crate) mod tests {
use std::sync::atomic::Ordering;

use crate::{Bytes, VolatileMemory};
#[cfg(feature = "backend-mmap")]
#[cfg(any(feature = "backend-mmap", all(xen, unix)))]
use crate::{GuestAddress, MemoryRegionAddress};

// Helper method to check whether a specified range is clean.
Expand Down Expand Up @@ -297,7 +297,7 @@ pub(crate) mod tests {
// them to test the mmap-based backend implementations for now. Going forward, the generic
// test functions defined here can be placed in a separate module (i.e. `test_utilities`)
// which is gated by a feature and can be used for testing purposes by other crates as well.
#[cfg(feature = "backend-mmap")]
#[cfg(any(feature = "backend-mmap", all(xen, unix)))]
fn test_guest_memory_region<R: GuestMemoryRegion>(region: &R) {
let dirty_addr = MemoryRegionAddress(0x0);
let val = 123u64;
Expand Down Expand Up @@ -331,7 +331,7 @@ pub(crate) mod tests {
);
}

#[cfg(feature = "backend-mmap")]
#[cfg(any(feature = "backend-mmap", all(xen, unix)))]
// Assumptions about M generated by f ...
pub fn test_guest_memory_and_region<M, F>(f: F)
where
Expand Down
Loading