mozilla / cbindgen

A project for generating C bindings from Rust code
Mozilla Public License 2.0
2.27k stars 294 forks source link

incorrect typedef order with circular dependency #981

Open RaphaelDarley opened 5 days ago

RaphaelDarley commented 5 days ago

I'm using cbindgen and its been working great, but I've run into an issue with two types: value_t and array_t, where a value could be an array and an array is an array of values.

typedef struct array_t
{
  struct value_t *arr;
  uintptr_t len;
} array_t;
typedef struct value_t
{
  value_t_Tag tag;
  union
  {
// ommited
    struct
    {
      struct array_t array;
    };
  };
} value_t;

if array is defined before value it works because it has a pointer, so known size, but cbindgen produces them in the opposite order which produces an error. Is there any way currently to alter this order, if not is would it be possible for me to add support for doing this automatically or manual reordering.

https://github.com/surrealdb/surrealdb.c/tree/02e6eafbc8f1b5d0ff303d4f19ba784ec04b466a clone the above and run ./test.sh to recreate