Skip to content

Commit 31abd7c

Browse files
author
Ben Li
committed
Fixes to building packaged libsqlite3.
Ensure that we are linking to the packaged library, even in cases where libsqlite is available in the system. * Move or replace all mkmf calls that would add -lsqlite3 to the command line: pkg_config, find_library * Explicitly link against the built sqlite3 as a static library.
1 parent 0cfccfc commit 31abd7c

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

ext/sqlite3/extconf.rb

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ def sqlcipher?
4545
def configure_system_libraries
4646
pkg_config(libname)
4747
append_cppflags("-DUSING_SQLCIPHER") if sqlcipher?
48+
49+
abort_could_not_find(libname) unless find_library(libname, "sqlite3_libversion_number", "sqlite3.h")
4850
end
4951

5052
def configure_packaged_libraries
@@ -83,19 +85,20 @@ def configure_packaged_libraries
8385

8486
lib_path = File.join(recipe.path, "lib")
8587
pcfile = File.join(lib_path, "pkgconfig", "sqlite3.pc")
86-
abort_pkg_config("pkg_config") unless pkg_config(pcfile)
88+
libfile = File.join(lib_path, "libsqlite3.a")
8789

88-
# see https://bugs.ruby-lang.org/issues/18490
89-
ldflags = xpopen(["pkg-config", "--libs", "--static", pcfile], err: [:child, :out], &:read)
90-
abort_pkg_config("xpopen") unless $?.success?
91-
ldflags = ldflags.split
90+
# Avoid one-arg pkg_config call adding -lsqlite3
91+
pkg_cflags = pkg_config(pcfile, "cflags")
92+
# Include directories are prioritized over system defaults
93+
append_cflags(pkg_cflags)
9294

93-
# see https://github.com/flavorjones/mini_portile/issues/118
94-
"-L#{lib_path}".tap do |lib_path_flag|
95-
ldflags.prepend(lib_path_flag) unless ldflags.include?(lib_path_flag)
96-
end
95+
# Force static linkage to packaged libsqlite3
96+
append_ldflags(libfile)
9797

98-
ldflags.each { |ldflag| append_ldflags(ldflag) }
98+
# Pull dependencies but not the library itself
99+
pkg_libs = pkg_config(pcfile, "libs-only-l", "static")
100+
pkg_libs.sub!(/\w*-lsqlite3\w*/, "")
101+
append_ldflags(pkg_libs)
99102

100103
append_cppflags("-DUSING_PACKAGED_LIBRARIES")
101104
append_cppflags("-DUSING_PRECOMPILED_LIBRARIES") if cross_build?
@@ -113,8 +116,6 @@ def configure_extension
113116
abort_could_not_find("sqlite3.h")
114117
end
115118

116-
abort_could_not_find(libname) unless find_library(libname, "sqlite3_libversion_number", "sqlite3.h")
117-
118119
# Truffle Ruby doesn't support this yet:
119120
# https://github.com/oracle/truffleruby/issues/3408
120121
have_func("rb_enc_interned_str_cstr")

0 commit comments

Comments
 (0)