Closed IvanUkhov closed 8 years ago
The linking is handled by the build script. If the API of SQLCipher is indeed the same as the one of SQLite3, one could implement a Cargo feature changing the name of the library the build script links to. What do you think about this approach?
Hm, that could work, yes. As far as I know, the interface should really be the same (depending on the SQLite version, of course).
Have a look at this. I’ve not tried, but it sounds promising. Could you please give it a shot?
Theoretically, if this functionality works, you could have your own crate, say sqlcipher
(the name is still available), which would depend on sqlite3-sys
and sqlite
and just swap the library that is used under the hood. You could also compile SQLCipher; I suppose it’s not as widespread as SQLite.
I'll try, thanks for the helpful hints!
Heh, it seems it's not as easy as one would first think. Cargo let's you override metadata, but only if your crate directly depends on the crate you're modifying. In this particular case, the dependency would be sqlcipher -> sqlite -> sqlite3-sys, so override doesn't work.
@istankovic, but your crate can directly depend on both sqlite
and sqlite3-sys
, can’t it?
Probably, but I'm not sure that would be best.
@istankovic, push your crate to GitHub so that one could have a look.
Doesn't work, cargo complains:
native library
sqlite3is being linked to by more than one package, and can only be linked to by one package
Which is as expected, because of the Cargo rule that there needs to be a single crate linking to a native lib.
I'm thinking of just adding a feature to sqlite that would override the lib in sqlite3 and be done with it. What do you think?
Ok, adding the feature was straightforward and works nicely. Would you find this approach acceptable?
Please open a pull request. I’d like to have a look how it plays out.
Please open a pull request. I’d like to have a look how it plays out.
Done. There are two actually, one for sqlite3-sys and one for sqlite.
Thanks for the pull requests! What was bothering me about a name switch in the build script is that the links
key would be lying. To prevent this, I delegated the linking to separate crates, sqlite3-provider
and sqlcipher-provider
. The first is a default feature in both sqlite3-sys
and sqlite
, and the second is an optional feature. Please try the following in your project and tell me if it works for you:
[dependencies.sqlite]
version = "0.21"
default-features = false
features = ["sqlcipher"]
The approach with provider crates is definitely better and, I've just checked, works perfectly. Thanks!
@istankovic, if some day you have the time and desire, sqlcipher-provider
would definitely benefit from the ability to compile SQLCipher in case pkg-config
fails to find it installed.
Yes, that would be nice to have. Right now I'm actually focused on using this.