|
6 | 6 | //! This crate embeds the sandbox supervisor plus the minimal libkrun runtime |
7 | 7 | //! artifacts it needs to boot VMs without a separate VM runtime binary. |
8 | 8 |
|
| 9 | +use std::fs::File; |
9 | 10 | use std::path::{Path, PathBuf}; |
10 | 11 | use std::{env, fs}; |
11 | 12 |
|
@@ -44,6 +45,27 @@ fn main() { |
44 | 45 | } |
45 | 46 | }; |
46 | 47 |
|
| 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 | + |
47 | 69 | let compressed_dir = if let Ok(dir) = env::var("OPENSHELL_VM_RUNTIME_COMPRESSED_DIR") { |
48 | 70 | PathBuf::from(dir) |
49 | 71 | } else { |
@@ -88,10 +110,6 @@ fn main() { |
88 | 110 | format!("{libkrunfw_name}.zst"), |
89 | 111 | ), |
90 | 112 | ("gvproxy.zst".to_string(), "gvproxy.zst".to_string()), |
91 | | - ( |
92 | | - "openshell-sandbox.zst".to_string(), |
93 | | - "openshell-sandbox.zst".to_string(), |
94 | | - ), |
95 | 113 | ("umoci.zst".to_string(), "umoci.zst".to_string()), |
96 | 114 | ]; |
97 | 115 |
|
|
0 commit comments