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 06e47b4 commit 62193fa
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-only-l", "--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)
static_archive_path = File.join(lib_path, "libsqlite3.#{$LIBEXT}")
ldflags.delete("-lsqlite3")

if needs_darwin_linker_hack
ldflags.prepend("-Wl,-load_hidden,#{static_archive_path}")
ldflags.prepend("-Wl,-flat_namespace")
else
ldflags.prepend(static_archive_path)
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 62193fa

Please sign in to comment.