microsandbox_utils/lib.rs
1//! Shared constants and utilities for the microsandbox project.
2
3pub mod index;
4pub mod size;
5pub mod wake_pipe;
6
7//--------------------------------------------------------------------------------------------------
8// Constants: Directory Layout
9//--------------------------------------------------------------------------------------------------
10
11/// Name of the microsandbox home directory (relative to user's home).
12pub const BASE_DIR_NAME: &str = ".microsandbox";
13
14/// Subdirectory for shared libraries (libkrunfw).
15pub const LIB_SUBDIR: &str = "lib";
16
17/// Subdirectory for helper binaries.
18pub const BIN_SUBDIR: &str = "bin";
19
20/// Subdirectory for the database.
21pub const DB_SUBDIR: &str = "db";
22
23/// Subdirectory for OCI layer cache.
24pub const CACHE_SUBDIR: &str = "cache";
25
26/// Subdirectory for per-sandbox state.
27pub const SANDBOXES_SUBDIR: &str = "sandboxes";
28
29/// Subdirectory for named volumes.
30pub const VOLUMES_SUBDIR: &str = "volumes";
31
32/// Subdirectory for logs.
33pub const LOGS_SUBDIR: &str = "logs";
34
35/// Subdirectory for secrets.
36pub const SECRETS_SUBDIR: &str = "secrets";
37
38/// Subdirectory for TLS certificates.
39pub const TLS_SUBDIR: &str = "tls";
40
41/// Subdirectory for SSH keys.
42pub const SSH_SUBDIR: &str = "ssh";
43
44//--------------------------------------------------------------------------------------------------
45// Constants: Binary Names
46//--------------------------------------------------------------------------------------------------
47
48/// Guest agent binary name.
49pub const AGENTD_BINARY: &str = "agentd";
50
51/// CLI binary name.
52pub const MSB_BINARY: &str = "msb";
53
54//--------------------------------------------------------------------------------------------------
55// Constants: Versions
56//--------------------------------------------------------------------------------------------------
57
58/// Version for downloading prebuilt release artifacts.
59///
60/// This tracks the published crate/package version so the SDK and the
61/// downloaded runtime bundle stay aligned.
62pub const PREBUILT_VERSION: &str = env!("CARGO_PKG_VERSION");
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 = "superradcompany";
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}