mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-11-17 07:05:31 +08:00
ToolsCI / Tools (push) Has been cancelled
RT-Thread BSP Static Build Check / 🔍 Summary of Git Diff Changes (push) Has been cancelled
RT-Thread BSP Static Build Check / ${{ matrix.legs.RTT_BSP }} (push) Has been cancelled
RT-Thread BSP Static Build Check / collect-artifacts (push) Has been cancelled
pkgs_test / change (push) Has been cancelled
utest_auto_run / A9 :components/dfs.cfg (push) Has been cancelled
utest_auto_run / A9 :components/lwip.cfg (push) Has been cancelled
utest_auto_run / A9 :components/netdev.cfg (push) Has been cancelled
utest_auto_run / A9 :components/sal.cfg (push) Has been cancelled
utest_auto_run / A9 :cpp11/cpp11.cfg (push) Has been cancelled
utest_auto_run / AARCH64-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / A9-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / XUANTIE-rtsmart :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64 :default.cfg (push) Has been cancelled
utest_auto_run / AARCH64-smp :default.cfg (push) Has been cancelled
utest_auto_run / A9 :default.cfg (push) Has been cancelled
utest_auto_run / A9-smp :default.cfg (push) Has been cancelled
utest_auto_run / RISCV :default.cfg (push) Has been cancelled
utest_auto_run / RISCV-smp :default.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / RISCV :kernel/atomic_c11.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/ipc.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/kernel_basic.cfg (push) Has been cancelled
utest_auto_run / A9 :kernel/mem.cfg (push) Has been cancelled
Weekly CI Scheduler / Trigger and Monitor CIs (push) Has been cancelled
Weekly CI Scheduler / Create Discussion Report (push) Has been cancelled
95 lines
2.1 KiB
Rust
95 lines
2.1 KiB
Rust
/*
|
|
* Copyright (c) 2006-2025, RT-Thread Development Team
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* Change Logs:
|
|
* Date Author notes
|
|
* 2025-10-29 foxglove Modular macro library for RT-Thread Rust
|
|
*/
|
|
|
|
/*! RT-Thread Rust Macro Library
|
|
|
|
This library provides Rust macros for RT-Thread system, including:
|
|
|
|
- `rt_thread_main!` - Main thread entry macro
|
|
- `rt_component_export!` - Component export macro
|
|
- `rt_app_export!` - Application export macro
|
|
- `msh_cmd_export!` - Shell command export macro
|
|
|
|
## Usage Examples
|
|
|
|
### Main Thread Entry
|
|
```rust
|
|
use rt_macros::rt_thread_main;
|
|
|
|
#[rt_thread_main]
|
|
fn main() {
|
|
println!("Hello RT-Thread!");
|
|
}
|
|
```
|
|
|
|
### Component Export
|
|
```rust
|
|
use rt_macros::rt_component_export;
|
|
|
|
#[rt_component_export]
|
|
fn my_component_init() {
|
|
// Component initialization code
|
|
}
|
|
```
|
|
|
|
### Application Export
|
|
```rust
|
|
use rt_macros::rt_app_export;
|
|
|
|
#[rt_app_export]
|
|
fn my_app_init() {
|
|
// Application initialization code
|
|
}
|
|
```
|
|
|
|
### Shell Command Export
|
|
```rust
|
|
use rt_macros::msh_cmd_export;
|
|
|
|
#[msh_cmd_export(name = "hello", desc = "Say hello")]
|
|
fn hello_cmd(args: vec::IntoIter<rt_rust::param::ParamItem>) {
|
|
println!("Hello from shell command!");
|
|
}
|
|
```
|
|
*/
|
|
|
|
#[macro_use]
|
|
extern crate quote;
|
|
|
|
use proc_macro::TokenStream;
|
|
|
|
/* Import modular macro definitions */
|
|
mod macros;
|
|
|
|
/* Modular macro definitions */
|
|
/* RT-Thread main thread entry macro */
|
|
#[proc_macro_attribute]
|
|
pub fn rt_thread_main(args: TokenStream, input: TokenStream) -> TokenStream {
|
|
macros::main::rt_thread_main(args, input)
|
|
}
|
|
|
|
/* RT-Thread component export macro */
|
|
#[proc_macro_attribute]
|
|
pub fn rt_component_export(args: TokenStream, input: TokenStream) -> TokenStream {
|
|
macros::component::rt_component_export(args, input)
|
|
}
|
|
|
|
/* RT-Thread application export macro */
|
|
#[proc_macro_attribute]
|
|
pub fn rt_app_export(args: TokenStream, input: TokenStream) -> TokenStream {
|
|
macros::app::rt_app_export(args, input)
|
|
}
|
|
|
|
/* MSH command export macro */
|
|
#[proc_macro_attribute]
|
|
pub fn msh_cmd_export(args: TokenStream, input: TokenStream) -> TokenStream {
|
|
macros::cmd::msh_cmd_export(args, input)
|
|
}
|