File tree Expand file tree Collapse file tree 5 files changed +124
-0
lines changed
Expand file tree Collapse file tree 5 files changed +124
-0
lines changed Original file line number Diff line number Diff line change 1+ # Hello Component
2+
3+ 这是一个使用package.json配置的RT-Thread组件示例,展示了如何使用package.json来替代传统的SConscript中DefineGroup的方式。
4+
5+ ## 文件结构
6+
7+ ```
8+ hello/
9+ ├── hello.h # 头文件
10+ ├── hello.c # 源文件
11+ ├── package.json # 组件配置文件
12+ ├── SConscript # 构建脚本
13+ └── README.md # 说明文档
14+ ```
15+
16+ ## package.json配置说明
17+
18+ package.json文件包含了组件的所有构建信息:
19+
20+ - ` name ` : 组件名称
21+ - ` version ` : 版本号
22+ - ` description ` : 组件描述
23+ - ` author ` : 作者信息
24+ - ` license ` : 许可证
25+ - ` source_files ` : 源文件列表
26+ - ` CPPPATH ` : 头文件搜索路径
27+ - ` CPPDEFINES ` : 预定义宏
28+ - ` depends ` : 依赖的组件
29+
30+ ## 使用方法
31+
32+ 1 . 将hello文件夹复制到你的RT-Thread项目的components目录下
33+ 2 . 在应用代码中包含头文件:
34+ ``` c
35+ #include " hello.h"
36+ ```
37+ 3 . 调用hello_world函数:
38+ ``` c
39+ hello_world (); // 输出: Hello World!
40+ ```
41+
42+ ## 构建过程
43+
44+ SConscript文件会:
45+ 1 . 导入package.py模块
46+ 2 . 调用BuildPackage函数处理package.json
47+ 3 . 自动创建DefineGroup并返回构建对象
48+
49+ 这种方式比传统的SConscript更加简洁和易于维护。
Original file line number Diff line number Diff line change 1+ from package import *
2+
3+ objs = BuildPackage ()
4+ Return ('objs' )
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (c) 2025 RT-Thread Development Team
3+ *
4+ * SPDX-License-Identifier: Apache-2.0
5+ *
6+ * Change Logs:
7+ * Date Author Notes
8+ * 2025-06-21 Bernard First version
9+ */
10+
11+ #include <rtthread.h>
12+ #include "hello.h"
13+
14+ /**
15+ * @brief Hello world function implementation
16+ *
17+ * This function prints "Hello World!" to the console using rt_kprintf
18+ */
19+ void hello_world (void )
20+ {
21+ rt_kprintf ("Hello World!\n" );
22+ }
Original file line number Diff line number Diff line change 1+ /*
2+ * Copyright (c) 2025 RT-Thread Development Team
3+ *
4+ * SPDX-License-Identifier: Apache-2.0
5+ *
6+ * Change Logs:
7+ * Date Author Notes
8+ * 2025-06-21 Bernard First version
9+ */
10+
11+ #ifndef __HELLO_H__
12+ #define __HELLO_H__
13+
14+ #ifdef __cplusplus
15+ extern "C" {
16+ #endif
17+
18+ /**
19+ * @brief Hello world function
20+ *
21+ * This function prints "Hello World!" to the console
22+ */
23+ void hello_world (void );
24+
25+ #ifdef __cplusplus
26+ }
27+ #endif
28+
29+ #endif /* __HELLO_H__ */
Original file line number Diff line number Diff line change 1+ {
2+ "name" : " hello" ,
3+ "version" : " 1.0.0" ,
4+ "description" : " Hello World component for RT-Thread" ,
5+ "author" : " RT-Thread Development Team" ,
6+ "license" : " Apache-2.0" ,
7+ "type" : " rt-package" ,
8+ "source_files" : [
9+ " hello.c"
10+ ],
11+ "CPPPATH" : [
12+ " ."
13+ ],
14+ "CPPDEFINES" : [
15+ " HELLO"
16+ ],
17+ "depends" : [
18+ " "
19+ ]
20+ }
You can’t perform that action at this time.
0 commit comments