#cfs #space #ffi #sys #bindgen

sys cfs-sys

Bindings for NASA's cFE, cFS, and OSAL for flight software systems. Write CFS Apps in Rust!

1 unstable release

Uses old Rust 2015

0.1.0 Dec 16, 2018

#40 in #sys

MIT license

13KB
93 lines

CFS App in Rust

This crate provides Rust bindings to the NASA Core Flight Executive (CFE) and Operational System Abstraction Layer (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.

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

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

. ./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

No runtime deps

~0–2MB
~42K SLoC