Skip to content

Commit 918ffe0

Browse files
authored
Merge pull request #232 from WA9ACE/sqlcipher-flag
Adds --with-sqlcipher flag
2 parents eb16642 + 75aaafe commit 918ffe0

3 files changed

Lines changed: 38 additions & 10 deletions

File tree

ext/.DS_Store

6 KB
Binary file not shown.

ext/sqlite3/extconf.rb

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,20 @@
66

77
RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
88

9-
10-
119
ldflags = cppflags = nil
1210
if RbConfig::CONFIG["host_os"] =~ /darwin/
1311
begin
14-
brew_prefix = `brew --prefix sqlite3`.chomp
15-
ldflags = "#{brew_prefix}/lib"
16-
cppflags = "#{brew_prefix}/include"
17-
pkg_conf = "#{brew_prefix}/lib/pkgconfig"
12+
if with_config('sqlcipher')
13+
brew_prefix = `brew --prefix sqlcipher`.chomp
14+
ldflags = "#{brew_prefix}/lib"
15+
cppflags = "#{brew_prefix}/include/sqlcipher"
16+
pkg_conf = "#{brew_prefix}/lib/pkgconfig"
17+
else
18+
brew_prefix = `brew --prefix sqlite3`.chomp
19+
ldflags = "#{brew_prefix}/lib"
20+
cppflags = "#{brew_prefix}/include"
21+
pkg_conf = "#{brew_prefix}/lib/pkgconfig"
22+
end
1823

1924
# pkg_config should be less error prone than parsing compiler
2025
# commandline options, but we need to set default ldflags and cpp flags
@@ -24,10 +29,19 @@
2429
end
2530
end
2631

27-
pkg_config("sqlite3")
32+
if with_config('sqlcipher')
33+
pkg_config("sqlcipher")
34+
else
35+
pkg_config("sqlite3")
36+
end
2837

2938
# --with-sqlite3-{dir,include,lib}
30-
dir_config("sqlite3", cppflags, ldflags)
39+
if with_config('sqlcipher')
40+
$CFLAGS << ' -DUSING_SQLCIPHER'
41+
dir_config("sqlcipher", cppflags, ldflags)
42+
else
43+
dir_config("sqlite3", cppflags, ldflags)
44+
end
3145

3246
if RbConfig::CONFIG["host_os"] =~ /mswin/
3347
$CFLAGS << ' -W3'
@@ -49,7 +63,12 @@ def asplode missing
4963

5064
asplode('sqlite3.h') unless find_header 'sqlite3.h'
5165
find_library 'pthread', 'pthread_create' # 1.8 support. *shrug*
52-
asplode('sqlite3') unless find_library 'sqlite3', 'sqlite3_libversion_number'
66+
67+
if with_config('sqlcipher')
68+
asplode('sqlcipher') unless find_library 'sqlcipher', 'sqlite3_libversion_number'
69+
else
70+
asplode('sqlite3') unless find_library 'sqlite3', 'sqlite3_libversion_number'
71+
end
5372

5473
# Functions defined in 1.9 but not 1.8
5574
have_func('rb_proc_arity')

ext/sqlite3/sqlite3.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ static VALUE libversion(VALUE UNUSED(klass))
6565
return INT2NUM(sqlite3_libversion_number());
6666
}
6767

68+
static VALUE using_sqlcipher(VALUE UNUSED(klass))
69+
{
70+
#ifdef USING_SQLCIPHER
71+
return Qtrue;
72+
#else
73+
return Qfalse;
74+
#endif
75+
}
76+
6877
/* Returns the compile time setting of the SQLITE_THREADSAFE flag.
6978
* See: https://www.sqlite.org/c3ref/threadsafe.html
7079
*/
@@ -144,7 +153,7 @@ void Init_sqlite3_native()
144153
#ifdef HAVE_SQLITE3_BACKUP_INIT
145154
init_sqlite3_backup();
146155
#endif
147-
156+
rb_define_singleton_method(mSqlite3, "sqlcipher?", using_sqlcipher, 0);
148157
rb_define_singleton_method(mSqlite3, "libversion", libversion, 0);
149158
rb_define_singleton_method(mSqlite3, "threadsafe", threadsafe_p, 0);
150159
rb_define_const(mSqlite3, "SQLITE_VERSION", rb_str_new2(SQLITE_VERSION));

0 commit comments

Comments
 (0)