Support for Rust flight software modules #262
Replies: 7 comments 17 replies
|
As an update, I shared Basilisk with the AeroRust forum and found several people interested in collaborating on bringing Rust to Basilisk. @schaubh do you have any resources or thoughts on how this could be done? Is there documentation on how basilisk integrates C modules that the Rust collaborators could look to for integrating Rust.modules? |
|
The first challenge is does the SWIG language support Rust? I don't think it does. Then the build system would have to be updated to support compiling such modules. Generally speaking I like the BSK supports simulations with components written C, C++ and Python. It would be interesting to explore what it would take to include BSK modules written in other languages. @patkenneally, do you have any thoughts on this? |
|
We love Basilisk and are especially excited about the possibility of maintaining software equivalence between simulation and flight, but we're hoping to use rust for flight software to take advantage of it's greater safety. In my opinion, the question doesn't need to be about supporting other languages generally. Rust stands out as the next-generation of C and is well underway in adoption. For example, Rust is the only other language to receive support in the Linux kernel (starting with Linux 6.1): https://www.infoq.com/news/2022/12/linux-6-1-rust/ |
|
The key is creating a Python interface to the compiled code. There might be other tools out there that could be used for Rust BSK modules to create python bindings. However, just to be clear, this is not something we are currently working on. |
|
This PR added support for using non-swig modules inside basilisk : #652 |
|
Hi @schaubh, I've looked into the Rust/Swig support. It looks like there is a PR open for Rust on the swig repository, but it is not clear how soon support for that will land in Swig or if it will at all. In the meantime it isn't that hard to reuse a similar solution to the C++->C wrapping that Basilisk already does, since most languages have a C compatible FFI. @patrickwalton is having me look into this, and I've already got a working implementation. The questions I have are not really technical (its possible and not too hard), but more around the user experience (both from typical Rust users learning Basilisk, as well as Basilisk users learning or adopting Rust). I'm excited to share our branch and progress soon, but before opening a PR I want to start discussion on what it would take to get such an experience upstreamed, so that I don't spend too much time headed down the wrong direction, particularly when it comes to user experience expectations. As someone coming from Rust, and just learning Basilisk, I've heavily leaned into idiomatic Rust, type safety, and the macro / build-time code-generation that Rust provides. For example, using the Basilisk/CMake build system for plugins, I call out to Cargo to build the Rust module, including generating C wrapper interfaces that are needed for SWIG. Additionally, separately I generate Rust wrappers for some of the standard messages and utility libraries basilisk provides. This can seem like "magic" sometimes, but reduces the setup complexity and overhead, keeps things more reliably in sync, and preventing user errors and reduces the maintenance burden. I believe this amount of code-generation provides a baseline experience that means users can switch to Rust without feeling like it being too much of a second class citizen. A few maybe more controversial changes include automatically handling some of the messaging boilerplate: generating the is_linked calls in the reset function based on whether an input to update has an optional type, and automatically reading the input messages and writing the output messages at the beginning and end of the update function - the update function in Rust just takes a tuple of the inputs and expects a tuple of the outputs. In particular this prevents accidentally forgetting to write an output. I plan on having good documentation for getting started with Rust modules. Before pushing to hard into finalizing the design and polishing documentation I'd like to get your input. Does this seem like a good direction to you? What are your concerns? We can dig into details on particulars in a PR, just would like high level feedback now. |
|
Ok, I'll start with that. Thanks for making this switch. I see extensions providing the ability to make stand-alone BSK wheels, but core functionality should originate in core BSK. That said, have several other PRs, tasks, and some papers to finish up. Might be next week before I get to this. |
Uh oh!
There was an error while loading. Please reload this page.
The Rust Programming language is designed as a more reliable alternative to C. Has anyone thought about what it would take to implement support for flight software modules written in Rust?
There's a great AeroRust community for aerospace projects written in Rust. They'd probably be really excited about collaborating on basilisk Rust support.
All reactions