microsandbox_utils/lib.rs
1//! Shared constants and utilities for the microsandbox project.
2
3pub mod index;
4pub mod size;
5
6//--------------------------------------------------------------------------------------------------
7// Constants: Directory Layout
8//--------------------------------------------------------------------------------------------------
9
10/// Name of the microsandbox home directory (relative to user's home).
11pub const BASE_DIR_NAME: &str = ".microsandbox";
12
13/// Subdirectory for shared libraries (libkrunfw).
14pub const LIB_SUBDIR: &str = "lib";
15
16/// Subdirectory for helper binaries (msbnet).
17pub const BIN_SUBDIR: &str = "bin";
18
19/// Subdirectory for the database.
20pub const DB_SUBDIR: &str = "db";
21
22/// Subdirectory for OCI layer cache.
23pub const CACHE_SUBDIR: &str = "cache";
24
25/// Subdirectory for per-sandbox state.
26pub const SANDBOXES_SUBDIR: &str = "sandboxes";
27
28/// Subdirectory for named volumes.
29pub const VOLUMES_SUBDIR: &str = "volumes";
30
31/// Subdirectory for logs.
32pub const LOGS_SUBDIR: &str = "logs";
33
34/// Subdirectory for secrets.
35pub const SECRETS_SUBDIR: &str = "secrets";
36
37/// Subdirectory for TLS certificates.
38pub const TLS_SUBDIR: &str = "tls";
39
40/// Subdirectory for SSH keys.
41pub const SSH_SUBDIR: &str = "ssh";
42
43//--------------------------------------------------------------------------------------------------
44// Constants: Binary Names
45//--------------------------------------------------------------------------------------------------
46
47/// Guest agent binary name.
48pub const AGENTD_BINARY: &str = "agentd";
49
50/// Network helper binary name.
51pub const MSBNET_BINARY: &str = "msbnet";
52
53/// CLI binary name.
54pub const MSB_BINARY: &str = "msb";
55
56//--------------------------------------------------------------------------------------------------
57// Constants: Versions
58//--------------------------------------------------------------------------------------------------
59
60/// libkrunfw release version. Keep in sync with justfile.
61pub const LIBKRUNFW_VERSION: &str = "5.2.1";
62
63/// libkrunfw ABI version (soname major). Keep in sync with justfile.
64pub const LIBKRUNFW_ABI: &str = "5";
65
66//--------------------------------------------------------------------------------------------------
67// Constants: Filenames
68//--------------------------------------------------------------------------------------------------
69
70/// Database filename.
71pub const DB_FILENAME: &str = "msb.db";
72
73/// Global configuration filename.
74pub const CONFIG_FILENAME: &str = "config.json";
75
76/// Project-local sandbox configuration filename.
77pub const SANDBOXFILE_NAME: &str = "Sandboxfile";
78
79//--------------------------------------------------------------------------------------------------
80// Constants: GitHub
81//--------------------------------------------------------------------------------------------------
82
83/// GitHub organization.
84pub const GITHUB_ORG: &str = "zerocore-ai";
85
86/// Main repository name.
87pub const MICROSANDBOX_REPO: &str = "microsandbox";
88
89//--------------------------------------------------------------------------------------------------
90// Functions
91//--------------------------------------------------------------------------------------------------
92
93/// Returns the platform-specific libkrunfw filename.
94pub fn libkrunfw_filename(os: &str) -> String {
95 if os == "macos" {
96 format!("libkrunfw.{LIBKRUNFW_ABI}.dylib")
97 } else {
98 format!("libkrunfw.so.{LIBKRUNFW_VERSION}")
99 }
100}
101
102/// Returns the GitHub release download URL for libkrunfw.
103pub fn libkrunfw_download_url(version: &str, arch: &str, os: &str) -> String {
104 let (target_os, ext) = if os == "macos" {
105 ("darwin", "dylib")
106 } else {
107 ("linux", "so")
108 };
109
110 format!(
111 "https://github.com/{GITHUB_ORG}/{MICROSANDBOX_REPO}/releases/download/v{version}/libkrunfw-{target_os}-{arch}.{ext}"
112 )
113}
114
115/// Returns the GitHub release download URL for the agentd binary.
116pub fn agentd_download_url(version: &str, arch: &str) -> String {
117 format!(
118 "https://github.com/{GITHUB_ORG}/{MICROSANDBOX_REPO}/releases/download/v{version}/{AGENTD_BINARY}-{arch}"
119 )
120}