Skip to content

Commit

Permalink
Merge pull request #232 from WA9ACE/sqlcipher-flag
Browse files Browse the repository at this point in the history
Adds --with-sqlcipher flag
  • Loading branch information
tenderlove committed Jun 20, 2018
2 parents eb16642 + 75aaafe commit 918ffe0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
Binary file added ext/.DS_Store
Binary file not shown.
37 changes: 28 additions & 9 deletions ext/sqlite3/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@

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



ldflags = cppflags = nil
if RbConfig::CONFIG["host_os"] =~ /darwin/
begin
brew_prefix = `brew --prefix sqlite3`.chomp
ldflags = "#{brew_prefix}/lib"
cppflags = "#{brew_prefix}/include"
pkg_conf = "#{brew_prefix}/lib/pkgconfig"
if with_config('sqlcipher')
brew_prefix = `brew --prefix sqlcipher`.chomp
ldflags = "#{brew_prefix}/lib"
cppflags = "#{brew_prefix}/include/sqlcipher"
pkg_conf = "#{brew_prefix}/lib/pkgconfig"
else
brew_prefix = `brew --prefix sqlite3`.chomp
ldflags = "#{brew_prefix}/lib"
cppflags = "#{brew_prefix}/include"
pkg_conf = "#{brew_prefix}/lib/pkgconfig"
end

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

pkg_config("sqlite3")
if with_config('sqlcipher')
pkg_config("sqlcipher")
else
pkg_config("sqlite3")
end

# --with-sqlite3-{dir,include,lib}
dir_config("sqlite3", cppflags, ldflags)
if with_config('sqlcipher')
$CFLAGS << ' -DUSING_SQLCIPHER'
dir_config("sqlcipher", cppflags, ldflags)
else
dir_config("sqlite3", cppflags, ldflags)
end

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

asplode('sqlite3.h') unless find_header 'sqlite3.h'
find_library 'pthread', 'pthread_create' # 1.8 support. *shrug*
asplode('sqlite3') unless find_library 'sqlite3', 'sqlite3_libversion_number'

if with_config('sqlcipher')
asplode('sqlcipher') unless find_library 'sqlcipher', 'sqlite3_libversion_number'
else
asplode('sqlite3') unless find_library 'sqlite3', 'sqlite3_libversion_number'
end

# Functions defined in 1.9 but not 1.8
have_func('rb_proc_arity')
Expand Down
11 changes: 10 additions & 1 deletion ext/sqlite3/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ static VALUE libversion(VALUE UNUSED(klass))
return INT2NUM(sqlite3_libversion_number());
}

static VALUE using_sqlcipher(VALUE UNUSED(klass))
{
#ifdef USING_SQLCIPHER
return Qtrue;
#else
return Qfalse;
#endif
}

/* Returns the compile time setting of the SQLITE_THREADSAFE flag.
* See: https://www.sqlite.org/c3ref/threadsafe.html
*/
Expand Down Expand Up @@ -144,7 +153,7 @@ void Init_sqlite3_native()
#ifdef HAVE_SQLITE3_BACKUP_INIT
init_sqlite3_backup();
#endif

rb_define_singleton_method(mSqlite3, "sqlcipher?", using_sqlcipher, 0);
rb_define_singleton_method(mSqlite3, "libversion", libversion, 0);
rb_define_singleton_method(mSqlite3, "threadsafe", threadsafe_p, 0);
rb_define_const(mSqlite3, "SQLITE_VERSION", rb_str_new2(SQLITE_VERSION));
Expand Down

0 comments on commit 918ffe0

Please sign in to comment.