From 58dd02c28261945366666cf3316d564abe653feb Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Tue, 31 May 2022 11:19:11 +0800 Subject: [PATCH] xous-rs: remove log, hex, and debug-here deps The `xous-rs` library is used in many places, and should have as few dependencies as possible. Remove these as dependencies. Signed-off-by: Sean Cross --- Cargo.lock | 3 --- xous-rs/Cargo.toml | 7 ------- xous-rs/src/arch/hosted/mod.rs | 9 ++------- xous-rs/src/arch/hosted/process.rs | 22 +++++++++++++++++++++- xous-rs/src/arch/test/mod.rs | 28 ++++++++++++++++++++++------ xous-rs/src/lib.rs | 21 --------------------- 6 files changed, 45 insertions(+), 45 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8dddb68e8..25a9d7b8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3843,10 +3843,7 @@ version = "0.9.7" dependencies = [ "bitflags", "compiler_builtins", - "debug-here", - "hex", "lazy_static", - "log", "rustc-std-workspace-core", "xous-macros", ] diff --git a/xous-rs/Cargo.toml b/xous-rs/Cargo.toml index 51d2f3127..e7f0510e2 100644 --- a/xous-rs/Cargo.toml +++ b/xous-rs/Cargo.toml @@ -12,7 +12,6 @@ homepage = "https://betrusted.io/" [dependencies] bitflags = {version = "1.2.1", optional = true } xous-macros = { path = "../macros", version = "0.1.0", optional = true } -log = { version = "0.4.14", optional = true } core = { version = '1.0.0', optional = true, package = 'rustc-std-workspace-core' } compiler_builtins = { version = '0.1.0', optional = true } @@ -25,10 +24,6 @@ forget-memory-messages = [] # Enable using `bitflags` bit-flags = ["bitflags"] -# `logging` causes this program to connect to a log server on startup -# so you can run log commands such as `info!()`. -logging = ["log"] - # This is being built as part of libstd rustc-dep-of-std = ['core', 'compiler_builtins/rustc-dep-of-std'] @@ -40,5 +35,3 @@ default = ["bit-flags", "xous-macros"] [target.'cfg(any(windows,unix))'.dependencies] lazy_static = "1.4.0" -hex = "0.4.3" -debug-here = "0.2.2" diff --git a/xous-rs/src/arch/hosted/mod.rs b/xous-rs/src/arch/hosted/mod.rs index 97a0f0b1f..5a807e719 100644 --- a/xous-rs/src/arch/hosted/mod.rs +++ b/xous-rs/src/arch/hosted/mod.rs @@ -39,11 +39,7 @@ lazy_static::lazy_static! { // resume with PROCESS_KEY initialization std::env::var("XOUS_PROCESS_KEY") - .map(|s| { - let mut base = ProcessKey([0u8; 16]); - hex::decode_to_slice(s, &mut base.0).unwrap(); - base - }) + .map(|s| s.as_str().into()) .unwrap_or(ProcessKey([0u8; 16])) }; @@ -286,8 +282,7 @@ fn read_next_syscall_result( if data != previous_data.as_slice() { println!("Data: {:x?}", data); println!("Previous data: {:x?}", previous_data); - ::debug_here::debug_here!(); - panic!("Data was not equal!"); + panic!("Data changed during borrow!"); } // assert_eq!( // data, diff --git a/xous-rs/src/arch/hosted/process.rs b/xous-rs/src/arch/hosted/process.rs index f105c96b3..66cd3e5a5 100644 --- a/xous-rs/src/arch/hosted/process.rs +++ b/xous-rs/src/arch/hosted/process.rs @@ -12,6 +12,26 @@ impl ProcessKey { } } +impl Into for ProcessKey { + fn into(self) -> String { + let mut out = String::new(); + for i in self.0 { + out.push_str(&format!("{:02x}", i)); + } + out + } +} + +impl From<&str> for ProcessKey { + fn from(v: &str) -> ProcessKey { + let mut key = [0u8; 16]; + for (src, dest) in v.as_bytes().chunks(2).zip(key.iter_mut()) { + *dest = u8::from_str_radix(core::str::from_utf8(src).unwrap(), 16).unwrap(); + } + ProcessKey::new(key) + } +} + /// Describes all parameters that are required to start a new process /// on this platform. #[derive(Copy, Clone, Debug, PartialEq)] @@ -125,7 +145,7 @@ pub fn create_process_post( let server_env = format!("{}", CHILD_PROCESS_ADDRESS.lock().unwrap()); let pid_env = format!("{}", startup.pid); let process_name_env = args.name.to_string(); - let process_key_env = hex::encode(&init.key.0); + let process_key_env: String = init.key.into(); let (shell, args) = if cfg!(windows) { ("cmd", ["/C", &args.command]) } else if cfg!(unix) { diff --git a/xous-rs/src/arch/test/mod.rs b/xous-rs/src/arch/test/mod.rs index ff043e0fa..4450eddab 100644 --- a/xous-rs/src/arch/test/mod.rs +++ b/xous-rs/src/arch/test/mod.rs @@ -20,6 +20,26 @@ impl ProcessKey { } } +impl Into for ProcessKey { + fn into(self) -> String { + let mut out = String::new(); + for i in self.0 { + out.push_str(&format!("{:02x}", i)); + } + out + } +} + +impl From<&str> for ProcessKey { + fn from(v: &str) -> ProcessKey { + let mut key = [0u8; 16]; + for (src, dest) in v.as_bytes().chunks(2).zip(key.iter_mut()) { + *dest = u8::from_str_radix(core::str::from_utf8(src).unwrap(), 16).unwrap(); + } + ProcessKey::new(key) + } +} + #[derive(Debug, Clone, Copy, PartialEq)] pub struct ThreadInit {} @@ -226,7 +246,7 @@ pub fn create_process_post( let server_env = format!("{}", xous_address()); let pid_env = format!("{}", startup.pid); let process_name_env = args.name.to_string(); - let process_key_env = hex::encode(&init.key.0); + let process_key_env: String = init.key.into(); let (shell, args) = if cfg!(windows) { ("cmd", ["/C", &args.command]) } else if cfg!(unix) { @@ -343,11 +363,7 @@ fn default_xous_address() -> SocketAddr { fn default_process_key() -> ProcessKey { std::env::var("XOUS_PROCESS_KEY") - .map(|s| { - let mut base = ProcessKey([0u8; 16]); - hex::decode_to_slice(s, &mut base.0).unwrap(); - base - }) + .map(|s| s.as_str().into()) .unwrap_or(ProcessKey([0u8; 16])) } diff --git a/xous-rs/src/lib.rs b/xous-rs/src/lib.rs index 607678755..5f0609719 100644 --- a/xous-rs/src/lib.rs +++ b/xous-rs/src/lib.rs @@ -31,29 +31,8 @@ pub use locale::LANG; #[cfg(feature = "processes-as-threads")] pub use crate::arch::ProcessArgsAsThread; -#[cfg(any(target_os = "none", target_os = "xous"))] pub fn init() {} -#[cfg(not(any(target_os = "none", target_os = "xous")))] -pub fn init() { - use std::panic; - panic::set_hook(Box::new(|arg| { - println!("PANIC!"); - println!("Details: {:?}", arg); - debug_here::debug_here!(); - })); -} - -/// Convert a four-letter string into a 32-bit int. -#[macro_export] -macro_rules! make_name { - ($fcc:expr) => {{ - let mut c: [u8; 4] = Default::default(); - c.copy_from_slice($fcc.as_bytes()); - u32::from_le_bytes(c) as usize - }}; -} - #[cfg(not(target_os = "none"))] #[macro_export] macro_rules! maybe_main {