Skip to content

[Feature Request] Add a config option to add dependencies for a specific struct / type #1046

@bavalpey

Description

@bavalpey

I have this issue where I am adding non abi-breaking methods to some of the structs emitted by cbindgen. However, some of them require the full definition of other structures to be emitted before.

For example, I have something equivalent to the following in my cbindgen.toml

[export.body]
"Bar" = """
public:
  bar_method(Foo::Tag tag);
"""

(I am defining the body of bar_method using the trailing configuration option).

In this case, a simple forward declaration for Foo will not work, as I specifically want to use the generated Tag field. FWIW, the rust code for Foo would look something like this:

pub enum Foo {
   MyFoo1(u8),
   MyFoo2(u8),
}

I saw issue #43 which is similar in a way. I think that having a field in the [export] table (similar to [export.body]) that allows manually specifying a dependency for an item would be beneficial. This feature would work as a workaround for that issue, in that we could use this configuration option to get around deficiencies in the dependency logic.

Right now, what I am doing is actually adding Foo to [export.exclude], and then putting what cbindgen would generate for it in the after_includes configuration field. This is fairly brittle, however, as I have to remember to change it should the definition of Foo ever change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions