diff --git a/ext/.DS_Store b/ext/.DS_Store new file mode 100644 index 00000000..8c6c3d2f Binary files /dev/null and b/ext/.DS_Store differ diff --git a/ext/sqlite3/extconf.rb b/ext/sqlite3/extconf.rb index 3fafa8d3..bdd56995 100644 --- a/ext/sqlite3/extconf.rb +++ b/ext/sqlite3/extconf.rb @@ -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 @@ -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' @@ -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') diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index dedfdf5d..ede81ea6 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -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 */ @@ -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));