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

Add sqlite binding #170

Open
jonas opened this issue Aug 22, 2018 · 11 comments
Open

Add sqlite binding #170

jonas opened this issue Aug 22, 2018 · 11 comments
Labels
bindings Bindings for a library

Comments

@jonas
Copy link
Member

jonas commented Aug 22, 2018

No description provided.

@jonas jonas added the bindings Bindings for a library label Aug 22, 2018
@david-bouyssie
Copy link

I would like to generate bindings for library which is using SQLite.
My first problem is that "sqlite3.h" includes stdarg.h like this: #include <stdarg.h>.
Thus when I call "sbt compile" on my project sbt complains that stdarg.h is missing.

So as a hack I copy pasted stdarg.h in my project and I changed the include to #include "stdarg.h".
But I would like to know what would be the proper way to do this with the plugin configuration.

Then, after having performed the hack above the situation is worse because 118 errors are emitted.
Any experience relative to SQLite bindings generation?

Thanks.

@kornilova203
Copy link
Member

Hi @david-bouyssie, I'll take a look at your problem tomorrow

@david-bouyssie
Copy link

Would be awesome.
In the meantime I found a way to only expose the function of my library without exposing the sqlite library.
But I think it would be nice if sqlite bindings generation could work properly.

@jonas
Copy link
Member Author

jonas commented Jan 28, 2019

I started work on sqlite bindings back in August. I just pushed my WIP branch https://github.com/scala-native/scala-native-bindgen/compare/sqlite-binding

I don't remember if I got any tests working, but you could use it as a starting point. As long as you use the docker build infrastructure for generating the bindings (which might not be well documented) you shouldn't run into issues with stdarg.h.

@david-bouyssie
Copy link

david-bouyssie commented Jan 28, 2019

Thank you so much.
At least even if I cannot generate my own bindings I can use your definitions.
About the ".so" files how do I specify the location of my library?
I searched in the scala-native documentation (https://scala-native.readthedocs.io/en/v0.3.8/user/interop.html#linking-with-native-libraries) but it is not that clear.

@jonas
Copy link
Member Author

jonas commented Jan 28, 2019

For sbt you can use the nativeLinkingOptions setting (https://scala-native.readthedocs.io/en/v0.3.8/user/sbt.html#sbt-settings-and-tasks) to pass non-standard /lib folders.

@david-bouyssie
Copy link

Hi.

I have some good progress regarding SQLite bindings usage.
I think I could provide a wrapper soon.

I have however some issues with some specific C typedefs.
For instance these types were not translated automatically by bindgen:

typedef void (*sqlite3_destructor_type)(void*);
#define SQLITE_STATIC      ((sqlite3_destructor_type)0)
#define SQLITE_TRANSIENT   ((sqlite3_destructor_type)-1)

And I don't know how to do it manually. Do I have to define a C function pointer?
The signature of this parameter in sqlite3_bind_blob is:
CFunctionPtr1[native.Ptr[Byte], Unit]

But I don't figure out how the SQLite library will understand the function pointer definition.

Additionally I also observed that sqlite3_win32_xxx functions and SQLITE_WIN32_XXX constants were not exported by bindgen.

@jonas
Copy link
Member Author

jonas commented Feb 20, 2019

I'm surprised that the typedef is not translates. For the macro, it is supposed to handle constants, but those macros looks like black magic. 🙀

If we cannot fix this in the bindings generator, one option would be to allow some custom code to be included.

@david-bouyssie
Copy link

Actually I had a short discussion with @densh on gitter.
He suggested to do:

val SQLITE_STATIC = 0.cast[CFunctionPtr1[Ptr[Byte], Unit]]
val SQLITE_TRANSIENT = 1.cast[CFunctionPtr1[Ptr[Byte], Unit]]

But with the tag 0.3.8 this trick doesn't seem to work.
I end up with a java.lang.RuntimeException: Nonzero exit code.

I didn't try with the latest version of the github master branch.
So I don't know if it works or not.

@david-bouyssie
Copy link

Moreover I don't know why but the section named CAPI3REF: Extended Result Codes of the sqlite.h contains several defines (from SQLITE_IOERR_READ to SQLITE_READONLY_CANTLOCK ) which are not exported by bindgen. Weird isn't it?

@david-bouyssie
Copy link

FYI, sqlite4s 0.1.0 is now out 😄
See david-bouyssie/sqlite4s

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

No branches or pull requests

3 participants