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

Q: Way to static link all these into a single library? #69

Closed
jay-swyfft opened this issue Feb 28, 2023 · 8 comments
Closed

Q: Way to static link all these into a single library? #69

jay-swyfft opened this issue Feb 28, 2023 · 8 comments

Comments

@jay-swyfft
Copy link

Is it possible to link some subset of these into a static library to be included directly in a binary?

@nalgeon
Copy link
Owner

nalgeon commented Mar 1, 2023

Do you mean compiling all extensions into the SQLite binary itself? It's possible, but may require some code changes. And I've never tried it.

@jay-swyfft
Copy link
Author

Yes. I imagine that this would be easier for mobile platforms and other constrained environments.

BTW, this is a really great resource. Thanks for putting it together.

@nalgeon
Copy link
Owner

nalgeon commented Mar 2, 2023

I've thought about bundling with SQLite, but haven't tried it yet. Will do someday.

Thanks a lot!

@Hurricos
Copy link

Hurricos commented Apr 6, 2023

I compile a static sqlite3, with certain sqlean extensions compiled in, at work.

Here's a dump of my commit message from our private repo for doing so:

fix: tools: Compile-in some sqlean extensions to sqlite3

The extensions specifically being crypto, text and vsv.

In commit 724c83654, we committed a new statically compiled version of
sqlite3 whose "loader runtime stuff" was compatible with the
libraries available on CentOS 8 and Fedora 35.

I did not originally notice these messages upon compilation:

```txt
/usr/bin/ld: sqlite3-sqlite3.o: in function `unixDlOpen':
sqlite3.c:(.text+0x1071e): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: sqlite3-shell.o: in function `find_home_dir':
shell.c:(.text+0x2593b): warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
```

As it turns out, the versions of these shared libraries on CentOS 7
are too old to be compatible, so the result just crashes when one
attempts to e.g. `.load /cvt/common/tools/bin/crypto.so`.

This commit replaces the existing copy of SQLite with one where the
necessary extensions are compiled in; it is compiled from
`sqlite-src-3380100`, plus the following patch file:

https://gist.github.com/Hurricos/58dbb8e7a93da3d5983645e7d0f73519

Finally, build using `./configure CFLAGS='--static'; make -j8
sqlite3`.

The gist is a patch against, I believe, https://www.sqlite.org/2022/sqlite-autoconf-3380100.tar.gz. I created the gist by copy-pasting sections of code from sqlean here.

@nalgeon
Copy link
Owner

nalgeon commented Jun 10, 2023

The first step is a single-file extension bundle, available as of 0.21.0.

@nalgeon
Copy link
Owner

nalgeon commented Jun 11, 2023

The second step is a custom SQLite shell with preinstalled extensions.

@nalgeon
Copy link
Owner

nalgeon commented Jun 15, 2023

The third step is a drop-in replacement for Python's sqlite3 module.

@nalgeon
Copy link
Owner

nalgeon commented Jun 16, 2023

The fourth (and probably final) step is the browser-based build. Let me know if you have something else in mind.

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

3 participants