Skip to content

Commit

Permalink
ext(native): work around darwin linker behavior in Ruby 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Jan 2, 2023
1 parent 155c6db commit 409b895
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions ext/sqlite3/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,21 @@ def configure_packaged_libraries
abort_pkg_config("pkg_config") unless pkg_config(pcfile)

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

# see https://github.com/flavorjones/mini_portile/issues/118
"-L#{lib_path}".tap do |lib_path_flag|
flags.prepend(lib_path_flag) unless flags.include?(lib_path_flag)
if needs_darwin_linker_hack
ldflags.delete("-lsqlite3")
ldflags.prepend("-Wl,-flat_namespace", "-Wl,-hidden-lsqlite3")
else
# 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
end

flags.each { |flag| append_ldflags(flag) }
ldflags.each { |ldflag| append_ldflags(ldflag) }
end
end

Expand Down Expand Up @@ -172,6 +177,17 @@ def download
minimal_recipe.download
end

def needs_darwin_linker_hack
# See https://github.com/rake-compiler/rake-compiler-dock/issues/87 for more info.
cross_build? &&
darwin? &&
RbConfig::CONFIG["ruby_version"] >= "3.2"
end

def darwin?
RbConfig::CONFIG["target_os"].include?("darwin")
end

def print_help
print(<<~TEXT)
USAGE: ruby #{$PROGRAM_NAME} [options]
Expand Down

0 comments on commit 409b895

Please sign in to comment.