Rust FFI and cbindgen: Integrating Embedded Rust Code in C

This page summarizes the projects mentioned and recommended in the original post on dev.to

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • cbindgen

    A project for generating C bindings from Rust code

  • Later we'll see what cbindgen essentially does is receive a configuration and a Rust library and then spit out a C header (.h) file. One might think that what cbindgen is doing might not be that special and can be done by hand. In which some cases that might be true if the project is simple enough. Though additionally as the cbindgen documentation states:

  • stm32-nucleo-f401re

    Rust projects and templates for the STM32Nucleo-F4 development board

  • As might be obvious already, a project needs to be created, in this case, however, it's a library crate (lib.rs) that we need to include rather than a binary crate (main.rs). Additionally, I will need to configure the project for the hardware I need. To make things easier, I grabbed an existing template for a GPIO project I've created in the past and modified it. I simply deleted main.rs and replaced it with an empty lib.rs as a first step. Finally, cbindgen also requires that we add a cbindgen.toml the configuration file which can be empty for starts. Afterward, the project folder tree looks like this:

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts