Skip to content

[Draft, for discussion only] IDL gen improvements 3 - Fold all proc-macro code back into rs-matter-macros #239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
resolver = "2"
members = [
"rs-matter",
"rs-matter-data-model",
"rs-matter-macros",
"rs-matter-macros-impl",
"examples",
]

Expand Down
30 changes: 0 additions & 30 deletions rs-matter-data-model/Cargo.toml

This file was deleted.

9 changes: 0 additions & 9 deletions rs-matter-data-model/README.md

This file was deleted.

43 changes: 0 additions & 43 deletions rs-matter-data-model/examples/file_parser.rs

This file was deleted.

18 changes: 0 additions & 18 deletions rs-matter-macros-impl/Cargo.toml

This file was deleted.

7 changes: 0 additions & 7 deletions rs-matter-macros-impl/README.md

This file was deleted.

18 changes: 0 additions & 18 deletions rs-matter-macros-impl/src/lib.rs

This file was deleted.

17 changes: 15 additions & 2 deletions rs-matter-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ syn = { version = "2", features = ["extra-traits", "parsing"] }
quote = "1"
proc-macro2 = "1"
proc-macro-crate = "3"
miette = { version = "5", features = ["fancy"] }
nom = "7"
nom-greedyerror = "0.5"
nom-supreme = "0.8"
nom_locate = "4.2"
convert_case = "0.6"
thiserror = "1"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["regex", "json"] }

rs-matter-data-model = { path = "../rs-matter-data-model" }
rs-matter-macros-impl = { path = "../rs-matter-macros-impl" }
[dev-dependencies]
assert-tokenstreams-eq = "0.1.0"
criterion = { version = "0.5.1", features = ["html_reports"] }
divan = "0.1.4"
rstest = "0.18.2"
clap = { version = "4", features = ["derive"] }
5 changes: 3 additions & 2 deletions rs-matter-macros/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# rs-matter-macros: The Rust Implementation of Matter Library - Proc-macros
# rs-matter-macros: The Rust Implementation of Matter Library - Procedural Macros

Proc-macros for implementing the `ToTLV` and `FromTLV` traits.
* Proc-macros for deriving the `FromTLV` and `ToTLV` traits
* An `import!` proc-macro for generating Matter clusters' meta-data and handler traits

NOTE: The macros are re-exported by the `rs-matter` crate which should be used instead of adding a direct dependency on the `rs-matter-macros` crate.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use miette::GraphicalReportHandler;
use rs_matter_data_model::{idl::Idl, CSA_STANDARD_CLUSTERS_IDL};
use rs_matter_macros::{idl::Idl, CSA_STANDARD_CLUSTERS_IDL};

pub fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("load example client clusters", |b| {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use divan::black_box;
use miette::GraphicalReportHandler;
use rs_matter_data_model::{idl::Idl, CSA_STANDARD_CLUSTERS_IDL};
use rs_matter_macros::{idl::Idl, CSA_STANDARD_CLUSTERS_IDL};

fn main() {
// Run registered benchmarks.
Expand Down
12 changes: 8 additions & 4 deletions rs-matter-macros-impl/src/idl.rs → rs-matter-macros/src/idl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@
* limitations under the License.
*/

use parser::Cluster;
use proc_macro2::{Ident, Literal, Span, TokenStream};
use quote::quote;

use rs_matter_data_model::Cluster;

mod bitmap;
mod cluster;
mod enumeration;
mod field;
mod handler;
mod id;
mod parser;
mod struct_in;
mod struct_out;

pub use parser::Idl;

pub const CSA_STANDARD_CLUSTERS_IDL: &str = include_str!("idl/parser/controller-clusters.matter");

/// Some context data for IDL generation
///
/// Data that is necessary to be able to code generate various bits.
Expand Down Expand Up @@ -142,8 +146,8 @@ fn cluster_internal(
mod tests {
use assert_tokenstreams_eq::assert_tokenstreams_eq;

use rs_matter_data_model::idl::Idl;
use rs_matter_data_model::{Cluster, CSA_STANDARD_CLUSTERS_IDL};
use super::Idl;
use super::{Cluster, CSA_STANDARD_CLUSTERS_IDL};

use crate::idl::IdlGenerateContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ use proc_macro2::{Literal, TokenStream};

use quote::quote;

use rs_matter_data_model::{Bitmap, Cluster};

use super::id::{ident, idl_id_to_constant_name};
use super::parser::{Bitmap, Cluster};
use super::IdlGenerateContext;

/// Create the token stream corresponding to all bitmap definitions in the provided IDL cluster.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
use proc_macro2::{Literal, TokenStream};
use quote::quote;

use rs_matter_data_model::{AccessPrivilege, Cluster, StructType};

use super::id::{ident, idl_attribute_name_to_enum_variant_name};
use super::parser::{AccessPrivilege, Cluster, StructType};
use super::IdlGenerateContext;

pub(crate) const NO_RESPONSE: &str = "DefaultSuccess";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
use proc_macro2::{Literal, TokenStream};
use quote::quote;

use rs_matter_data_model::{Cluster, Enum};

use super::id::{ident, idl_id_to_enum_variant_name};
use super::parser::{Cluster, Enum};
use super::IdlGenerateContext;

/// Create the token stream corresponding to all enum definitions in the provided IDL cluster.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
use proc_macro2::{Ident, TokenStream};
use quote::quote;

use rs_matter_data_model::{Cluster, DataType};

use super::id::ident;
use super::parser::{Cluster, DataType};

/// Return a stream representing the Rust type that corresponds to the given
/// IDL type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@
use proc_macro2::{Ident, Literal, TokenStream};
use quote::quote;

use rs_matter_data_model::{Attribute, Cluster, Command, DataType, StructType};

use super::cluster::{GLOBAL_ATTR, NO_RESPONSE};
use super::field::{field_type, field_type_builder, BuilderPolicy};
use super::id::{ident, idl_attribute_name_to_enum_variant_name, idl_field_name_to_rs_name};
use super::parser::{Attribute, Cluster, Command, DataType, StructType};
use super::IdlGenerateContext;

/// Return a token stream defining the handler trait for the provided IDL cluster.
Expand Down
File renamed without changes.
Loading