diff options
| author | zhang san <[email protected]> | 2025-12-08 18:34:25 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-12-08 18:34:25 +0800 |
| commit | 69980f8b9d29b38dbd4ddf6373b4b45f3a138409 (patch) | |
| tree | 21dd9a8ce80e3d30192e9ffa56ea39a199bae309 /components/rust/examples/component/component_registry | |
| parent | cd1d47b87c5d47e131730e5506eb3ad77d357653 (diff) | |
Adding Rust Language Support for RT-Thread #10910
Diffstat (limited to 'components/rust/examples/component/component_registry')
| -rw-r--r-- | components/rust/examples/component/component_registry/Cargo.toml | 19 | ||||
| -rw-r--r-- | components/rust/examples/component/component_registry/src/lib.rs | 43 |
2 files changed, 62 insertions, 0 deletions
diff --git a/components/rust/examples/component/component_registry/Cargo.toml b/components/rust/examples/component/component_registry/Cargo.toml new file mode 100644 index 0000000000..64ec88c2d4 --- /dev/null +++ b/components/rust/examples/component/component_registry/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "em_component_registry" +version = "0.1.0" +edition = "2021" + +[lib] +name = "em_component_registry" +crate-type = ["staticlib"] + +[dependencies] +rt-rust = { path = "../../../core" } +rt_macros = { path = "../../../rt_macros" } + +# Optional dependencies - only included when features are enabled +em_component_log = { path = "../log", optional = true } + +[features] +default = [] +enable-log = ["em_component_log", "em_component_log/enable-log"]
\ No newline at end of file diff --git a/components/rust/examples/component/component_registry/src/lib.rs b/components/rust/examples/component/component_registry/src/lib.rs new file mode 100644 index 0000000000..beff2df698 --- /dev/null +++ b/components/rust/examples/component/component_registry/src/lib.rs @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2006-2025, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author notes + * 2025-10-25 foxglove Component registry for unified component registration + * 2025-10-29 foxglove Updated to demonstrate new modular macro interface + */ +#![no_std] + +extern crate alloc; + +/* Demonstrate the new modular macro interface */ +use rt_macros::rt_component_export; +use rt_rust::param::{Param, ParamItem}; +use rt_rust::println; + +/* Re-export component functionality for other modules */ +#[cfg(feature = "enable-log")] +pub use em_component_log::*; +#[cfg(feature = "enable-log")] +use em_component_log::logging::Level; + +/** Unified component registration entrypoint */ +#[cfg(feature = "enable-log")] +#[rt_component_export(name = "rust_component_registry")] +fn init_registry_component() { + println!("[logging component init] hello world"); + log!(Level::Info, "hello world"); + info!("hello world"); + warn!("hello world"); + error!("hello world"); + trace!("hello world"); + debug!("hello world"); +} + +/** Provide a no-op implementation when no component feature is enabled */ +#[cfg(not(feature = "enable-log"))] +pub extern "C" fn component_init() { + /* Empty implementation to ensure the library still links */ +} |
