vrischmann / zig-sqlite

zig-sqlite is a small wrapper around sqlite's C API, making it easier to use with Zig.
MIT License
367 stars 49 forks source link

Loadable extension #112

Closed vrischmann closed 2 years ago

vrischmann commented 2 years ago

Add the ability to build a loadable extension (with .load myextension.so for example).

Buliding a loadable extension is problematic with Zig because the way sqlite3ext.h works is that it redefines the sqlite API with defines, like this:

#define sqlite3_open_v2 sqlite3_api->open_v2

This is not supported by translate-c, I looked into ways to make it work but it's not straightforward:

To make it work requires quite a bit of work:

The two first steps are done with a tool which can be run like this:

$ zig build preprocess-files

The last step is easy enough but will take some time to do.

jiacai2050 commented 2 years ago

To make it work requires quite a bit of work:

How you tried solution like this:

The Go library has similar issue with Zig, the author define a bridge header to redefine most functions of sqlite_api, then in Go side, it only need to include bridge.h, not sqlite3ext.h.

I think Zig can also use this method to avoid modify sqlite3.h and sqlite3ext.h