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

[draft] use mini_portile 2.8.5.rc2 to simplify extconf #405

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
11 changes: 9 additions & 2 deletions bin/test-gem-set
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@ function remove_all {
gem uninstall --all --force $1
}

function assert_sqlite_version_matches {
ruby -r sqlite3 -e '\
puts "compiled #{SQLite3::SQLITE_VERSION} / loaded #{SQLite3::SQLITE_LOADED_VERSION}"; \
raise("sqlite version mismatch") unless SQLite3::SQLITE_VERSION == SQLite3::SQLITE_LOADED_VERSION; \
'
}

function test_installation {
gem=$1

# test installation
remove_all sqlite3
gem install $gem
ruby -r sqlite3 -e 'pp SQLite3::SQLITE_VERSION, SQLite3::SQLITE_LOADED_VERSION'
assert_sqlite_version_matches

if [[ $gem =~ sqlite3-[^-]*\.gem ]] ; then
# test installation against system libs without mini_portile, linux distro repackagers
Expand All @@ -36,7 +43,7 @@ function test_installation {
# test installation against system libs
remove_all sqlite3
gem install $gem -- --enable-system-libraries
ruby -r sqlite3 -e 'pp SQLite3::SQLITE_VERSION, SQLite3::SQLITE_LOADED_VERSION'
assert_sqlite_version_matches
fi
}

Expand Down
46 changes: 14 additions & 32 deletions ext/sqlite3/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ def sqlcipher?
def configure_system_libraries
pkg_config(libname)
append_cppflags("-DUSING_SQLCIPHER") if sqlcipher?

if find_header("sqlite3.h")
# noop
elsif sqlcipher? && find_header("sqlcipher/sqlite3.h")
append_cppflags("-DUSING_SQLCIPHER_INC_SUBDIR")
else
abort_could_not_find("sqlite3.h")
end

abort_could_not_find(libname) unless find_library(libname, "sqlite3_libversion_number", "sqlite3.h")
end

def configure_packaged_libraries
Expand All @@ -65,29 +75,9 @@ def configure_packaged_libraries
unless File.exist?(File.join(recipe.target, recipe.host, recipe.name, recipe.version))
recipe.cook
end
recipe.activate

# on macos, pkg-config will not return --cflags without this
ENV["PKG_CONFIG_ALLOW_SYSTEM_CFLAGS"] = "t"

# only needed for Ruby 3.1.3, see https://bugs.ruby-lang.org/issues/19233
RbConfig::CONFIG["PKG_CONFIG"] = config_string("PKG_CONFIG") || "pkg-config"

lib_path = File.join(recipe.path, "lib")
pcfile = File.join(lib_path, "pkgconfig", "sqlite3.pc")
abort_pkg_config("pkg_config") unless pkg_config(pcfile)

# see https://bugs.ruby-lang.org/issues/18490
ldflags = xpopen(["pkg-config", "--libs", "--static", pcfile], err: [:child, :out], &:read)
abort_pkg_config("xpopen") unless $?.success?
ldflags = ldflags.split

# see https://github.com/flavorjones/mini_portile/issues/118
"-L#{lib_path}".tap do |lib_path_flag|
ldflags.prepend(lib_path_flag) unless ldflags.include?(lib_path_flag)
end

ldflags.each { |ldflag| append_ldflags(ldflag) }
recipe.mkmf_config(pkg: libname, static: libname)
have_func("sqlite3_libversion_number", "sqlite3.h") || abort_could_not_find(libname)
end
end

Expand All @@ -98,16 +88,6 @@ def configure_extension

append_cflags("-fvisibility=hidden") # see https://github.com/rake-compiler/rake-compiler-dock/issues/87

if find_header("sqlite3.h")
# noop
elsif sqlcipher? && find_header("sqlcipher/sqlite3.h")
append_cppflags("-DUSING_SQLCIPHER_INC_SUBDIR")
else
abort_could_not_find("sqlite3.h")
end

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 All @@ -131,6 +111,8 @@ def configure_extension
end

def minimal_recipe
require "rubygems"
gem "mini_portile2", "2.8.5.rc2" # gemspec is not respected at install time
require "mini_portile2"

MiniPortile.new(libname, sqlite3_config[:version]).tap do |recipe|
Expand Down
2 changes: 1 addition & 1 deletion sqlite3.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Gem::Specification.new do |s|
]
s.rdoc_options = ["--main", "README.md"]

s.add_dependency("mini_portile2", "~> 2.8.0")
s.add_dependency("mini_portile2", "2.8.5.rc2")

s.extensions << "ext/sqlite3/extconf.rb"
end