Skip to content
This repository was archived by the owner on May 21, 2026. It is now read-only.

Commit 3d28251

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

5 files changed

Lines changed: 86 additions & 73 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/bin/hyperlight-nanvix.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ async fn setup_registry_command() -> Result<()> {
4040
println!("Setting up Nanvix registry...");
4141

4242
// Check cache status first using shared cache utilities
43-
let kernel_cached = cache::is_binary_cached("kernel.elf");
44-
let qjs_cached = cache::is_binary_cached("qjs");
45-
let python_cached = cache::is_binary_cached("python3");
43+
let kernel_cached = cache::is_binary_cached("kernel.elf").await;
44+
let qjs_cached = cache::is_binary_cached("qjs").await;
45+
let python_cached = cache::is_binary_cached("python3").await;
4646

4747
if kernel_cached && qjs_cached && python_cached {
4848
println!("Registry already set up at ~/.cache/nanvix-registry/");

src/cache.rs

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
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

27-
/// Check if a binary exists in the cache (synchronous version for setup command)
28-
pub fn is_binary_cached(binary_name: &str) -> bool {
29-
let cache_path = get_binary_cache_directory().join(binary_name);
30-
cache_path.exists()
18+
/// Check if a binary exists in the cache
19+
pub async fn is_binary_cached(binary_name: &str) -> bool {
20+
get_cached_binary_path(binary_name).await.is_some()
3121
}

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)