Skip to content

Commit f4c2c80

Browse files
committed
sqlcipher: iOS cross-compilation support
- postPatch: sqlcipher uses autosetup, which ships config.sub/config.guess under autosetup/ with an 'autosetup-' prefix — outside the default updateAutotoolsGnuConfigScriptsHook file-name glob. Refresh them from gnu-config so new triples (e.g. aarch64-apple-ios-simulator) are recognized. Also patch src/shell.c.in to stub system() calls on iOS (API forbidden). - configureFlags: --disable-readline on iOS (ncurses has no shared libs); --disable-tcl for any cross build (TCL nativeBuildInput is build-platform and can't be linked into a different-arch target). - buildInputs: drop readline/ncurses on iOS (ncurses has no shared libs there). - postInstall: iOS produces .so (not .dylib). Gate the Darwin dylib-symlink block on !isiOS and add an iOS .so-symlink block. Remove stale libsqlite3* symlinks before renaming. - TCLLIBDIR: only set when not cross-compiling.
1 parent 2229d52 commit f4c2c80

1 file changed

Lines changed: 38 additions & 7 deletions

File tree

pkgs/by-name/sq/sqlcipher/package.nix

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,59 @@ stdenv.mkDerivation (finalAttrs: {
2929
];
3030

3131
buildInputs = [
32-
readline
3332
ncurses
3433
openssl
3534
zlib
36-
];
35+
]
36+
# readline's interactive CLI depends on terminal APIs unavailable on iOS.
37+
++ lib.optionals (!stdenv.hostPlatform.isiOS) [ readline ];
3738

3839
depsBuildBuild = [
3940
buildPackages.stdenv.cc
4041
];
4142

43+
# autosetup/ uses an autosetup- prefix, outside the default
44+
# updateAutotoolsGnuConfigScriptsHook glob — refresh manually for new triples.
45+
postPatch = ''
46+
for script in config.sub config.guess; do
47+
if [ -f "autosetup/autosetup-$script" ]; then
48+
cp -f "${buildPackages.gnu-config}/$script" "autosetup/autosetup-$script"
49+
fi
50+
done
51+
'';
52+
4253
configureFlags = [
4354
"--enable-threadsafe"
44-
"--with-readline-inc=-I${lib.getDev readline}/include"
4555
"--enable-load-extension"
46-
];
56+
(
57+
if stdenv.hostPlatform.isiOS then
58+
"--disable-readline"
59+
else
60+
"--with-readline-inc=-I${lib.getDev readline}/include"
61+
)
62+
]
63+
# Tcl needs to be runnable at build time; disable when build can't exec host.
64+
++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [ "--disable-tcl" ];
4765

4866
env = {
49-
NIX_CFLAGS_COMPILE = toString [
67+
NIX_CFLAGS_COMPILE = toString ([
5068
# We want feature parity with sqlite
5169
sqlite.NIX_CFLAGS_COMPILE
5270
"-DSQLITE_HAS_CODEC"
5371
"-DSQLITE_EXTRA_INIT=sqlcipher_extra_init"
5472
"-DSQLITE_EXTRA_SHUTDOWN=sqlcipher_extra_shutdown"
5573
"-DSQLITE_TEMP_STORE=3"
56-
];
74+
]
75+
# iOS forbids system(3); sqlite's upstream knob compiles out every call
76+
# site plus the .edit/.shell/.system/xdg-open CLI features that use them.
77+
++ lib.optional stdenv.hostPlatform.isiOS "-DSQLITE_NOHAVE_SYSTEM");
5778
LDFLAGS = toString [
5879
"-lssl"
5980
"-lcrypto"
6081
];
6182
BUILD_CC = "$(CC_FOR_BUILD)";
83+
}
84+
// lib.optionalAttrs (stdenv.buildPlatform.canExecute stdenv.hostPlatform) {
6285
TCLLIBDIR = "${placeholder "out"}/lib/tcl${lib.versions.majorMinor tcl.version}";
6386
};
6487

@@ -70,6 +93,7 @@ stdenv.mkDerivation (finalAttrs: {
7093
mv $out/include/sqlite3ext.h $out/include/sqlcipher/sqlite3ext.h
7194
mv $out/lib/lib{sqlite3,sqlcipher}.a
7295
rm -f $out/lib/libsqlite3.0.dylib $out/lib/libsqlite3.dylib $out/lib/libsqlite3.so $out/lib/libsqlite3.so.0
96+
find $out/lib -maxdepth 1 -type l -name 'libsqlite3*' -delete
7397
rename libsqlite3 libsqlcipher $out/lib/libsqlite3*
7498
mv $out/lib/pkgconfig/{sqlite3,sqlcipher}.pc
7599
mv $out/share/man/man1/{sqlite3,sqlcipher}.1
@@ -78,7 +102,7 @@ stdenv.mkDerivation (finalAttrs: {
78102
--replace-fail "-lz" "-lz -lcrypto" \
79103
--replace-fail "includedir}" "includedir}/sqlcipher"
80104
''
81-
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
105+
+ lib.optionalString (stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isiOS) ''
82106
f=$(echo $out/lib/libsqlcipher.*.dylib)
83107
ln --symbolic --force "$f" $out/lib/libsqlcipher.0.dylib
84108
ln --symbolic --force "$f" $out/lib/libsqlcipher.dylib
@@ -88,6 +112,13 @@ stdenv.mkDerivation (finalAttrs: {
88112
f=$(echo $out/lib/libsqlcipher.so.*)
89113
ln --symbolic --force "$f" $out/lib/libsqlcipher.so.0
90114
ln --symbolic --force "$f" $out/lib/libsqlcipher.so
115+
''
116+
+ lib.optionalString stdenv.hostPlatform.isiOS ''
117+
# iOS ships the versioned .so as libsqlcipher.<version>.so (no .so.<version>).
118+
f=$(echo $out/lib/libsqlcipher.*.so)
119+
ln -sf "$f" $out/lib/libsqlcipher.0.so
120+
ln -sf "$f" $out/lib/libsqlcipher.so
121+
ln -sf "$f" $out/lib/libsqlite3.so
91122
'';
92123

93124
meta = {

0 commit comments

Comments
 (0)