From 7308cfe259d55e91bb0056b02424c72a9902ee80 Mon Sep 17 00:00:00 2001 From: Wildan M Date: Sat, 22 Nov 2025 08:58:24 -0800 Subject: [PATCH 1/2] Move installer code --- src/{lib.rs => installer.rs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{lib.rs => installer.rs} (100%) diff --git a/src/lib.rs b/src/installer.rs similarity index 100% rename from src/lib.rs rename to src/installer.rs From 7a85862733c30db61f354dd74cde2ba7b6552d23 Mon Sep 17 00:00:00 2001 From: Wildan M Date: Sat, 22 Nov 2025 09:06:51 -0800 Subject: [PATCH 2/2] Split installer code to cargo feature --- Cargo.lock | 60 ++++++--------------------------- Cargo.toml | 60 +++++++++++++++++++++------------ src/config/file.rs | 73 ----------------------------------------- src/config/file_impl.rs | 72 ++++++++++++++++++++++++++++++++++++++++ src/config/mod.rs | 2 ++ src/installer.rs | 16 +++------ src/lib.rs | 14 ++++++++ 7 files changed, 142 insertions(+), 155 deletions(-) create mode 100644 src/config/file_impl.rs create mode 100644 src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 38aee5fa7e..82d2de2263 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -317,12 +317,6 @@ version = "3.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" -[[package]] -name = "bytecount" -version = "0.6.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "175812e0be2bccb6abe50bb8d566126198344f707e304f45c648fd8f2cc0365e" - [[package]] name = "bytemuck" version = "1.23.2" @@ -357,9 +351,11 @@ checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" [[package]] name = "cc" -version = "1.1.22" -source = "git+https://github.com/tea/cc-rs?branch=riscv-abi-arch-fix#588ceacb084af41415690c57688e338a32a1f1b4" +version = "1.2.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd405d82c84ff7f35739f175f67d8b9fb7687a0e84ccdc78bd3568839827cf07" dependencies = [ + "find-msvc-tools", "shlex", ] @@ -718,6 +714,12 @@ version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" +[[package]] +name = "find-msvc-tools" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a3076410a55c90011c298b04d0cfa770b00fa04e1e3c97d3f6c9de105a03844" + [[package]] name = "fnv" version = "1.0.7" @@ -1224,15 +1226,6 @@ version = "1.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" -[[package]] -name = "itertools" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "1.0.15" @@ -1708,7 +1701,6 @@ version = "0.2.37" dependencies = [ "anyhow", "arg_parser", - "cc", "fatfs", "fscommon", "gpt", @@ -1719,7 +1711,6 @@ dependencies = [ "pkgar-keys", "rand", "redox-pkg", - "redox_liner", "redox_syscall", "redoxfs", "rust-argon2", @@ -1730,19 +1721,6 @@ dependencies = [ "uuid", ] -[[package]] -name = "redox_liner" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee4596948a78a2ac29268d4ee45f788789ac8c032c77cf255378e5c96ca0c779" -dependencies = [ - "bytecount", - "itertools", - "strip-ansi-escapes", - "termion", - "unicode-width 0.1.14", -] - [[package]] name = "redox_syscall" version = "0.5.17" @@ -2118,15 +2096,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" -[[package]] -name = "strip-ansi-escapes" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a8f8038e7e7969abb3f1b7c2a811225e9296da208539e0f79c5251d6cac0025" -dependencies = [ - "vte", -] - [[package]] name = "strsim" version = "0.8.0" @@ -2503,15 +2472,6 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" -[[package]] -name = "vte" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "231fdcd7ef3037e8330d8e17e61011a2c244126acc0a982f4040ac3f9f0bc077" -dependencies = [ - "memchr", -] - [[package]] name = "walkdir" version = "2.5.0" diff --git a/Cargo.toml b/Cargo.toml index cc35de4cc5..b6ffce5e5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,42 +11,60 @@ edition = "2021" [[bin]] name = "redox_installer" path = "src/bin/installer.rs" +required-features = ["installer"] [[bin]] name = "redox_installer_tui" path = "src/bin/installer_tui.rs" +required-features = ["installer"] [lib] name = "redox_installer" path = "src/lib.rs" [dependencies] -anyhow = "1.0.89" -arg_parser = "0.1.0" -cc = "1" -fatfs = "0.3.0" -fscommon = "0.1.1" -gpt = "3.0.0" -libc = "0.2.70" -pkgar = "0.1.19" -pkgar-core = "0.1.19" -pkgar-keys = "0.1.19" -rand = "0.9" -redox_liner = "0.5" -redox-pkg = { version = "0.2.8", features = ["indicatif"] } -redox_syscall = "0.5.2" -redoxfs = "0.8.0" -rust-argon2 = "0.8.2" +anyhow = { version = "1" } +arg_parser = { version = "0.1.0", optional = true } +fatfs = { version = "0.3.0", optional = true } +fscommon = { version = "0.1.1", optional = true } +gpt = { version = "3.0.0", optional = true } +libc = { version = "0.2.70" } +pkgar = { version = "0.1.19", optional = true } +pkgar-core = { version = "0.1.19", optional = true } +pkgar-keys = { version = "0.1.19", optional = true } +rand = { version = "0.9", optional = true } +redox-pkg = { version = "0.2.8", features = ["indicatif"], optional = true } +redox_syscall = { version = "0.5.2", optional = true } +redoxfs = { version = "0.8.0", optional = true } +rust-argon2 = { version = "0.8.2", optional = true } serde = "1" -serde_derive = "1.0.110" -termion = "4" -toml = "0.8" -uuid = { version = "1.4", features = ["v4"] } +serde_derive = "1.0" +termion = { version = "4", optional = true } +toml = { version = "0.8" } +uuid = { version = "1.4", features = ["v4"], optional = true } [target.'cfg(target_os = "redox")'.dependencies] libredox = "0.1" +[features] +default = ["installer"] +installer = [ + "arg_parser", + "fatfs", + "fscommon", + "gpt", + "pkgar", + "pkgar-core", + "pkgar-keys", + "rand", + "redox-pkg", + "redox_syscall", + "redoxfs", + "rust-argon2", + "termion", + "uuid", +] + [patch.crates-io] -cc-11 = { git = "https://github.com/tea/cc-rs", branch="riscv-abi-arch-fix", package = "cc" } # https://github.com/briansmith/ring/issues/1999 ring = { git = "https://gitlab.redox-os.org/redox-os/ring.git", branch = "redox-0.17.8" } diff --git a/src/config/file.rs b/src/config/file.rs index f1da3c723c..c4e88fec6b 100644 --- a/src/config/file.rs +++ b/src/config/file.rs @@ -1,33 +1,3 @@ -use crate::Result; -use libc::{gid_t, uid_t}; - -use std::ffi::{CString, OsStr}; -use std::fs::{self, File}; -use std::io::{Error, Write}; -use std::os::unix::ffi::OsStrExt; -use std::os::unix::fs::{symlink, PermissionsExt}; -use std::path::Path; - -//type Result = std::result::Result; - -fn chown>(path: P, uid: uid_t, gid: gid_t, recursive: bool) -> Result<()> { - let path = path.as_ref(); - - let c_path = CString::new(path.as_os_str().as_bytes()).unwrap(); - if unsafe { libc::chown(c_path.as_ptr(), uid, gid) } != 0 { - return Err(Error::last_os_error().into()); - } - - if recursive && path.is_dir() { - for entry_res in fs::read_dir(path)? { - let entry = entry_res?; - chown(entry.path(), uid, gid, recursive)?; - } - } - - Ok(()) -} - #[derive(Clone, Debug, Default, Deserialize, Serialize)] pub struct FileConfig { pub path: String, @@ -45,7 +15,6 @@ pub struct FileConfig { pub postinstall: bool, } -// TODO: Rewrite impls impl FileConfig { pub fn new_file(path: String, data: String) -> FileConfig { FileConfig { @@ -76,46 +45,4 @@ impl FileConfig { self.recursive_chown = true; self } - - pub(crate) fn create>(&self, prefix: P) -> Result<()> { - let path = self.path.trim_start_matches('/'); - let target_file = prefix.as_ref().join(path); - - if self.directory { - println!("Create directory {}", target_file.display()); - fs::create_dir_all(&target_file)?; - self.apply_perms(&target_file)?; - return Ok(()); - } else if let Some(parent) = target_file.parent() { - println!("Create file parent {}", parent.display()); - fs::create_dir_all(parent)?; - } - - if self.symlink { - println!("Create symlink {}", target_file.display()); - symlink(&OsStr::new(&self.data), &target_file)?; - Ok(()) - } else { - println!("Create file {}", target_file.display()); - let mut file = File::create(&target_file)?; - file.write_all(self.data.as_bytes())?; - - self.apply_perms(target_file) - } - } - - fn apply_perms>(&self, target: P) -> Result<()> { - let path = target.as_ref(); - let mode = self - .mode - .unwrap_or_else(|| if self.directory { 0o0755 } else { 0o0644 }); - let uid = self.uid.unwrap_or(!0); - let gid = self.gid.unwrap_or(!0); - - // chmod - fs::set_permissions(path, fs::Permissions::from_mode(mode))?; - - // chown - chown(path, uid, gid, self.recursive_chown) - } } diff --git a/src/config/file_impl.rs b/src/config/file_impl.rs new file mode 100644 index 0000000000..45928efaf0 --- /dev/null +++ b/src/config/file_impl.rs @@ -0,0 +1,72 @@ +use anyhow::Result; +use libc::{gid_t, uid_t}; + +use std::ffi::{CString, OsStr}; +use std::fs::{self, File}; +use std::io::{Error, Write}; +use std::os::unix::ffi::OsStrExt; +use std::os::unix::fs::{symlink, PermissionsExt}; +use std::path::Path; + +fn chown>(path: P, uid: uid_t, gid: gid_t, recursive: bool) -> Result<()> { + let path = path.as_ref(); + + let c_path = CString::new(path.as_os_str().as_bytes()).unwrap(); + if unsafe { libc::chown(c_path.as_ptr(), uid, gid) } != 0 { + return Err(Error::last_os_error().into()); + } + + if recursive && path.is_dir() { + for entry_res in fs::read_dir(path)? { + let entry = entry_res?; + chown(entry.path(), uid, gid, recursive)?; + } + } + + Ok(()) +} + +// TODO: Rewrite impls +impl crate::FileConfig { + pub(crate) fn create>(&self, prefix: P) -> Result<()> { + let path = self.path.trim_start_matches('/'); + let target_file = prefix.as_ref().join(path); + + if self.directory { + println!("Create directory {}", target_file.display()); + fs::create_dir_all(&target_file)?; + self.apply_perms(&target_file)?; + return Ok(()); + } else if let Some(parent) = target_file.parent() { + println!("Create file parent {}", parent.display()); + fs::create_dir_all(parent)?; + } + + if self.symlink { + println!("Create symlink {}", target_file.display()); + symlink(&OsStr::new(&self.data), &target_file)?; + Ok(()) + } else { + println!("Create file {}", target_file.display()); + let mut file = File::create(&target_file)?; + file.write_all(self.data.as_bytes())?; + + self.apply_perms(target_file) + } + } + + fn apply_perms>(&self, target: P) -> Result<()> { + let path = target.as_ref(); + let mode = self + .mode + .unwrap_or_else(|| if self.directory { 0o0755 } else { 0o0644 }); + let uid = self.uid.unwrap_or(!0); + let gid = self.gid.unwrap_or(!0); + + // chmod + fs::set_permissions(path, fs::Permissions::from_mode(mode))?; + + // chown + chown(path, uid, gid, self.recursive_chown) + } +} diff --git a/src/config/mod.rs b/src/config/mod.rs index 577a7b0d0d..a1fe76de78 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -7,6 +7,8 @@ use anyhow::bail; use anyhow::Result; pub mod file; +#[cfg(feature = "installer")] +pub mod file_impl; pub mod general; pub mod package; pub mod user; diff --git a/src/installer.rs b/src/installer.rs index 8ae25721a0..12a4d9b240 100644 --- a/src/installer.rs +++ b/src/installer.rs @@ -1,14 +1,3 @@ -#[macro_use] -extern crate serde_derive; - -mod config; -mod disk_wrapper; - -pub use crate::config::file::FileConfig; -pub use crate::config::package::PackageConfig; -pub use crate::config::Config; -use crate::disk_wrapper::DiskWrapper; - #[cfg(target_os = "redox")] use anyhow::{anyhow, Context}; use anyhow::{bail, Result}; @@ -17,6 +6,11 @@ use rand::{rngs::OsRng, TryRngCore}; use redoxfs::{unmount_path, Disk, DiskIo, FileSystem}; use termion::input::TermRead; +use crate::config::file::FileConfig; +use crate::config::package::PackageConfig; +use crate::config::Config; +use crate::disk_wrapper::DiskWrapper; + use std::{ cell::RefCell, collections::BTreeMap, diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000000..216478d901 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,14 @@ +#[macro_use] +extern crate serde_derive; + +mod config; +#[cfg(feature = "installer")] +mod disk_wrapper; +#[cfg(feature = "installer")] +mod installer; +#[cfg(feature = "installer")] +pub use crate::installer::*; + +pub use crate::config::file::FileConfig; +pub use crate::config::package::PackageConfig; +pub use crate::config::Config;