Skip to main content

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/// Pinned version for downloading prebuilt release artifacts.
61/// Update this after publishing a new GitHub release.
62pub const PREBUILT_VERSION: &str = "0.3.1";
63
64/// libkrunfw release version. Keep in sync with justfile.
65pub const LIBKRUNFW_VERSION: &str = "5.2.1";
66
67/// libkrunfw ABI version (soname major). Keep in sync with justfile.
68pub const LIBKRUNFW_ABI: &str = "5";
69
70//--------------------------------------------------------------------------------------------------
71// Constants: Filenames
72//--------------------------------------------------------------------------------------------------
73
74/// Database filename.
75pub const DB_FILENAME: &str = "msb.db";
76
77/// Global configuration filename.
78pub const CONFIG_FILENAME: &str = "config.json";
79
80/// Project-local sandbox configuration filename.
81pub const SANDBOXFILE_NAME: &str = "Sandboxfile";
82
83//--------------------------------------------------------------------------------------------------
84// Constants: GitHub
85//--------------------------------------------------------------------------------------------------
86
87/// GitHub organization.
88pub const GITHUB_ORG: &str = "zerocore-ai";
89
90/// Main repository name.
91pub const MICROSANDBOX_REPO: &str = "microsandbox";
92
93//--------------------------------------------------------------------------------------------------
94// Functions
95//--------------------------------------------------------------------------------------------------
96
97/// Returns the platform-specific libkrunfw filename.
98pub fn libkrunfw_filename(os: &str) -> String {
99    if os == "macos" {
100        format!("libkrunfw.{LIBKRUNFW_ABI}.dylib")
101    } else {
102        format!("libkrunfw.so.{LIBKRUNFW_VERSION}")
103    }
104}
105
106/// Returns the GitHub release download URL for libkrunfw.
107pub fn libkrunfw_download_url(version: &str, arch: &str, os: &str) -> String {
108    let (target_os, ext) = if os == "macos" {
109        ("darwin", "dylib")
110    } else {
111        ("linux", "so")
112    };
113
114    format!(
115        "https://github.com/{GITHUB_ORG}/{MICROSANDBOX_REPO}/releases/download/v{version}/libkrunfw-{target_os}-{arch}.{ext}"
116    )
117}
118
119/// Returns the GitHub release download URL for the agentd binary.
120pub fn agentd_download_url(version: &str, arch: &str) -> String {
121    format!(
122        "https://github.com/{GITHUB_ORG}/{MICROSANDBOX_REPO}/releases/download/v{version}/{AGENTD_BINARY}-{arch}"
123    )
124}
125
126/// Returns the GitHub release download URL for the microsandbox bundle tarball.
127pub fn bundle_download_url(version: &str, arch: &str, os: &str) -> String {
128    let target_os = if os == "macos" { "darwin" } else { "linux" };
129    format!(
130        "https://github.com/{GITHUB_ORG}/{MICROSANDBOX_REPO}/releases/download/v{version}/{MICROSANDBOX_REPO}-{target_os}-{arch}.tar.gz"
131    )
132}