use std::sync::Once;
use log::info;
pub(crate) mod built_info {
include!(concat!(env!("OUT_DIR"), "/built.rs"));
}
#[deny(dead_code, missing_docs, unused_mut)]
pub mod error;
#[deny(dead_code, missing_docs, unused_mut)]
pub mod func;
#[deny(dead_code, missing_docs, unused_mut)]
pub mod hypervisor;
#[deny(dead_code, missing_docs, unused_mut)]
pub mod mem;
#[deny(dead_code, missing_docs, unused_mut)]
pub mod metrics;
#[deny(dead_code, missing_docs, unused_mut)]
pub mod sandbox;
pub mod sandbox_state;
#[cfg(all(feature = "seccomp", target_os = "linux"))]
pub(crate) mod seccomp;
#[cfg(target_os = "linux")]
pub(crate) mod signal_handlers;
#[deny(missing_docs, unused_mut)]
#[cfg(test)]
pub(crate) mod testing;
pub use error::HyperlightError;
pub use metrics::set_metrics_registry;
pub use sandbox::is_hypervisor_present;
pub use sandbox::uninitialized::GuestBinary;
pub use sandbox::MultiUseSandbox;
pub use sandbox::SandboxRunOptions;
pub use sandbox::SingleUseSandbox;
pub use sandbox::UninitializedSandbox;
pub use crate::func::call_ctx::MultiUseGuestCallContext;
pub type Result<T> = core::result::Result<T, error::HyperlightError>;
#[macro_export]
macro_rules! log_then_return {
($msg:literal $(,)?) => {{
let __args = std::format_args!($msg);
let __err_msg = match __args.as_str() {
Some(msg) => String::from(msg),
None => std::format!($msg),
};
let __err = $crate::HyperlightError::Error(__err_msg);
log::error!("{}", __err);
return Err(__err);
}};
($err:expr $(,)?) => {
log::error!("{}", $err);
return Err($err);
};
($err:stmt $(,)?) => {
log::error!("{}", $err);
return Err($err);
};
($fmtstr:expr, $($arg:tt)*) => {
let __err_msg = std::format!($fmtstr, $($arg)*);
let __err = $crate::error::HyperlightError::Error(__err_msg);
log::error!("{}", __err);
return Err(__err);
};
}
#[macro_export]
macro_rules! debug {
($($arg:tt)+) =>
{
#[cfg(all(feature = "print_debug", debug_assertions))]
{
(println!($($arg)+))
}
(log::debug!($($arg)+))
}
}
static LOG_ONCE: Once = Once::new();
pub(crate) fn log_build_details() {
LOG_ONCE.call_once(|| {
info!("Package name: {}", built_info::PKG_NAME);
info!("Package version: {}", built_info::PKG_VERSION);
info!("Package features: {:?}", built_info::FEATURES);
info!("Target triple: {}", built_info::TARGET);
info!("Optimization level: {}", built_info::OPT_LEVEL);
info!("Profile: {}", built_info::PROFILE);
info!("Debug: {}", built_info::DEBUG);
info!("Rustc: {}", built_info::RUSTC);
info!("Built at: {}", built_info::BUILT_TIME_UTC);
match built_info::CI_PLATFORM.unwrap_or("") {
"" => info!("Not built on a CI platform"),
other => info!("Built on : {}", other),
}
match built_info::GIT_COMMIT_HASH.unwrap_or("") {
"" => info!("No git commit hash found"),
other => info!("Git commit hash: {}", other),
}
let git = match built_info::GIT_HEAD_REF.unwrap_or("") {
"" => {
info!("No git head ref found");
false
}
other => {
info!("Git head ref: {}", other);
true
}
};
match built_info::GIT_VERSION.unwrap_or("") {
"" => info!("No git version found"),
other => info!("Git version: {}", other),
}
match built_info::GIT_DIRTY.unwrap_or(false) {
true => info!("Repo had uncommitted changes"),
false => {
if git {
info!("Repo had no uncommitted changes")
} else {
info!("No git repo found")
}
}
}
});
}