diff --git a/Cargo.lock b/Cargo.lock index 273cc77..f313f4b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -715,35 +715,34 @@ dependencies = [ "csv", "delegate 0.8.0", "satrs-core", - "satrs-macros", "satrs-mib", "spacepackets", "zerocopy", ] -[[package]] -name = "satrs-macros" -version = "0.1.0" -dependencies = [ - "proc-macro2", - "quote", - "satrs-core", - "satrs-mib", - "syn", - "trybuild", -] - [[package]] name = "satrs-mib" version = "0.1.0" dependencies = [ "csv", "satrs-core", - "satrs-macros", + "satrs-mib-codegen", "serde", "serde-hex", ] +[[package]] +name = "satrs-mib-codegen" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "satrs-core", + "satrs-mib", + "syn", + "trybuild", +] + [[package]] name = "scopeguard" version = "1.1.0" diff --git a/satrs-example/Cargo.toml b/satrs-example/Cargo.toml index 4ba1cb2..c6626ee 100644 --- a/satrs-example/Cargo.toml +++ b/satrs-example/Cargo.toml @@ -14,9 +14,6 @@ csv = "1" [dependencies.spacepackets] path = "../spacepackets" -[dependencies.satrs-macros] -path = "../satrs-macros" - [dependencies.satrs-core] path = "../satrs-core" diff --git a/satrs-example/src/lib.rs b/satrs-example/src/lib.rs index 7ba2416..5be45a9 100644 --- a/satrs-example/src/lib.rs +++ b/satrs-example/src/lib.rs @@ -1,8 +1,7 @@ use std::net::Ipv4Addr; -use satrs_core::res_code::ResultU16; -use satrs_macros::resultcode; -use satrs_mib::res_code::ResultU16Info; +use satrs_mib::resultcode; +use satrs_mib::res_code::{ResultU16, ResultU16Info}; #[derive(Debug)] pub enum GroupId { diff --git a/satrs-mib/Cargo.toml b/satrs-mib/Cargo.toml index 975aed8..8be0562 100644 --- a/satrs-mib/Cargo.toml +++ b/satrs-mib/Cargo.toml @@ -7,17 +7,21 @@ edition = "2021" [dependencies] serde-hex = "0.1.0" -csv = "1" + +[dependencies.csv] +version = "1" +optional = true [dependencies.satrs-core] path = "../satrs-core" -[dependencies.satrs-macros] -path = "../satrs-macros" - [dependencies.satrs-mib-codegen] path = "codegen" [dependencies.serde] version = "1.0" default-features = false + +[features] +default = ["std"] +std = ["csv", "serde/std"] diff --git a/satrs-mib/codegen/tests/basic.rs b/satrs-mib/codegen/tests/basic.rs index 3a4e430..2030920 100644 --- a/satrs-mib/codegen/tests/basic.rs +++ b/satrs-mib/codegen/tests/basic.rs @@ -1,6 +1,6 @@ //! Basic check which just verifies that everything compiles use satrs_core::res_code::ResultU16; -use satrs_macros::*; +use satrs_mib::resultcode; #[resultcode(info = "This is a test result where the first parameter is foo")] const _TEST_RESULT: ResultU16 = ResultU16::const_new(0, 1); diff --git a/satrs-mib/codegen/tests/verify_gen_struct.rs b/satrs-mib/codegen/tests/verify_gen_struct.rs index 39ef428..675f6d6 100644 --- a/satrs-mib/codegen/tests/verify_gen_struct.rs +++ b/satrs-mib/codegen/tests/verify_gen_struct.rs @@ -1,5 +1,5 @@ use satrs_core::res_code::ResultU16; -use satrs_macros::*; +use satrs_mib::resultcode; use satrs_mib::res_code::ResultU16Info; #[resultcode(info = "This is a test result where the first parameter is foo")] diff --git a/satrs-mib/src/lib.rs b/satrs-mib/src/lib.rs index cd42767..d2ba843 100644 --- a/satrs-mib/src/lib.rs +++ b/satrs-mib/src/lib.rs @@ -1,2 +1,8 @@ +#![no_std] +#[cfg(feature = "alloc")] +extern crate alloc; +#[cfg(any(feature = "std", test))] +extern crate std; + pub use satrs_mib_codegen::*; pub mod res_code; diff --git a/satrs-mib/src/res_code.rs b/satrs-mib/src/res_code.rs index 7c0bde1..8de5d2f 100644 --- a/satrs-mib/src/res_code.rs +++ b/satrs-mib/src/res_code.rs @@ -1,10 +1,10 @@ -use std::io; -use std::path::Path; +#[cfg(feature = "std")] +pub use stdmod::*; pub use satrs_core::res_code::ResultU16; + use serde::{Deserialize, Serialize}; use serde_hex::{SerHex, StrictCapPfx}; - #[derive(Debug, Copy, Clone, Serialize)] pub struct ResultU16Info { pub name: &'static str, @@ -55,7 +55,13 @@ impl From for ResultU16InfoSerializable { } } -pub fn print_resultcodes_as_csv(codes: &[ResultU16Info]) -> Result<(), csv::Error> { +#[cfg(feature = "std")] +pub mod stdmod { + use std::path::Path; + use std::io; + use super::*; + + pub fn print_resultcodes_as_csv(codes: &[ResultU16Info]) -> Result<(), csv::Error> { let mut wtr = csv::Writer::from_writer(io::stdout()); for result in codes { wtr.serialize(ResultU16InfoSerializable::from(*result))?; @@ -76,16 +82,18 @@ pub fn write_resultcodes_to_csv( Ok(()) } +} #[cfg(test)] mod tests { use super::*; use std::fs::File; + use std::path::Path; use std::io::{BufRead, BufReader}; // Special solution for this crate because the code generated by a macro will use // satrs_mib::res_code::* use crate as satrs_mib; use satrs_core::res_code::ResultU16; - use satrs_macros::resultcode; + use satrs_mib::resultcode; #[derive(Debug)] #[allow(dead_code)]