-
Notifications
You must be signed in to change notification settings - Fork 35
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
Use autolinking on Apple platforms to prevent the need to link with sqlite3 explicitly #120
base: main
Are you sure you want to change the base?
Conversation
Such failure happens when K/N produces a library archive of a static framework and the linkage happens outside, for example as part of an Xcode build process.
That's an interesting option. We'd need to figure out how to use things like sqlcipher in this context, which is a "drop-in" replacement for the system sqlite library. Will have to look at this in more detail, though. |
Disabling default search paths via // main.c
#include "sqlite3.h"
int main(void) {
sqlite3_sourceid();
} and a custom implementation: // my_sqlite3.c
const char *sqlite3_sourceid(void) { return "foo"; } one could: # Compile main
clang -Xclang --linker-option=-lsqlite3 -c main.c -o main.o
# Default option: link against system's sqlite3
clang main.o -o mainSystem && otool -L mainSystem | grep sqlite
# Compile and link custom sqlite3 dylib
mkdir dylib
clang my_sqlite3.c -dynamiclib -o "$(realpath dylib)"/libsqlite3.dylib
# Link against custom sqlite3
clang -Z -Ldylib -L/usr/lib main.o -o mainCustom && otool -L mainCustom | grep sqlite |
Hi Kevin. Were you able to look into this PR? Perhaps implementing autolinking and linking against a custom sqlite3 version could be achieved in a simpler way than what I originally suggested. I think it is sufficient to add
When producing a framework:
I believe in case you need to link against a custom
|
I was not. It is an interesting option, but the overall todo list is rather long (outside of SQLiter). I'll bump it back up, but there are follow-on considerations, and other conversations happening concurrently.
So, in summary, it's on the radar, but it's complicated :) |
On Apple platforms an explicit linking configuration is usually not required, because
clang
andswiftc
compilers embed linker commands into.o
files they produce. These linker commands can be printed out viaotool -l /path/to/object | grep -A 4 LC_LINKER_OPTION
.This MR uses this technique to remove the requirement to explicitly link with
-lsqlite3
on Apple platforms by embeddingLC_LINKER_OPTION
command into object files produced by K/N. This may be most useful for projects that link against K/N static libraries in Xcode, but should also remove the need for consumer side linker configuration.As an integration test, I disabled explicit linking in sqldelight and ran the tests I could find against this MR: 1, 2