Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds --with-sqlcipher flag #232

Merged
merged 7 commits into from
Jun 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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