# CFS App in Rust This crate provides Rust bindings to the NASA [Core Flight Executive (CFE)](https://github.com/nasa/cFE) and [Operational System Abstraction Layer (OSAL)](https://github.com/nasa/osal). These provide a core set of software components for building flight software systems, as well as a mechanism to extend the system with additional modules called Core Flight Software (CFS) Apps. With the cfs-sys crate, you can write your CFS Apps in Rust! This is the base bindings generated by bindgen. A Rusty interface could be written to wrap up all the unsafe FFI called and raw pointers. The intent is that these bindings would be generated by a Rust crate integrated it the CFS build process. This build process would set up the necessary environment and start the process of building the CFS App with cargo, which would generate the necessary bindings at that time. This ensures that Rust binds against the version of CFS it is run with. I'm working on an example CFS system that uses these bindings to include a CFS App written in Rust, to show how you could include Rust in a CFS system. The project is a work in progress, but can be found [here](https://github.com/nsmryan/cfs\_app\_rs). ## Building The intent of this project is that it would be included in CFS Apps integrated into the CFS build process. In this case, the bindings generated would be specific to the installation of CFS, including certain project and board specific definitions. This would also providing the environment variables necessary to point to the CFS installation, described below. ### Target This project has been tested with the i686-unknown-linux-gnu target by building the POSIX version of OSAL. To get this target using rustup, type ```shell rustup target add i686-unknown-linux-gnu ``` I have not tried cross-compiling CFS with a Rust App for an embedded system yet. ### Environment Variables To build this project, you need the following environment variables defined: * OSAL\_DIR * PSP\_DIR * CFE\_FSW * CFE\_CORE\_SRC * CFS\_MISSION * CFS\_MISSION\_INC The easiest way to define these is to clone the [cFE github repository](https://github.com/nasa/cFE) and its submodules (at least OSAL- the submodules in the app directory are not necessary). Then go to your cloned cFE repository, and type the following to set up the necessary environment variables: ```shell . ./setvars.sh ``` At this point, the Rust App will be able to build the cfs-sys bindings. ## Note on Shared Object Size When using the cfs-sys crate to write a CFS App, I've noticed that I get a .so file 3MB by default, with lto=true and panic='abort'. Stripping this gets down to about 200 KB. For reference, other CFS apps are 8KB to 20KB or so. This works fine for some environments, but in space it would be nice to have small object files to assist in uploading new code through a slow, intermittent connection. Compression with xz gets this down to 79KB, which is better, but still not as good as a C module. ## Macros in CFS There are macros with arguments (aka inline functions) used in certain CFE modules. Bindgen does not translate these, so they are missing from these bindings. They could be added as functions in C, or in Rust, but currently they are simply missing. There are listed below: * ccsds.h * cfs\_es.h * cfs\_evs.h * cfs\_tbl\_filedef.h * cfs\_sb.h * common\_types.h * cfe\_platform\_cfg.h * cfe\_psp\_module.h