Skip to content

Commit 409b895

Browse files
committed
ext(native): work around darwin linker behavior in Ruby 3.2
rake-compiler/rake-compiler-dock#87
1 parent 155c6db commit 409b895

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

ext/sqlite3/extconf.rb

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,21 @@ def configure_packaged_libraries
7777
abort_pkg_config("pkg_config") unless pkg_config(pcfile)
7878

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

84-
# see https://github.com/flavorjones/mini_portile/issues/118
85-
"-L#{lib_path}".tap do |lib_path_flag|
86-
flags.prepend(lib_path_flag) unless flags.include?(lib_path_flag)
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
8792
end
8893

89-
flags.each { |flag| append_ldflags(flag) }
94+
ldflags.each { |ldflag| append_ldflags(ldflag) }
9095
end
9196
end
9297

@@ -172,6 +177,17 @@ def download
172177
minimal_recipe.download
173178
end
174179

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+
187+
def darwin?
188+
RbConfig::CONFIG["target_os"].include?("darwin")
189+
end
190+
175191
def print_help
176192
print(<<~TEXT)
177193
USAGE: ruby #{$PROGRAM_NAME} [options]

0 commit comments

Comments
 (0)