Skip to content

Commit f8afca3

Browse files
committed
feat(openshell-driver-vm): fetch and compress sandbox from bindeps directly
1 parent 09e56f1 commit f8afca3

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/openshell-driver-vm/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ zstd = "0.13"
5454
[target.'cfg(any(target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd", target_os = "dragonfly"))'.dependencies]
5555
polling = "3.11"
5656

57+
[build-dependencies]
58+
zstd = "0.13"
59+
5760
[target.'cfg(all(target_os = "linux", target_arch = "x86_64"))'.build-dependencies]
5861
openshell-sandbox = { path = "../openshell-sandbox", artifact = "bin:openshell-sandbox", target = "x86_64-unknown-linux-gnu" }
5962

crates/openshell-driver-vm/build.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//! This crate embeds the sandbox supervisor plus the minimal libkrun runtime
77
//! artifacts it needs to boot VMs without a separate VM runtime binary.
88
9+
use std::fs::File;
910
use std::path::{Path, PathBuf};
1011
use std::{env, fs};
1112

@@ -44,6 +45,27 @@ fn main() {
4445
}
4546
};
4647

48+
let supervisor_path = env::var_os("CARGO_BIN_FILE_OPENSHELL_SANDBOX")
49+
.or_else(|| env::var_os("CARGO_BIN_FILE_OPENSHELL_SANDBOX_openshell-sandbox"))
50+
.expect("CARGO_BIN_FILE_OPENSHELL_SANDBOX not set");
51+
let supervisor_path = PathBuf::from(supervisor_path);
52+
println!("cargo:rerun-if-changed={}", supervisor_path.display());
53+
54+
let mut supervisor = File::open(&supervisor_path)
55+
.unwrap_or_else(|e| panic!("Failed to open {}: {e}", supervisor_path.display()));
56+
let dst_path = out_dir.join("openshell-sandbox.zst");
57+
let mut dst = File::create(&dst_path)
58+
.unwrap_or_else(|e| panic!("Failed to create {}: {e}", dst_path.display()));
59+
zstd::stream::copy_encode(&mut supervisor, &mut dst, 1).unwrap_or_else(|e| {
60+
panic!(
61+
"Failed to compress {} to {}: {e}",
62+
supervisor_path.display(),
63+
dst_path.display()
64+
)
65+
});
66+
let size = fs::metadata(&dst_path).map_or(0, |m| m.len());
67+
println!("cargo:warning=Embedded openshell-sandbox.zst: {size} bytes");
68+
4769
let compressed_dir = if let Ok(dir) = env::var("OPENSHELL_VM_RUNTIME_COMPRESSED_DIR") {
4870
PathBuf::from(dir)
4971
} else {
@@ -88,10 +110,6 @@ fn main() {
88110
format!("{libkrunfw_name}.zst"),
89111
),
90112
("gvproxy.zst".to_string(), "gvproxy.zst".to_string()),
91-
(
92-
"openshell-sandbox.zst".to_string(),
93-
"openshell-sandbox.zst".to_string(),
94-
),
95113
("umoci.zst".to_string(), "umoci.zst".to_string()),
96114
];
97115

0 commit comments

Comments
 (0)