Skip to content

Conversation

Copy link

Copilot AI commented Oct 24, 2025

Provides comprehensive directory structure recommendations for integrating Rust language support into RT-Thread, addressing the issue on organizing Rust components following RT-Thread's loose coupling and modular design philosophy.

Documentation Added

Primary Documents

  • docs/rust-component-structure-recommendation.md - Concise proposal with recommended structure for rt-thread/components/rust/, covering:

    • Core library with C API bindings (kernel, thread, IPC, memory, device)
    • Runtime support for no_std mode with panic handlers and language items
    • Shell integration via #[msh_cmd_export] macro
    • Three example categories: applications, components, and kernel modules
    • Kconfig/SConscript integration patterns
    • 4-phase implementation roadmap
  • docs/rust-component-structure-proposal.md - Detailed technical design including ABI compatibility considerations, memory allocator integration, and complete code examples

  • docs/README.md - Documentation index

Proposed Structure

rt-thread/components/rust/
├── core/            # Bindings and allocator
├── runtime/         # no_std support, start code
├── shell/           # Shell command macros
├── examples/
│   ├── applications/    # hello_world, thread_sync, device_io
│   ├── components/      # logger, sensor_driver, protocol_stack
│   └── modules/         # simple_module, device_module
└── tools/           # Build helpers

Example Usage

#![no_std]
#![no_main]

use rt_rust_core::prelude::*;

#[rt_thread_main]
fn main() {
    rt_println!("Hello from Rust!");
    Thread::create("rust_thread", thread_entry, 0, 2048, 20).startup();
}

#[msh_cmd_export]
fn hello_rust(_argc: i32, _argv: &[&str]) {
    rt_println!("Hello from Rust command!");
}

Design reflects RT-Thread component patterns observed in fal, vbus, and utilities components, maintaining consistency with existing architecture.

Updates

Original prompt

This section details on the original issue you should resolve

<issue_title>当加入rust组件支持时的目录结构</issue_title>
<issue_description>在RT-Thread内核中来支持到rust时,以RT-Thread的风格,这个rust组件的文件、目录结构可以如何来安排,希望包括:

  • rust本身的基础支持;
    • 围绕着rt-thread操作系统本身的一些系统服务(这样可以在rust程序中导入,可以获得基础的一些API支持);
    • 通常一个rust应用会包括main函数,但在内核层面一般使用no_std模式,这个时候可以采用宏的方式进行转定义,这个时候目录结构可以如何安排;
    • 导出一些和rust程序相关的命令到RT-Thread shell中;
  • rust组件本身也包含一定的examples:
    • 使用rust来编写应用时的example;
    • 使用rust来编写组件或软件包的example;
    • 使用rust来编写内核动态模块的example;

希望本身是可以符合RT-Thread的一些理念,松耦合,以目录、文件的方式反映出组件、面向对象的特点。

对于rust的支持,在PR #12 给出了部分信息。
</issue_description>

<agent_instructions>根据issue的情况给出建议,并回复到issue中,不一定需要涉及到调整代码。</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Add directory structure for Rust component support Add Rust component directory structure design proposal for RT-Thread Oct 24, 2025
Copilot AI requested a review from BernardXiong October 24, 2025 23:18
Copilot finished work on behalf of BernardXiong October 24, 2025 23:18
可以参考PR #12中的部分实现,以及以下开源项目:

1. [Linux内核Rust支持](https://github.com/Rust-for-Linux/linux)
2. [Zephyr RTOS的Rust集成](https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/rust)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot 这个链接并不存在,请进行核对。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修复,更新为正确的链接 https://github.com/zephyrproject-rtos/zephyr (提交 53ca94f)


1. [Linux内核Rust支持](https://github.com/Rust-for-Linux/linux)
2. [Zephyr RTOS的Rust集成](https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/rust)
3. [嵌入式Rust示例](https://github.com/rust-embedded/rust-embedded)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot 这个链接也并不存在,请进行核对。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修复,更新为 Rust嵌入式开发手册的正确链接 https://github.com/rust-embedded/book (提交 53ca94f)

│ │ └── lang_items.rs # 语言项
│ └── linker/
│ └── rust_module.ld # 链接脚本
├── msh/ # Shell命令支持
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot 如是针对msh,可以直接更改目录名称为 shell

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已将所有文档中的 msh/ 目录更名为 shell/ (提交 53ca94f)

@BernardXiong
Copy link
Member

@copilot PR的message都采用英文和中文对照的方式。

Copy link
Author

Copilot AI commented Oct 24, 2025

@copilot PR的message都采用英文和中文对照的方式。

明白了。后续的 commit message 会采用中英文对照的格式。

Understood. Future commit messages will use bilingual format (English and Chinese).

注:现有的 commit 已经推送,无法修改历史记录(不支持 force push)。如需修改现有 commits,请告知是否需要创建新的 commits 来替代。

Note: Existing commits have been pushed and cannot be modified (force push not supported). If existing commits need to be updated, please let me know if new commits should be created instead.

Copilot finished work on behalf of BernardXiong October 24, 2025 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants