-
Notifications
You must be signed in to change notification settings - Fork 0
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
How to specify foreign import headers #333
Comments
My understanding is that users should specify header files using paths that are relative to an include directory, in which case we generate For the When manually configuring, users should configure both Am I missing or misunderstanding anything? |
I'm not fan of looking up extra information (system include paths, Cabal includes) if the opposite cost is just make user specify a bit more information. I think it will clarify when |
A quick clarification: in my understanding described above, it is up to the user to specify include directories relative to include paths (as configured by |
@TravisCardwell even if understand you, my point stands:
For TH usage nothing you said really make much sense, users would need to specify where to find the file, but also how include it from C anyway (and the latter may have a default for common cases). It might also make sense to always require some kind of wrapper header (so it's file local to package), even if it's literally just |
TL;DR I think it's time to work towards the real example, not just golden-fixture runs in our test-suite. There is a very simple TH test, and that can be extended; but Cabal/preprocessor usage is completely unexplored. |
👍 We should probably test against real examples using When using |
Related to #71 . |
Perhaps this issue is about more than just paths. Suppose some package provides two headers
Of course, if a "public" header imports from a "private" header, this necessarily means that that "private" header must also be installed and accessible, so importing from the private header must at least work (I think?). As long as the bindgen generated bindings are only ever generated "last minute" I guess this is therefore not a big problem either way. It might be a problem if the bindings are checked in and the internal structure is different than expected, perhaps on different machines? |
It won't in general. Consider // public.h
#define FOO int
#include "private.h" // private.h
FOO foobar(FOO x); which is reasonable pattern, where some header could setup various things ("configuration") for the rest of the library. |
Ah, yes. Nice example! |
To clarify, importing |
My proposal would be:
|
I have been digesting this for a while. This comment documents my current thoughts. When generating external bindings, we may want to allow users to specify a list of headers to translate (not just one) as well as a list of external bindings to be used as dependencies. Standard library bindings will likely often be used as dependencies, but we should make it possible to have no dependencies as well. In one mode, we can the generate external bindings configuration file (YAML) while the specified headers are translated. Only those specified headers are output in the generated configuration for the types (etc.), not the (possibly internal) header files where they are actually declared. We need to support repeated declarations, where the same type is exposed by more than one header file. For example, we may first encounter We need to take care to not include types (etc.) that are already included in dependencies. For example, if we create separate external bindings for In some cases, users may not want to create bindings for everything. Note that users may not be able to parse everything if we do not support everything (such as Note that the standard library remains a special case that we implement and maintain by hand, as it defines the standard types (etc.), not those of a specific implementation. |
How about we always import from the header file that is being translated? It exposes everything that it imports, after all. When we support translating more than one header file, users would be able to specify all of the headers that they would like to import from. For example, if
Note that input paths must be relative to an include path. In the above example, library header I have unfortunately not been able to find a (good) way to get the include path from |
This is essentially what I am proposing also right? So seems we are on the same page? |
Yes! We are indeed on the same page. I had to work through it before I understood why the other options I had in mind do not work. 🙇 At some point, there were comments about not wanting to import from header files that users write just to specify what they want to translate. This is no longer viable, correct? We would include from such a header, which must be in a directory added to the include path. I think that specifying multiple headers is a good way for users to specify which headers may be imported from. On the command line, perhaps we could specify them via (one or more) arguments (instead of using options). For the TH API, perhaps we can have a |
With PR #417, the user-specified header path (relative, as specified in a |
For
CApiFFI
we need to include a header for declrations, e.g.However, with file-processing interface we don't know what's the canonical import. Is it
some-header.h
orclang-c/Index.h
(i.e. whether to drop directories or not).How to solve this?
Note: rust-bindgen doesn't have such problem as it doesn't have
CApiFFI
like system. If we use ordinary ForeignFunctionInterface, then the linker will find symbol, socapi
(but then we need to at least care about calling conventions)The text was updated successfully, but these errors were encountered: