RIOT icon indicating copy to clipboard operation
RIOT copied to clipboard

async Rust runtime and applications

Open j-devel opened this issue 8 months ago • 3 comments

Contribution description

async Rust runtime and applications ('RIOT/examples/rust-async')

We would like to add a new Rust example that includes a practical async-Rust runtime and its related application modules. Using this runtime, we demonstrate how to

  • write a new async RIOT application starting from the provided async fn main() entry point,
  • run the (adapted) Rust gcoap server application as a spawned async task, and
  • use the accompanying async shell module ('src/shell.rs') to interactively test Rust code within running RIOT.

NOTE:

  • Currently, async shell is supported for native board only

Testing procedure

Build and run with a tap interface:

$ cd examples/rust-async
$ make
$ sudo ip tuntap add dev tap3 mode tap
$ sudo ip link set tap3 down
$ sudo ip link set tap3 up
$ ./bin/native/rust_async.elf tap3

Upon startup, the async Rust runtime spawns three tasks:

  1. the CoAP server in 'src/server.rs'
  2. the async_main() function in 'src/lib.rs'
  3. the async shell application in 'src/shell.rs' that is capable of executing custom sync/async Rust functions defined in 'src/alias.rs', and also ordinary RIOT-c shell commands
main(): This is RIOT! (Version: 2023.07-devel-2828-g193073-rust-async-wip)
task_server(): starting
constfs mounted successfully
CoAP server ready
task_main(): starting
async Rust example application
task_shell(): starting

along with some initial announcements:

---- named alias ----
[a] alias
[h] help
---- function alias ----
[f0] <function>
[f1] <function>
[f2] <function>
---- enumerated alias ----
[0] version
[1] ifconfig
[2] ping ::1
(async)> announce_netif():
active interface from PID KernelPID(6) ("gnrc_netdev_tap")
    Address fe80:0000:0000:0000:ec85:2eff:fe5a:64e9

(async)>

Call sync/async Rust functions defined in 'src/alias.rs':

(async)> f0
hello world!
(async)> f1
test_async_sleep():
1
2
3

Call RIOT-c shell commands:

(async)> help
Command              Description
---------------------------------------
ifconfig             Configure network interfaces
ls                   list files
nib                  Configure neighbor information base
ping                 Ping via ICMPv6
[...]
(async)> ifconfig
Iface  6  HWaddr: EE:85:2E:5A:64:E9
          L2-PDU:1500  MTU:1500  HL:64  Source address length: 6
          Link type: wired
          inet6 addr: fe80::ec85:2eff:fe5a:64e9  scope: link  VAL
          inet6 group: ff02::1
          inet6 group: ff02::1:ff5a:64e9

In a parallel shell, test the server using the libcoap client:

$ coap-client -m get coap://[fe80:0000:0000:0000:ec85:2eff:fe5a:64e9%tap3]/.well-known/core
<>;ct=0;title="Landing page"</time>;ct=0;title="Clock"</poem>;sz=1338</cbor>;ct=60</ps/>;title="Process list"</vfs/>;ct=0</saul/>;title="SAUL index"

Issues/PRs references

  • Discussions: https://forum.riot-os.org/t/on-prototyping-an-async-rust-runtime-for-riot/4002
  • (WIP) async gcoap client integration built on top of this PR: https://github.com/AnimaGUS-minerva/RIOT/tree/rust-async-gcoap/examples/rust-async/src

j-devel avatar May 29 '24 07:05 j-devel