Skip to content
Closed
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
17 changes: 10 additions & 7 deletions crates/bhyve-api/header-check/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fn ver_lt(ver: u32) -> bool {
CHECK_VERSION.load(Ordering::Relaxed) < ver
}
/// Source checked against has API version equal to `ver` argument
#[allow(dead_code)]
fn ver_eq(ver: u32) -> bool {
CHECK_VERSION.load(Ordering::Relaxed) == ver
}
Expand Down Expand Up @@ -91,13 +92,15 @@ fn main() {
// We expose our own copy for now for us as a constraint.
"VM_MAXCPU" => true,

// Do not bother checking the version definition define if we are
// assuming the source is from a different version.
"VMM_CURRENT_INTERFACE_VERSION"
if !ver_eq(VMM_CURRENT_INTERFACE_VERSION) =>
{
true
}
// The bhyve interface is generally backwards-compatible; headers may be newer
// than Propolis knows about. In service of additive changes, ignore the
// interface version from headers.
//
// If items (structs, ioctl numbers) we know about changed, header-check
// will find and report those specifically. If items were removed, we
// may need to conditionally `skip_const` or `skip_field` based on the
// version Propolis knows about.
"VMM_CURRENT_INTERFACE_VERSION" => true,

// API V11 saw the removal of several time-realted VMM_ARCH defines
"VAI_TSC_BOOT_OFFSET" | "VAI_BOOT_HRTIME" | "VAI_TSC_FREQ"
Expand Down
2 changes: 2 additions & 0 deletions crates/viona-api/header-check/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ libc = "0.2"
[build-dependencies]
cc = "1"
ctest2 = "0.4.7"
# Build-time conditions depend on the max API version defined in the crate
viona_api = { path = ".." }

[[test]]
name = "main"
Expand Down
59 changes: 59 additions & 0 deletions crates/viona-api/header-check/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,34 @@
use std::convert::TryFrom;
use std::env;
use std::path::PathBuf;
use std::str::FromStr;
use std::sync::atomic::{AtomicU32, Ordering};

use viona_api::VIONA_CURRENT_INTERFACE_VERSION;

static CHECK_VERSION: AtomicU32 =
AtomicU32::new(VIONA_CURRENT_INTERFACE_VERSION);

// A selection of helpers to concisely manage header-check rules, below.
//
// These are added in expectation of future use, hence `allow(dead_code)`.
// Remove the attributes as they become used, please.

/// Source checked against has API version greater than `ver` argument
#[allow(dead_code)]
fn ver_gt(ver: u32) -> bool {
CHECK_VERSION.load(Ordering::Relaxed) > ver
}
/// Source checked against has API version less than `ver` argument
#[allow(dead_code)]
fn ver_lt(ver: u32) -> bool {
CHECK_VERSION.load(Ordering::Relaxed) < ver
}
/// Source checked against has API version equal to `ver` argument
#[allow(dead_code)]
fn ver_eq(ver: u32) -> bool {
CHECK_VERSION.load(Ordering::Relaxed) == ver
}

fn main() {
let mut cfg = ctest2::TestGenerator::new();
Expand All @@ -19,6 +47,27 @@ fn main() {
}
};

// Like with byhve: allow the user to specify a target interface version to
// check against.
match env::var("API_VERSION").ok().map(|v| u32::from_str(&v)) {
Some(Ok(ver)) => {
if ver > VIONA_CURRENT_INTERFACE_VERSION {
eprintln!(
"API_VERSION {} cannot be > \
VIONA_CURRENT_INTERFACE_VERSION ({})",
ver, VIONA_CURRENT_INTERFACE_VERSION
);
std::process::exit(1);
}
CHECK_VERSION.store(ver, Ordering::Relaxed);
}
Some(Err(e)) => {
eprintln!("Invalid API_VERSION {:?}", e);
std::process::exit(1);
}
_ => {}
}

let include_paths = ["usr/src/uts/intel", "usr/src/uts/common"];
cfg.include("/usr/include");
for p in include_paths {
Expand All @@ -31,6 +80,16 @@ fn main() {
cfg.skip_const(move |name| match name {
"VIONA_DEV_PATH" => true,

// Like bhyve, the viona interface is generally backwards-compatible.
// Headers may be newer than Propolis knows about. In service of
// additive changes, ignore the interface version from headers.
//
// If items (structs, ioctl numbers) we know about changed, header-check
// will find and report those specifically. If items were removed, we
// may need to conditionally `skip_const` or `skip_field` based on the
// version Propolis knows about.
"VIONA_CURRENT_INTERFACE_VERSION" => true,

_ => false,
});

Expand Down
Loading