From ba7db0c517c9cdda3b07f08ffe1affcc1b075d7a Mon Sep 17 00:00:00 2001 From: Paul Mucur Date: Tue, 26 Mar 2024 08:02:24 +0000 Subject: [PATCH] Ensure we don't add `lre2` to `$LIBS` 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. --- ext/re2/extconf.rb | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/ext/re2/extconf.rb b/ext/re2/extconf.rb index 8e9f9c4..20a7e5a 100644 --- a/ext/re2/extconf.rb +++ b/ext/re2/extconf.rb @@ -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 @@ -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 int main() { return 0; } @@ -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