/cstruct2rs

Abandoned project to convert C structs to Rust. Use bindgen instead!

Primary LanguageRust

cstruct2rs

A utility to help convert C structs to Rust structs for integration over FFI.

As part of my project MediaOrgan.com, I interface with RAW-processing library LibRaw, a C library that uses massive amounts of structs with many fields. The aim of the utility is to remove most of the manual labor of converting such structs to Rust format.

My primary source of information about C to Rust structs comes from this article
FFI in Rust - writing bindings for libcpuid

How to run

This program revealed some bugs in Rusts compiler, so it may need Rust 1.3 nightly to build.

  • Compile by running cargo build --release
  • Run target/release/cstruct2rs input-file output-file
    (for instance: target/release/cstruct2rs.exe example/libraw_types.h example/libraw_types.rs )

    Status and issues

    First-commit status. Have not tried to actually use the generated output for anything yet, so it is probably all wrong.

    The example folder holds an input example file from LibRaw and the generated output from cstruct2rs. Obvious issues are:

  • Does not handle const fields.
  • Does not handle enum fields
  • Does not respect paranthesis around pointers.