Files
rt-thread/components/rust/docs/4.modules/modules_cn.md
zhang san 69980f8b9d
Some checks failed
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
Adding Rust Language Support for RT-Thread #10910
2025-12-08 18:34:25 +08:00

1.3 KiB
Raw Blame History

编写RT-Thread可以使用的rust动态库

  1. 设置项目 像往常一样创建一个新的cargo项目。有一些标志可以告诉cargo去生成一个系统库而不是常规的rust目标文件。
[lib]
name = "your_crate"
crate-type = ["cdylib"]      # 生成动态链接库
# crate-type = ["staticlib"] # 生成静态链接库

config.toml 中添加以下内容,以指定目标平台

[build]
target = "your_target
  1. 开启 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
  1. 打开文件系统 为了能够将动态模块放入 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 依赖

[dependencies]
rt_rust = { path = "PATH/TO/rust/rt-rust" }

目前不支持macro-main库的使用因为它会导致入口识别错误。

参考资料