Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bavalpey opened this issue Jan 18, 2025 · 0 comments

Comments

@bavalpey
Copy link

bavalpey commented Jan 18, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant