#![deny(dead_code, missing_docs, unused_mut)]
pub mod build_info;
mod sandbox;
use build_info::BuildInfo;
pub use sandbox::loaded_wasm_sandbox::LoadedWasmSandbox;
pub use sandbox::proto_wasm_sandbox::ProtoWasmSandbox;
pub use sandbox::sandbox_builder::SandboxBuilder;
pub use sandbox::wasm_sandbox::WasmSandbox;
pub type ParameterValue = hyperlight_host::func::ParameterValue;
pub type ReturnValue = hyperlight_host::func::ReturnValue;
pub type ReturnType = hyperlight_host::func::ReturnType;
pub type Result<T> = hyperlight_host::Result<T>;
pub use hyperlight_host::HyperlightError;
pub use hyperlight_host::func::HostFunction;
pub use hyperlight_host::func::ParameterTuple;
pub use hyperlight_host::func::Registerable;
pub use hyperlight_host::func::SupportedReturnType;
pub use hyperlight_host::hypervisor::InterruptHandle;
pub use hyperlight_host::is_hypervisor_present;
pub use hyperlight_host::new_error;
pub use hyperlight_host::sandbox::snapshot::Snapshot;
pub fn get_build_info() -> BuildInfo {
BuildInfo::get()
}
pub fn get_wasmtime_version() -> &'static str {
BuildInfo::get_wasmtime_version()
}
#[cfg(test)]
mod tests {
use std::env;
#[test]
fn test_build_info() {
let build_info = super::get_build_info();
let wasm_runtime_hash = blake3::hash(&super::sandbox::WASM_RUNTIME);
assert_eq!(
build_info.wasm_runtime_blake3_hash,
&wasm_runtime_hash.to_string()
);
assert_eq!(build_info.package_version, env!("CARGO_PKG_VERSION"));
}
#[test]
fn test_wasmtime_version() {
let wasmtime_version = super::get_wasmtime_version();
let manifest_path = env!("CARGO_MANIFEST_PATH");
let output = std::process::Command::new("cargo")
.arg("metadata")
.arg("--manifest-path")
.arg(manifest_path)
.arg("--format-version=1")
.output()
.expect("Failed to get cargo metadata");
#[derive(serde::Deserialize)]
struct CargoMetadata {
packages: Vec<CargoPackage>,
}
#[derive(serde::Deserialize)]
struct CargoPackage {
name: String,
manifest_path: std::path::PathBuf,
}
let metadata: CargoMetadata =
serde_json::from_slice(&output.stdout).expect("Failed to parse cargo metadata");
let hyperlight_wasm_runtime = metadata
.packages
.into_iter()
.find(|pkg| pkg.name == "hyperlight-wasm-runtime")
.expect("hyperlight-wasm-runtime crate not found in cargo metadata");
let cargo_toml_path = hyperlight_wasm_runtime.manifest_path;
let cargo_toml_content =
std::fs::read_to_string(cargo_toml_path).expect("Failed to read Cargo.toml");
let cargo_toml: toml::Value =
toml::from_str(&cargo_toml_content).expect("Failed to parse Cargo.toml");
let wasmtime_version_from_toml = cargo_toml
.get("target")
.and_then(|deps| deps.get("cfg(hyperlight)"))
.and_then(|cfg| cfg.get("dependencies"))
.and_then(|deps| deps.get("wasmtime"))
.and_then(|wasmtime| wasmtime.get("version"))
.and_then(|version| version.as_str())
.expect("Failed to find wasmtime version in Cargo.toml");
assert_eq!(wasmtime_version, wasmtime_version_from_toml);
}
}