Skip to content

Commit

Permalink
Ensure we don't add lre2 to $LIBS
Browse files Browse the repository at this point in the history
To ensure we link against the correct versions of Abseil and RE2 instead
of any in Ruby's exec_prefix, ensure we don't call `have_library` (which
will add `lre2` to `LIBS`) when compiling the vendored dependencies.
  • Loading branch information
mudge committed Mar 26, 2024
1 parent e72914f commit ba7db0c
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions ext/re2/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ def build_with_system_libraries
]

dir_config("re2", header_dirs, lib_dirs)

unless have_library("re2")
abort "You must have re2 installed and specified with --with-re2-dir, please see https://github.com/google/re2/wiki/Install"
end
end

def build_with_vendored_libraries
Expand Down Expand Up @@ -138,10 +142,6 @@ def build_extension
have_header("stdint.h")
have_func("rb_gc_mark_movable") # introduced in Ruby 2.7

unless have_library("re2")
abort "You must have re2 installed and specified with --with-re2-dir, please see https://github.com/google/re2/wiki/Install"
end

minimal_program = <<~SRC
#include <re2/re2.h>
int main() { return 0; }
Expand Down Expand Up @@ -232,20 +232,22 @@ def static_pkg_config(pc_file, pkg_config_paths)

# Replace all -l flags that can be found in one of the static library
# paths with the absolute path instead.
libflags = minimal_pkg_config(pc_file, '--libs-only-l', '--static')
minimal_pkg_config(pc_file, '--libs-only-l', '--static')
.shellsplit
.map do |flag|
next flag unless flag.start_with?('-l')

lib = "lib#{flag.delete_prefix('-l')}.#{$LIBEXT}"
static_lib_path = static_library_paths.find { |path| File.exist?(File.join(path, lib)) }
next flag unless static_lib_path

File.join(static_lib_path, lib)
.each do |flag|
if flag.start_with?('-l')
lib = "lib#{flag.delete_prefix('-l')}.#{$LIBEXT}"

if (static_lib_path = static_library_paths.find { |path| File.exist?(File.join(path, lib)) })
$LDFLAGS << ' ' << File.join(static_lib_path, lib)
else
append_ldflags(flag.shellescape)
end
else
append_ldflags(flag.shellescape)
end
end

$libs = [libflags, $libs].join(" ").strip

incflags = minimal_pkg_config(pc_file, '--cflags-only-I')
$INCFLAGS = [incflags, $INCFLAGS].join(" ").strip

Expand Down

0 comments on commit ba7db0c

Please sign in to comment.