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