Skip to content

Commit

Permalink
ext(sqlcipher): add check to extconf for sqlcipher
Browse files Browse the repository at this point in the history
and add test coverage to make sure the compiled and loaded versions
are the same.
  • Loading branch information
flavorjones committed Aug 9, 2022
1 parent 80468df commit b6a7cc2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ext/sqlite3/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ def sqlcipher?
with_config("sqlcipher") ||
with_config("sqlcipher-dir") ||
with_config("sqlcipher-include") ||
with_config("sqlcipher-lib")
with_config("sqlcipher-lib") ||
false
end

def configure_system_libraries
pkg_config(libname)
append_cflags("-DUSING_SQLCIPHER") if sqlcipher?
end

def configure_packaged_libraries
Expand Down Expand Up @@ -81,6 +81,14 @@ def configure_extension
abort_could_not_find("sqlite3.h") unless find_header("sqlite3.h")
abort_could_not_find(libname) unless find_library(libname, "sqlite3_libversion_number", "sqlite3.h")

# double-check that we're using the expected library (sqlite3 or sqlcipher)
#
# note that sqlcipher doesn't provide a C function for its version :(
# https://github.com/sqlcipher/sqlcipher/issues/354
actually_sqlcipher = have_func("sqlcipher_activate")
abort("\nWanted #{libname} but sqlcipher is #{actually_sqlcipher}\n\n") if actually_sqlcipher != sqlcipher?
append_cflags("-DUSING_SQLCIPHER") if sqlcipher?

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

Expand Down
4 changes: 4 additions & 0 deletions test/test_sqlite3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,9 @@ def test_version_strings
skip if SQLite3::VERSION.include?("test") # see set-version-to-timestamp rake task
assert_equal(SQLite3::VERSION, SQLite3::VersionProxy::STRING)
end

def test_compiled_version_and_loaded_version
assert_equal(SQLite3::SQLITE_VERSION, SQLite3::SQLITE_LOADED_VERSION)
end
end
end

0 comments on commit b6a7cc2

Please # to comment.