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

Multiple inventories to generate multiple outputs. #102

Closed
All8Up opened this issue Apr 8, 2024 · 6 comments
Closed

Multiple inventories to generate multiple outputs. #102

All8Up opened this issue Apr 8, 2024 · 6 comments
Labels
question Further information is requested

Comments

@All8Up
Copy link
Contributor

All8Up commented Apr 8, 2024

I'm wondering if there is anyway to have exclusion lists during generation and insert "include"/"using"/"import"s etc in the output? The specific intention is that I want to generate multiple files from a crate rather than a single bulk header. One file would be a support type used in the other files but currently the support type gets generated in all generated files. I haven't run across any way to tell interoptopus to insert an include/using/import statement during generation nor a way to tell it not to generate something referenced just because it has a CType implementation (i.e. it was generated by an other inventory). Have I missed something here?

I'm currently using CBindgen which allows this in an annoying way, I have a whole slew of little crates which I generate as individual files and of course tweak all the toml's to exclude the things I don't want in each. With the inventory approach here, it seemed like I could do this without all the annoyances, except the above?

@ralfbiedert
Copy link
Owner

I'm not sure I fully understand your use case, but are "namespaces" what you are looking for? You can put items into namespaces and at generation time use that to filter. The C# backend has best support for that right now. Which backend do you use?

@ralfbiedert ralfbiedert added the question Further information is requested label Apr 8, 2024
@All8Up
Copy link
Contributor Author

All8Up commented Apr 8, 2024

I'm actually using C and C# with a probable use of the Python in the near future. I'll look into the namespaces in a little while and see if that does the trick. But to be more detailed in the explanation, take the following C outline of a simple (but annoying) case:

-- u128_t.h because most of the target languages don't have u128.
... blah ...
typedef struct u128_t {..blah low/high..} u128_t;

-- a more specialized header doing something specific.
... blah ...
include "u128_t.h"
typedef struct specific {u128_t blargo;} specific;

These are both in the same crate at the moment but they are in separate inventories. But, if I generate the headers at this time I get u128_t defined in both. Is that more understandable.

@ralfbiedert
Copy link
Owner

Yes, if I understand that correctly this should be what namespaces address, have a look at the common namespace that's using in some examples.

Unfortunately their support in the backends varies, C being the worst. Depending on what you specifically want to achieve you might get away by applying an inventory filter when writing headers, and adding an explicit include. If that doesn't work then this would need a PR.

@All8Up
Copy link
Contributor Author

All8Up commented Apr 8, 2024

Well, I ended up in a meeting so haven't looked at the namespaces yet but you did mention two things I haven't seen in the docs yet so hopefully you could point towards them. The "inventory filter" and adding an explicit 'include' bits. That would work just fine for the simple case that I have but I never saw them while spelunking the documentation. (NOTE: found the filter, was looking in the backend side for it..)

@All8Up
Copy link
Contributor Author

All8Up commented Apr 8, 2024

So, after poking around, the filter + explicit include seemed like the best solution for my purposes. Only problem was that while internally when using C I don't allow headers in .h files, the externally visible files should be self contained for ease of use. So, after poking about in the C generator I could not find anything which allowed me to control additional includes. So, I present for your perusal: PR #103

Let me know if there is anything you would like changed. It seems to accomplish what I need though and all the tests passed.

@ralfbiedert
Copy link
Owner

Looks good!

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

No branches or pull requests

2 participants