Skip to content

Commit c8c1eb3

Browse files
committed
ext: export only Init_sqlite3_native
This works around new Darwin Ruby 3.2 symbol resolution issues, but also follows best practices around shipping shared libraries. Note that we remove the `-flat_namespace` hack because the latest rake-compiler-docker images have the changes from rake-compiler/rake-compiler-dock#94
1 parent 1815290 commit c8c1eb3

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

ext/sqlite3/extconf.rb

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def configure_packaged_libraries
5555
additional_cflags = [
5656
"-fPIC", # needed for linking the static library into a shared library
5757
"-O2", # see https://github.com/sparklemotion/sqlite3-ruby/issues/335 for some benchmarks
58+
"-fvisibility=hidden", # see https://github.com/rake-compiler/rake-compiler-dock/issues/87
5859
]
5960
env["CFLAGS"] = [env["CFLAGS"], additional_cflags].flatten.join(" ")
6061
recipe.configure_options += env.select { |k,v| ENV_ALLOWLIST.include?(k) }
@@ -81,14 +82,9 @@ def configure_packaged_libraries
8182
abort_pkg_config("xpopen") unless $?.success?
8283
ldflags = ldflags.split
8384

84-
if needs_darwin_linker_hack
85-
ldflags.delete("-lsqlite3")
86-
ldflags.prepend("-Wl,-flat_namespace", "-Wl,-hidden-lsqlite3")
87-
else
88-
# see https://github.com/flavorjones/mini_portile/issues/118
89-
"-L#{lib_path}".tap do |lib_path_flag|
90-
ldflags.prepend(lib_path_flag) unless ldflags.include?(lib_path_flag)
91-
end
85+
# see https://github.com/flavorjones/mini_portile/issues/118
86+
"-L#{lib_path}".tap do |lib_path_flag|
87+
ldflags.prepend(lib_path_flag) unless ldflags.include?(lib_path_flag)
9288
end
9389

9490
ldflags.each { |ldflag| append_ldflags(ldflag) }
@@ -100,6 +96,8 @@ def configure_extension
10096
append_cppflags("-DTAINTING_SUPPORT")
10197
end
10298

99+
append_cflags("-fvisibility=hidden") # see https://github.com/rake-compiler/rake-compiler-dock/issues/87
100+
103101
if find_header("sqlite3.h")
104102
# noop
105103
elsif sqlcipher? && find_header("sqlcipher/sqlite3.h")
@@ -177,13 +175,6 @@ def download
177175
minimal_recipe.download
178176
end
179177

180-
def needs_darwin_linker_hack
181-
# See https://github.com/rake-compiler/rake-compiler-dock/issues/87 for more info.
182-
cross_build? &&
183-
darwin? &&
184-
RbConfig::CONFIG["ruby_version"] >= "3.2"
185-
end
186-
187178
def darwin?
188179
RbConfig::CONFIG["target_os"].include?("darwin")
189180
end

ext/sqlite3/sqlite3.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ void init_sqlite3_constants()
127127
#endif
128128
}
129129

130+
RUBY_FUNC_EXPORTED
130131
void Init_sqlite3_native()
131132
{
132133
/*

0 commit comments

Comments
 (0)