Skip to content

Commit b7e0d3e

Browse files
committed
ext: ensure sqlcipher is supported as a system library
1 parent 998431c commit b7e0d3e

3 files changed

Lines changed: 48 additions & 31 deletions

File tree

.github/workflows/sqlite3-ruby.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,36 @@ jobs:
6969
- run: bundle install
7070
- run: bundle exec rake compile -- --enable-system-libraries
7171
- run: bundle exec rake test
72+
73+
sqlcipher:
74+
strategy:
75+
fail-fast: false
76+
matrix:
77+
os: ["ubuntu-latest", "macos-latest", "windows-2022"]
78+
ruby: ["3.1", "2.5"] # oldest and newest
79+
include:
80+
- os: "windows-2022"
81+
ruby: "mingw"
82+
# # I'm struggling to build against sqlcipher on mswin.
83+
# # find_header can't find sqlite3.h
84+
# # patches welcome from anyone who needs this functionality and can make it work.
85+
# - os: "windows-2022"
86+
# ruby: "mswin"
87+
runs-on: ${{matrix.os}}
88+
steps:
89+
- if: matrix.os == 'windows-2022'
90+
name: configure git crlf
91+
run: |
92+
git config --system core.autocrlf false
93+
git config --system core.eol lf
94+
- uses: actions/checkout@v3
95+
- uses: ruby/setup-ruby-pkgs@v1
96+
with:
97+
ruby-version: ${{matrix.ruby}}
98+
bundler-cache: true
99+
apt-get: "libsqlcipher-dev"
100+
brew: "sqlcipher"
101+
mingw: "sqlcipher"
102+
# vcpkg: "sqlcipher" # see above
103+
- run: bundle exec rake compile -- --with-sqlcipher
104+
- run: bundle exec rake test

ext/sqlite3/extconf.rb

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@
77
ENV["CC"] = RbConfig::CONFIG["CC"]
88

99
cross_build_p = enable_config("cross-build")
10-
system_libraries_p = enable_config("system-libraries")
1110
sqlcipher_p = with_config("sqlcipher")
11+
system_libraries_p = sqlcipher_p || enable_config("system-libraries")
12+
libname = sqlcipher_p ? "sqlcipher" : "sqlite3"
13+
14+
def abort_could_not_find(missing)
15+
abort("Could not find #{missing}. Please visit https://github.com/sparklemotion/sqlite3-ruby for installation instructions.")
16+
end
1217

1318
if system_libraries_p
14-
# if sqlcipher_p # TODO test and document this
15-
# message "Building sqlite3-ruby using system sqlcipher.\n"
16-
# pkg_config("sqlcipher") # TODO test and document this
17-
# else
18-
message "Building sqlite3-ruby using system sqlite3.\n"
19-
pkg_config("sqlite3") # TODO document
20-
# end
19+
message "Building sqlite3-ruby using system #{libname}.\n"
20+
pkg_config(libname)
21+
append_cflags("-DUSING_SQLCIPHER") if sqlcipher_p
22+
2123
else
2224
message "Building sqlite3-ruby using packaged sqlite3.\n"
2325
MiniPortile.new("sqlite3", "3.38.5").tap do |recipe|
@@ -66,29 +68,8 @@
6668

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

69-
def abort_could_not_find_library(missing)
70-
if RUBY_PLATFORM =~ /mingw|mswin/
71-
abort "#{missing} is missing. Install SQLite3 from " +
72-
"http://www.sqlite.org/ first."
73-
else
74-
abort <<-error
75-
#{missing} is missing. Try 'brew install sqlite3',
76-
'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
77-
and check your shared library search path (the
78-
location where your sqlite3 shared library is located).
79-
error
80-
end
81-
end
82-
83-
abort_could_not_find_library('sqlite3.h') unless find_header 'sqlite3.h'
84-
85-
# TODO sqlcipher support
86-
# if with_config('sqlcipher')
87-
# append_cflags("-DUSING_SQLCIPHER")
88-
# abort_could_not_find_library('sqlcipher') unless find_library 'sqlcipher', 'sqlite3_libversion_number'
89-
# else
90-
abort_could_not_find_library('sqlite3') unless find_library("sqlite3", "sqlite3_libversion_number", "sqlite3.h")
91-
# end
71+
abort_could_not_find("sqlite3.h") unless find_header("sqlite3.h")
72+
abort_could_not_find(libname) unless find_library(libname, "sqlite3_libversion_number", "sqlite3.h")
9273

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

test/helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
end
77

88
puts "info: sqlite3 version: #{SQLite3::SQLITE_VERSION}/#{SQLite3::SQLITE_LOADED_VERSION}"
9+
puts "info: sqlcipher?: #{SQLite3.sqlcipher?}"
10+
puts "info: threadsafe?: #{SQLite3.threadsafe?}"
11+
912
unless RUBY_VERSION >= "1.9"
1013
require 'iconv'
1114
end

0 commit comments

Comments
 (0)