1#![deny(dead_code, missing_docs, unused_mut)]
18pub mod build_info;
22mod sandbox;
23
24use build_info::BuildInfo;
25pub use sandbox::loaded_wasm_sandbox::LoadedWasmSandbox;
26pub use sandbox::proto_wasm_sandbox::ProtoWasmSandbox;
27pub use sandbox::sandbox_builder::SandboxBuilder;
28pub use sandbox::wasm_sandbox::WasmSandbox;
29
30pub type ParameterValue = hyperlight_host::func::ParameterValue;
35pub type ReturnValue = hyperlight_host::func::ReturnValue;
37pub type ReturnType = hyperlight_host::func::ReturnType;
39pub type Result<T> = hyperlight_host::Result<T>;
41
42pub use hyperlight_host::HyperlightError;
44pub use hyperlight_host::func::HostFunction;
46pub use hyperlight_host::func::ParameterTuple;
48pub use hyperlight_host::func::Registerable;
50pub use hyperlight_host::func::SupportedReturnType;
52pub use hyperlight_host::hypervisor::InterruptHandle;
54pub use hyperlight_host::is_hypervisor_present;
56pub use hyperlight_host::new_error;
58pub use hyperlight_host::sandbox::SandboxStatus;
60pub use hyperlight_host::sandbox::snapshot::Snapshot;
62pub use hyperlight_host::sandbox::snapshot::{OciDigest, OciReference, OciTag};
67
68pub fn get_build_info() -> BuildInfo {
70 BuildInfo::get()
71}
72pub fn get_wasmtime_version() -> &'static str {
74 BuildInfo::get_wasmtime_version()
75}
76
77#[cfg(test)]
78mod tests {
79 use std::env;
80
81 #[test]
83 fn test_build_info() {
84 let build_info = super::get_build_info();
85 let wasm_runtime_hash = blake3::hash(&super::sandbox::WASM_RUNTIME);
87 assert_eq!(
89 build_info.wasm_runtime_blake3_hash,
90 &wasm_runtime_hash.to_string()
91 );
92 assert_eq!(build_info.package_version, env!("CARGO_PKG_VERSION"));
93 }
94 #[test]
96 fn test_wasmtime_version() {
97 let wasmtime_version = super::get_wasmtime_version();
98 let manifest_path = env!("CARGO_MANIFEST_PATH");
101 let output = std::process::Command::new("cargo")
102 .arg("metadata")
103 .arg("--manifest-path")
104 .arg(manifest_path)
105 .arg("--format-version=1")
106 .output()
107 .expect("Failed to get cargo metadata");
108
109 #[derive(serde::Deserialize)]
110 struct CargoMetadata {
111 packages: Vec<CargoPackage>,
112 }
113
114 #[derive(serde::Deserialize)]
115 struct CargoPackage {
116 name: String,
117 manifest_path: std::path::PathBuf,
118 }
119
120 let metadata: CargoMetadata =
121 serde_json::from_slice(&output.stdout).expect("Failed to parse cargo metadata");
122
123 let hyperlight_wasm_runtime = metadata
125 .packages
126 .into_iter()
127 .find(|pkg| pkg.name == "hyperlight-wasm-runtime")
128 .expect("hyperlight-wasm-runtime crate not found in cargo metadata");
129
130 let cargo_toml_path = hyperlight_wasm_runtime.manifest_path;
131 let cargo_toml_content =
132 std::fs::read_to_string(cargo_toml_path).expect("Failed to read Cargo.toml");
133 let cargo_toml: toml::Value =
134 toml::from_str(&cargo_toml_content).expect("Failed to parse Cargo.toml");
135 let dep_key = if cfg!(feature = "wasmtime_latest") {
137 "wasmtime"
138 } else {
139 "wasmtime_lts"
140 };
141 let wasmtime_version_requirement = cargo_toml
142 .get("target")
143 .and_then(|deps| deps.get("cfg(hyperlight)"))
144 .and_then(|cfg| cfg.get("dependencies"))
145 .and_then(|deps| deps.get(dep_key))
146 .and_then(|wasmtime| wasmtime.get("version"))
147 .and_then(|version| version.as_str())
148 .expect("Failed to find wasmtime version in Cargo.toml");
149 let wasmtime_version =
150 semver::Version::parse(wasmtime_version).expect("Failed to parse Wasmtime version");
151 let wasmtime_version_requirement = semver::VersionReq::parse(wasmtime_version_requirement)
152 .expect("Failed to parse Wasmtime version requirement");
153 assert!(
154 wasmtime_version_requirement.matches(&wasmtime_version),
155 "Wasmtime version {wasmtime_version} does not satisfy manifest requirement {wasmtime_version_requirement}"
156 );
157 }
158}