Skip to content

Commit b9280c4

Browse files
committed
feat(openshell-driver-vm): make the bindeps dependency optional
1 parent f8afca3 commit b9280c4

2 files changed

Lines changed: 44 additions & 28 deletions

File tree

crates/openshell-driver-vm/Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,20 @@ 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+
[features]
58+
sandbox-bindeps = ["dep:openshell-sandbox"]
59+
5760
[build-dependencies]
5861
zstd = "0.13"
5962

6063
[target.'cfg(all(target_os = "linux", target_arch = "x86_64"))'.build-dependencies]
61-
openshell-sandbox = { path = "../openshell-sandbox", artifact = "bin:openshell-sandbox", target = "x86_64-unknown-linux-gnu" }
64+
openshell-sandbox = { path = "../openshell-sandbox", artifact = "bin:openshell-sandbox", target = "x86_64-unknown-linux-gnu", optional = true }
6265

6366
[target.'cfg(all(target_os = "linux", target_arch = "aarch64"))'.build-dependencies]
64-
openshell-sandbox = { path = "../openshell-sandbox", artifact = "bin:openshell-sandbox", target = "aarch64-unknown-linux-gnu" }
67+
openshell-sandbox = { path = "../openshell-sandbox", artifact = "bin:openshell-sandbox", target = "aarch64-unknown-linux-gnu", optional = true }
6568

6669
[target.'cfg(target_os = "macos")'.build-dependencies]
67-
openshell-sandbox = { path = "../openshell-sandbox", artifact = "bin:openshell-sandbox", target = "aarch64-unknown-linux-gnu" }
70+
openshell-sandbox = { path = "../openshell-sandbox", artifact = "bin:openshell-sandbox", target = "aarch64-unknown-linux-gnu", optional = true }
6871

6972

7073
[lints]

crates/openshell-driver-vm/build.rs

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,39 @@ fn main() {
4545
}
4646
};
4747

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");
48+
let supervisor_artifact = env::var_os("CARGO_BIN_FILE_OPENSHELL_SANDBOX")
49+
.or_else(|| env::var_os("CARGO_BIN_FILE_OPENSHELL_SANDBOX_openshell-sandbox"));
50+
let supervisor_embedded = supervisor_artifact.is_some();
51+
if let Some(supervisor_path) = supervisor_artifact {
52+
let supervisor_path = PathBuf::from(supervisor_path);
53+
println!("cargo:rerun-if-changed={}", supervisor_path.display());
54+
55+
let mut supervisor = File::open(&supervisor_path)
56+
.unwrap_or_else(|e| panic!("Failed to open {}: {e}", supervisor_path.display()));
57+
let dst_path = out_dir.join("openshell-sandbox.zst");
58+
let mut dst = File::create(&dst_path)
59+
.unwrap_or_else(|e| panic!("Failed to create {}: {e}", dst_path.display()));
60+
zstd::stream::copy_encode(&mut supervisor, &mut dst, 1).unwrap_or_else(|e| {
61+
panic!(
62+
"Failed to compress {} to {}: {e}",
63+
supervisor_path.display(),
64+
dst_path.display()
65+
)
66+
});
67+
let size = fs::metadata(&dst_path).map_or(0, |m| m.len());
68+
println!("cargo:warning=Embedded openshell-sandbox.zst: {size} bytes");
69+
}
70+
let setup_hint = if supervisor_embedded {
71+
"Run: mise run vm:setup"
72+
} else {
73+
"Run: mise run vm:setup && mise run vm:supervisor"
74+
};
6875

6976
let compressed_dir = if let Ok(dir) = env::var("OPENSHELL_VM_RUNTIME_COMPRESSED_DIR") {
7077
PathBuf::from(dir)
7178
} else {
7279
println!("cargo:warning=OPENSHELL_VM_RUNTIME_COMPRESSED_DIR not set");
73-
println!("cargo:warning=Run: mise run vm:setup && mise run vm:supervisor");
80+
println!("cargo:warning={setup_hint}");
7481
generate_stub_resources(
7582
&out_dir,
7683
&[
@@ -89,7 +96,7 @@ fn main() {
8996
"cargo:warning=Compressed runtime dir not found: {}",
9097
compressed_dir.display()
9198
);
92-
println!("cargo:warning=Run: mise run vm:setup && mise run vm:supervisor");
99+
println!("cargo:warning={setup_hint}");
93100
generate_stub_resources(
94101
&out_dir,
95102
&[
@@ -110,11 +117,19 @@ fn main() {
110117
format!("{libkrunfw_name}.zst"),
111118
),
112119
("gvproxy.zst".to_string(), "gvproxy.zst".to_string()),
120+
(
121+
"openshell-sandbox.zst".to_string(),
122+
"openshell-sandbox.zst".to_string(),
123+
),
113124
("umoci.zst".to_string(), "umoci.zst".to_string()),
114125
];
115126

116127
let mut all_found = true;
117128
for (src_name, dst_name) in &files {
129+
if supervisor_embedded && src_name == "openshell-sandbox.zst" {
130+
continue;
131+
}
132+
118133
let src_path = compressed_dir.join(src_name);
119134
let dst_path = out_dir.join(dst_name);
120135

@@ -143,9 +158,7 @@ fn main() {
143158
}
144159

145160
if !all_found {
146-
println!(
147-
"cargo:warning=Some artifacts missing. Run: mise run vm:setup && mise run vm:supervisor"
148-
);
161+
println!("cargo:warning=Some artifacts missing. {setup_hint}");
149162
generate_stub_resources(
150163
&out_dir,
151164
&[

0 commit comments

Comments
 (0)