From 4f154d8207be7320be07477fe3857523b1704977 Mon Sep 17 00:00:00 2001 From: bernard Date: Sat, 13 Dec 2025 21:42:29 +0800 Subject: [rust] Tidy core defaults and migrate docs to README --- components/rust/docs/4.modules/README.md | 47 ++++++++++++++++++++++++++++ components/rust/docs/4.modules/README_zh.md | 47 ++++++++++++++++++++++++++++ components/rust/docs/4.modules/modules.md | 47 ---------------------------- components/rust/docs/4.modules/modules_cn.md | 47 ---------------------------- 4 files changed, 94 insertions(+), 94 deletions(-) create mode 100644 components/rust/docs/4.modules/README.md create mode 100644 components/rust/docs/4.modules/README_zh.md delete mode 100644 components/rust/docs/4.modules/modules.md delete mode 100644 components/rust/docs/4.modules/modules_cn.md (limited to 'components/rust/docs/4.modules') diff --git a/components/rust/docs/4.modules/README.md b/components/rust/docs/4.modules/README.md new file mode 100644 index 0000000000..501a27215d --- /dev/null +++ b/components/rust/docs/4.modules/README.md @@ -0,0 +1,47 @@ +# Writing a Rust Dynamic Library Usable by RT-Thread + +1. Set up the project +Create a new `cargo` project as usual. There are some flags to tell `cargo` to generate a system library instead of a regular Rust target. + +```toml +[lib] +name = "your_crate" +crate-type = ["cdylib"] # generate a dynamic library +# crate-type = ["staticlib"] # generate a static library +``` + +Add the following to `config.toml` to specify the target platform: + +```toml +[build] +target = "your_target" +``` + +2. Enable RT-Thread dynamic module loading +To load dynamic modules in RT-Thread, enable it in `Kconfig`: +``` +RT-Thread Components → C/C++ and POSIX layer + → POSIX (Portable Operating System Interface) layer + → Enable dynamic module APIs, dlopen()/dlsym()/dlclose() etc +``` + +3. Enable the filesystem +To place dynamic modules into RT-Thread, enable a filesystem in `Kconfig`: +``` +RT-Thread online packages → system packages + → lwext4: an excellent choice of ext2/3/4 filesystem for microcontrollers. +``` + +## Using the rust library + +Add `rt_rust` dependency in `Cargo.toml`: + +```toml +[dependencies] +rt_rust = { path = "PATH/TO/rust/rt-rust" } +``` + +Currently the macro-main library is not supported because it causes entry detection issues. + +## References +- [The Embedded Rust Book](https://xxchang.github.io/book/interoperability/rust-with-c.html#extern-c) \ No newline at end of file diff --git a/components/rust/docs/4.modules/README_zh.md b/components/rust/docs/4.modules/README_zh.md new file mode 100644 index 0000000000..f9630d31ad --- /dev/null +++ b/components/rust/docs/4.modules/README_zh.md @@ -0,0 +1,47 @@ +# 编写RT-Thread可以使用的rust动态库 + +1. 设置项目 +像往常一样创建一个新的`cargo`项目。有一些标志可以告诉`cargo`去生成一个系统库,而不是常规的rust目标文件。 + +```toml +[lib] +name = "your_crate" +crate-type = ["cdylib"] # 生成动态链接库 +# crate-type = ["staticlib"] # 生成静态链接库 +``` + +在 `config.toml` 中添加以下内容,以指定目标平台 + +```toml +[build] +target = "your_target +``` + +2. 开启 RT-Thread 加载动态模块功能 +为了能够在 RT-Thread 中加载动态模块,需要在 `Kconfig` 中开启 +``` +RT-Thread Components → C/C++ and POSIX layer + → POSIX (Portable Operating System Interface) layer + → Enable dynamic module APIs, dlopen()/dlsym()/dlclose() etc +``` + +3. 打开文件系统 +为了能够将动态模块放入 RT-Thread 中,需要在 `Kconfig` 中开启文件系统。 + +``` +RT-Thread online packages → system packages + → lwext4: an excellent choice of ext2/3/4 filesystem for microcontrollers. +``` + +## rust库的使用 + +在 `Cargo.toml` 中添加 `rt_rust` 依赖 + +```toml +[dependencies] +rt_rust = { path = "PATH/TO/rust/rt-rust" } +``` + +目前不支持macro-main库的使用,因为它会导致入口识别错误。 +## 参考资料 +- [The Embedded Rust Book](https://xxchang.github.io/book/interoperability/rust-with-c.html#extern-c) diff --git a/components/rust/docs/4.modules/modules.md b/components/rust/docs/4.modules/modules.md deleted file mode 100644 index 501a27215d..0000000000 --- a/components/rust/docs/4.modules/modules.md +++ /dev/null @@ -1,47 +0,0 @@ -# Writing a Rust Dynamic Library Usable by RT-Thread - -1. Set up the project -Create a new `cargo` project as usual. There are some flags to tell `cargo` to generate a system library instead of a regular Rust target. - -```toml -[lib] -name = "your_crate" -crate-type = ["cdylib"] # generate a dynamic library -# crate-type = ["staticlib"] # generate a static library -``` - -Add the following to `config.toml` to specify the target platform: - -```toml -[build] -target = "your_target" -``` - -2. Enable RT-Thread dynamic module loading -To load dynamic modules in RT-Thread, enable it in `Kconfig`: -``` -RT-Thread Components → C/C++ and POSIX layer - → POSIX (Portable Operating System Interface) layer - → Enable dynamic module APIs, dlopen()/dlsym()/dlclose() etc -``` - -3. Enable the filesystem -To place dynamic modules into RT-Thread, enable a filesystem in `Kconfig`: -``` -RT-Thread online packages → system packages - → lwext4: an excellent choice of ext2/3/4 filesystem for microcontrollers. -``` - -## Using the rust library - -Add `rt_rust` dependency in `Cargo.toml`: - -```toml -[dependencies] -rt_rust = { path = "PATH/TO/rust/rt-rust" } -``` - -Currently the macro-main library is not supported because it causes entry detection issues. - -## References -- [The Embedded Rust Book](https://xxchang.github.io/book/interoperability/rust-with-c.html#extern-c) \ No newline at end of file diff --git a/components/rust/docs/4.modules/modules_cn.md b/components/rust/docs/4.modules/modules_cn.md deleted file mode 100644 index f9630d31ad..0000000000 --- a/components/rust/docs/4.modules/modules_cn.md +++ /dev/null @@ -1,47 +0,0 @@ -# 编写RT-Thread可以使用的rust动态库 - -1. 设置项目 -像往常一样创建一个新的`cargo`项目。有一些标志可以告诉`cargo`去生成一个系统库,而不是常规的rust目标文件。 - -```toml -[lib] -name = "your_crate" -crate-type = ["cdylib"] # 生成动态链接库 -# crate-type = ["staticlib"] # 生成静态链接库 -``` - -在 `config.toml` 中添加以下内容,以指定目标平台 - -```toml -[build] -target = "your_target -``` - -2. 开启 RT-Thread 加载动态模块功能 -为了能够在 RT-Thread 中加载动态模块,需要在 `Kconfig` 中开启 -``` -RT-Thread Components → C/C++ and POSIX layer - → POSIX (Portable Operating System Interface) layer - → Enable dynamic module APIs, dlopen()/dlsym()/dlclose() etc -``` - -3. 打开文件系统 -为了能够将动态模块放入 RT-Thread 中,需要在 `Kconfig` 中开启文件系统。 - -``` -RT-Thread online packages → system packages - → lwext4: an excellent choice of ext2/3/4 filesystem for microcontrollers. -``` - -## rust库的使用 - -在 `Cargo.toml` 中添加 `rt_rust` 依赖 - -```toml -[dependencies] -rt_rust = { path = "PATH/TO/rust/rt-rust" } -``` - -目前不支持macro-main库的使用,因为它会导致入口识别错误。 -## 参考资料 -- [The Embedded Rust Book](https://xxchang.github.io/book/interoperability/rust-with-c.html#extern-c) -- cgit v1.3.1