Files
rt-thread/components/rust/docs/4.modules/modules.md
T
zhang san 69980f8b9d
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

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.
[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:

[build]
target = "your_target"
  1. 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
  1. 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:

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

Currently the macro-main library is not supported because it causes entry detection issues.

References