Skip to content

Commit

Permalink
ext: ensure sqlcipher is supported as a system library
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Jul 4, 2022
1 parent 998431c commit b7e0d3e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 31 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/sqlite3-ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,36 @@ jobs:
- run: bundle install
- run: bundle exec rake compile -- --enable-system-libraries
- run: bundle exec rake test

sqlcipher:
strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "macos-latest", "windows-2022"]
ruby: ["3.1", "2.5"] # oldest and newest
include:
- os: "windows-2022"
ruby: "mingw"
# # I'm struggling to build against sqlcipher on mswin.
# # find_header can't find sqlite3.h
# # patches welcome from anyone who needs this functionality and can make it work.
# - os: "windows-2022"
# ruby: "mswin"
runs-on: ${{matrix.os}}
steps:
- if: matrix.os == 'windows-2022'
name: configure git crlf
run: |
git config --system core.autocrlf false
git config --system core.eol lf
- uses: actions/checkout@v3
- uses: ruby/setup-ruby-pkgs@v1
with:
ruby-version: ${{matrix.ruby}}
bundler-cache: true
apt-get: "libsqlcipher-dev"
brew: "sqlcipher"
mingw: "sqlcipher"
# vcpkg: "sqlcipher" # see above
- run: bundle exec rake compile -- --with-sqlcipher
- run: bundle exec rake test
43 changes: 12 additions & 31 deletions ext/sqlite3/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@
ENV["CC"] = RbConfig::CONFIG["CC"]

cross_build_p = enable_config("cross-build")
system_libraries_p = enable_config("system-libraries")
sqlcipher_p = with_config("sqlcipher")
system_libraries_p = sqlcipher_p || enable_config("system-libraries")
libname = sqlcipher_p ? "sqlcipher" : "sqlite3"

def abort_could_not_find(missing)
abort("Could not find #{missing}. Please visit https://github.com/sparklemotion/sqlite3-ruby for installation instructions.")
end

if system_libraries_p
# if sqlcipher_p # TODO test and document this
# message "Building sqlite3-ruby using system sqlcipher.\n"
# pkg_config("sqlcipher") # TODO test and document this
# else
message "Building sqlite3-ruby using system sqlite3.\n"
pkg_config("sqlite3") # TODO document
# end
message "Building sqlite3-ruby using system #{libname}.\n"
pkg_config(libname)
append_cflags("-DUSING_SQLCIPHER") if sqlcipher_p

else
message "Building sqlite3-ruby using packaged sqlite3.\n"
MiniPortile.new("sqlite3", "3.38.5").tap do |recipe|
Expand Down Expand Up @@ -66,29 +68,8 @@

append_cflags("-DTAINTING_SUPPORT") if Gem::Requirement.new("< 2.7").satisfied_by?(Gem::Version.new(RUBY_VERSION))

def abort_could_not_find_library(missing)
if RUBY_PLATFORM =~ /mingw|mswin/
abort "#{missing} is missing. Install SQLite3 from " +
"http://www.sqlite.org/ first."
else
abort <<-error
#{missing} is missing. Try 'brew install sqlite3',
'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
and check your shared library search path (the
location where your sqlite3 shared library is located).
error
end
end

abort_could_not_find_library('sqlite3.h') unless find_header 'sqlite3.h'

# TODO sqlcipher support
# if with_config('sqlcipher')
# append_cflags("-DUSING_SQLCIPHER")
# abort_could_not_find_library('sqlcipher') unless find_library 'sqlcipher', 'sqlite3_libversion_number'
# else
abort_could_not_find_library('sqlite3') unless find_library("sqlite3", "sqlite3_libversion_number", "sqlite3.h")
# end
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")

# Functions defined in 1.9 but not 1.8
have_func('rb_proc_arity')
Expand Down
3 changes: 3 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
end

puts "info: sqlite3 version: #{SQLite3::SQLITE_VERSION}/#{SQLite3::SQLITE_LOADED_VERSION}"
puts "info: sqlcipher?: #{SQLite3.sqlcipher?}"
puts "info: threadsafe?: #{SQLite3.threadsafe?}"

unless RUBY_VERSION >= "1.9"
require 'iconv'
end
Expand Down

0 comments on commit b7e0d3e

Please sign in to comment.