Skip to content

Commit 85acd53

Browse files
committed
Update dependencies and improve cache handling
Signed-off-by: Pedro Henrique Penna <ppenna@microsoft.com>
1 parent e5fa6b3 commit 85acd53

4 files changed

Lines changed: 97 additions & 68 deletions

File tree

Cargo.lock

Lines changed: 49 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = "2021"
55
description = "A Hyperlight VMM wrapper with out-of-the-box support for running Nanvix microkernel guests"
66

77
[dependencies]
8-
nanvix = { git = "https://github.com/nanvix/nanvix", rev = "7752e9f2deb4a5606f9885e4c130eec4ea583de1", features = [
8+
nanvix = { git = "https://github.com/nanvix/nanvix", rev = "cc9c508918bd17678e9d790f10a6a7c20b7902da", features = [
99
"single-process",
1010
"hyperlight",
1111
] }

src/cache.rs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,37 @@
1-
use std::path::PathBuf;
1+
use nanvix::registry::Registry;
22

3-
/// Get the default cache directory for nanvix registry
4-
pub fn get_cache_directory() -> PathBuf {
5-
let home_dir = std::env::var("HOME").unwrap_or_else(|_| ".".to_string());
6-
std::path::Path::new(&home_dir)
7-
.join(".cache")
8-
.join("nanvix-registry")
9-
}
3+
/// Default machine type for hyperlight-nanvix
4+
const DEFAULT_MACHINE: &str = "hyperlight";
105

11-
/// Get the binary cache directory
12-
pub fn get_binary_cache_directory() -> PathBuf {
13-
get_cache_directory().join("bin")
14-
}
6+
/// Default deployment type for hyperlight-nanvix
7+
const DEFAULT_DEPLOYMENT: &str = "single-process";
158

169
/// Check if a binary exists in the cache and return its path if found
1710
pub async fn get_cached_binary_path(binary_name: &str) -> Option<String> {
18-
let cache_path = get_binary_cache_directory().join(binary_name);
19-
20-
if tokio::fs::metadata(&cache_path).await.is_ok() {
21-
Some(cache_path.to_string_lossy().to_string())
22-
} else {
23-
None
24-
}
11+
let registry = Registry::new(None);
12+
registry
13+
.get_cached_binary(DEFAULT_MACHINE, DEFAULT_DEPLOYMENT, binary_name)
14+
.await
15+
.ok()
2516
}
2617

2718
/// Check if a binary exists in the cache (synchronous version for setup command)
2819
pub fn is_binary_cached(binary_name: &str) -> bool {
29-
let cache_path = get_binary_cache_directory().join(binary_name);
30-
cache_path.exists()
20+
// Use blocking runtime to check cache synchronously
21+
let registry = Registry::new(None);
22+
let rt = tokio::runtime::Builder::new_current_thread()
23+
.enable_all()
24+
.build()
25+
.ok();
26+
27+
if let Some(rt) = rt {
28+
rt.block_on(async {
29+
registry
30+
.get_cached_binary(DEFAULT_MACHINE, DEFAULT_DEPLOYMENT, binary_name)
31+
.await
32+
.is_ok()
33+
})
34+
} else {
35+
false
36+
}
3137
}

src/runtime.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ impl WorkloadType {
2626
}
2727
}
2828

29+
/// Get the registry package name for this workload type.
30+
/// Returns `None` for workload types that don't require a package installation.
31+
pub fn package_name(&self) -> Option<&'static str> {
32+
match self {
33+
WorkloadType::JavaScript => Some("quickjs"),
34+
WorkloadType::Python => Some("python"),
35+
WorkloadType::Binary => None,
36+
}
37+
}
38+
2939
/// Get the file extensions associated with this workload type
3040
pub fn extensions(&self) -> &'static [&'static str] {
3141
match self {
@@ -167,6 +177,16 @@ impl Runtime {
167177
let machine_type = "hyperlight";
168178
let deployment_type = "single-process";
169179

180+
// Install the required package (and its dependencies) for scripted workloads.
181+
// This ensures the interpreter and all transitive dependencies are present
182+
// before attempting to locate the binary.
183+
if let Some(package_name) = workload_type.package_name() {
184+
log::info!("Installing package '{}' and dependencies...", package_name);
185+
self.registry
186+
.install(machine_type, deployment_type, package_name, true)
187+
.await?;
188+
}
189+
170190
// Get interpreter binary (only needed for scripted workloads)
171191
let binary_path = if matches!(workload_type, WorkloadType::Binary) {
172192
// For binary workloads, we don't need an interpreter

0 commit comments

Comments
 (0)