From d348081a48c0849e60bc2898c8ee215f896d1414 Mon Sep 17 00:00:00 2001 From: rorka900 Date: Mon, 30 Mar 2026 18:32:47 +0000 Subject: feat: add musl support and dictionary-compressed ror package format --- src/install.rs | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 83 insertions(+), 6 deletions(-) (limited to 'src/install.rs') diff --git a/src/install.rs b/src/install.rs index 785746e..1801cc0 100644 --- a/src/install.rs +++ b/src/install.rs @@ -42,6 +42,8 @@ pub struct Package { #[serde(default)] pub install_steps: String, #[serde(default)] + pub libc: Option, + #[serde(default)] pub depends: Vec, #[serde(default)] pub conflicts: Vec, @@ -64,6 +66,10 @@ pub struct BinaryPackage { pub install_prefix: String, #[serde(default)] pub files: Vec, + #[serde(default)] + pub libc: Option, + #[serde(default)] + pub dict: Option, } fn default_install_prefix() -> String { @@ -74,6 +80,7 @@ fn default_install_prefix() -> String { pub struct InstalledPackage { pub name: String, pub version: String, + pub libc: Option, pub files: Vec, pub installed_at: String, } @@ -173,19 +180,48 @@ pub fn extract_deb(archive_path: &Path, dest_root: &Path) -> Result, Ok(installed_files) } -pub fn select_binary_for_arch<'a>(pkg: &'a Package, arch: &str) -> Result<&'a BinaryPackage, String> { - let target_arch = match arch { +fn normalize_arch(arch: &str) -> &str { + match arch { "native" => match std::env::consts::ARCH { "x86_64" => "amd64", "aarch64" => "arm64", other => other, }, + "x86_64" | "x64" => "amd64", + "aarch64" | "arm64" => "arm64", other => other, - }; + } +} + +fn normalize_libc(libc: &str) -> &str { + match libc { + "glibc" | "g" => "g", + "musl" | "m" => "m", + "static" => "static", + other => other, + } +} + +pub fn select_binary_for_arch<'a>(pkg: &'a Package, arch: &str, libc: &str) -> Result<&'a BinaryPackage, String> { + let target_arch = normalize_arch(arch); + let target_libc = normalize_libc(libc); + pkg.binaries .iter() - .find(|b| b.arch == target_arch || b.arch == "all" || b.arch == "x86_64") - .ok_or_else(|| format!("No binary package for architecture {}", arch)) + .find(|b| { + let arch_ok = b.arch == target_arch || b.arch == "all" || b.arch == "x86_64"; + let libc_ok = match b.libc.as_deref() { + None => true, + Some("gm") => true, + Some("static") => true, + Some(l) => normalize_libc(l) == target_libc, + }; + arch_ok && libc_ok + }) + .ok_or_else(|| format!( + "No binary for arch='{}' libc='{}' in package '{}'", + arch, libc, pkg.name + )) } pub fn find_package_file(pkg_name: &str) -> Option { @@ -241,7 +277,7 @@ pub fn install_package_with_result(pkg_name: &str, cfg: &config::Config) -> Resu return Err("No binary packages defined".to_string()); } - let binary = select_binary_for_arch(&pkg, "native")?; + let binary = select_binary_for_arch(&pkg, &cfg.global.arch, &cfg.global.libc)?; let db = InstalledDB::load(); for conflict in &pkg.conflicts { @@ -300,6 +336,19 @@ pub fn install_package_with_result(pkg_name: &str, cfg: &config::Config) -> Resu if pkg_type == "deb" { let mut files = extract_deb(&archive_path, Path::new("/"))?; all_installed_files.append(&mut files); + } else if pkg_type == "ror" { + let dict_url = binary.dict.as_ref() + .ok_or_else(|| format!("Package '{}' has type 'ror' but no dict URL", pkg_name))?; + sp2.tick(&format!("Downloading dictionary for {}...", pkg_name)); + let dict_path = download_and_verify(dict_url, "", cfg)?; + let files = extract_ror(&archive_path, &dict_path, &work_dir) + .map_err(|e| format!("Extraction failed: {}", e))?; + let _ = fs::remove_file(&dict_path); + let file_list = if binary.files.is_empty() { files } else { binary.files.clone() }; + sp2.tick(&format!("Installing files for {}...", pkg_name)); + let mut installed = install_files(&work_dir, &binary.install_prefix, &file_list) + .map_err(|e| format!("Failed to install files: {}", e))?; + all_installed_files.append(&mut installed); } else { let files = extract_native(&archive_path, &work_dir) .map_err(|e| format!("Extraction failed: {}", e))?; @@ -332,6 +381,7 @@ pub fn install_package_with_result(pkg_name: &str, cfg: &config::Config) -> Resu Ok(InstalledPackage { name: pkg.name.clone(), version: pkg.version.clone(), + libc: pkg.libc.clone(), files: all_installed_files, installed_at: Local::now().to_rfc3339(), }) @@ -450,6 +500,33 @@ pub fn extract_native(archive_path: &Path, target_dir: &Path) -> Result Result, String> { + let zstd_arg = format!("zstd -D {}", dict_path.display()); + + let status = Command::new("tar") + .arg("-I") + .arg(&zstd_arg) + .arg("-xf") + .arg(archive_path) + .arg("-C") + .arg(target_dir) + .status() + .map_err(|e| format!("Failed to execute tar for .ror: {}", e))?; + + if !status.success() { + return Err(format!("tar .ror extraction failed with exit code {:?}", status.code())); + } + + let mut files = Vec::new(); + for entry in WalkDir::new(target_dir).into_iter().filter_map(|e| e.ok()) { + if entry.file_type().is_file() || entry.file_type().is_symlink() { + let rel_path = entry.path().strip_prefix(target_dir).unwrap(); + files.push(rel_path.to_string_lossy().to_string()); + } + } + Ok(files) +} + fn install_files(source_dir: &Path, prefix: &str, files: &[String]) -> Result, String> { let prefix_path = Path::new(prefix); let mut installed = Vec::new(); -- cgit v1.2.3