Skip to content

Commit a7ae3dc

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 b3b3594 commit a7ae3dc

1 file changed

Lines changed: 45 additions & 5 deletions

File tree

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

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,51 @@ stdenv.mkDerivation (finalAttrs: {
2828
util-linux
2929
];
3030

31+
# readline/ncurses back the interactive CLI; iOS has no shared ncurses.
3132
buildInputs = [
32-
readline
33-
ncurses
3433
openssl
3534
zlib
35+
]
36+
++ lib.optionals (!stdenv.hostPlatform.isiOS) [
37+
readline
38+
ncurses
3639
];
3740

3841
depsBuildBuild = [
3942
buildPackages.stdenv.cc
4043
];
4144

45+
# Refresh sqlcipher's autosetup-bundled config.sub/config.guess from gnu-config —
46+
# they live under autosetup/ with an autosetup- prefix, outside the default
47+
# updateAutotoolsGnuConfigScriptsHook glob, so new triples (e.g.
48+
# aarch64-apple-ios-simulator) wouldn't be recognized otherwise.
49+
postPatch = ''
50+
for script in config.sub config.guess; do
51+
if [ -f "autosetup/autosetup-$script" ]; then
52+
cp -f "${buildPackages.gnu-config}/$script" "autosetup/autosetup-$script"
53+
fi
54+
done
55+
''
56+
+ lib.optionalString stdenv.hostPlatform.isiOS ''
57+
# iOS forbids system(); stub the three CLI shell call sites.
58+
sed -i -e 's|rc = system(zCmd);|rc = -1;|g' \
59+
-e 's|if( system(zCmd) ){|if( -1 ){|g' \
60+
-e 's|x = zCmd!=0 ? system(zCmd) : 1;|x = zCmd!=0 ? -1 : 1;|g' \
61+
src/shell.c.in
62+
'';
63+
4264
configureFlags = [
4365
"--enable-threadsafe"
44-
"--with-readline-inc=-I${lib.getDev readline}/include"
4566
"--enable-load-extension"
46-
];
67+
(
68+
if stdenv.hostPlatform.isiOS then
69+
"--disable-readline"
70+
else
71+
"--with-readline-inc=-I${lib.getDev readline}/include"
72+
)
73+
]
74+
# TCL is a nativeBuildInput (build-platform arch), can't link into a cross target.
75+
++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ "--disable-tcl" ];
4776

4877
env = {
4978
NIX_CFLAGS_COMPILE = toString [
@@ -59,6 +88,8 @@ stdenv.mkDerivation (finalAttrs: {
5988
"-lcrypto"
6089
];
6190
BUILD_CC = "$(CC_FOR_BUILD)";
91+
}
92+
// lib.optionalAttrs (stdenv.buildPlatform == stdenv.hostPlatform) {
6293
TCLLIBDIR = "${placeholder "out"}/lib/tcl${lib.versions.majorMinor tcl.version}";
6394
};
6495

@@ -69,7 +100,9 @@ stdenv.mkDerivation (finalAttrs: {
69100
mv $out/include/sqlite3.h $out/include/sqlcipher/sqlite3.h
70101
mv $out/include/sqlite3ext.h $out/include/sqlcipher/sqlite3ext.h
71102
mv $out/lib/lib{sqlite3,sqlcipher}.a
103+
# Remove stale libsqlite3 symlinks before renaming — their targets will be gone after rename.
72104
rm -f $out/lib/libsqlite3.0.dylib $out/lib/libsqlite3.dylib $out/lib/libsqlite3.so $out/lib/libsqlite3.so.0
105+
find $out/lib -maxdepth 1 -type l -name 'libsqlite3*' -delete
73106
rename libsqlite3 libsqlcipher $out/lib/libsqlite3*
74107
mv $out/lib/pkgconfig/{sqlite3,sqlcipher}.pc
75108
mv $out/share/man/man1/{sqlite3,sqlcipher}.1
@@ -78,7 +111,7 @@ stdenv.mkDerivation (finalAttrs: {
78111
--replace-fail "-lz" "-lz -lcrypto" \
79112
--replace-fail "includedir}" "includedir}/sqlcipher"
80113
''
81-
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
114+
+ lib.optionalString (stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isiOS) ''
82115
f=$(echo $out/lib/libsqlcipher.*.dylib)
83116
ln --symbolic --force "$f" $out/lib/libsqlcipher.0.dylib
84117
ln --symbolic --force "$f" $out/lib/libsqlcipher.dylib
@@ -88,6 +121,13 @@ stdenv.mkDerivation (finalAttrs: {
88121
f=$(echo $out/lib/libsqlcipher.so.*)
89122
ln --symbolic --force "$f" $out/lib/libsqlcipher.so.0
90123
ln --symbolic --force "$f" $out/lib/libsqlcipher.so
124+
''
125+
+ lib.optionalString stdenv.hostPlatform.isiOS ''
126+
# iOS ships the versioned .so as libsqlcipher.<version>.so (no .so.<version>).
127+
f=$(echo $out/lib/libsqlcipher.*.so)
128+
ln -sf "$f" $out/lib/libsqlcipher.0.so
129+
ln -sf "$f" $out/lib/libsqlcipher.so
130+
ln -sf "$f" $out/lib/libsqlite3.so
91131
'';
92132

93133
meta = {

0 commit comments

Comments
 (0)