From ac9bd16e3f1b676224156d3c1302cc190baadade Mon Sep 17 00:00:00 2001 From: Oskar Eichler Date: Fri, 28 Aug 2026 03:43:15 +0300 Subject: [PATCH 1/2] Let explicit PKG_CONFIG_LIBDIR replace default search paths --- lib/pkg-config.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/pkg-config.rb b/lib/pkg-config.rb index 542d67c..af5a696 100644 --- a/lib/pkg-config.rb +++ b/lib/pkg-config.rb @@ -264,6 +264,14 @@ def compute_native_pkg_config_prefix end def compute_default_path + libdir = ENV["PKG_CONFIG_LIBDIR"] + if libdir + return [ + with_config("pkg-config-path") || ENV["PKG_CONFIG_PATH"], + libdir, + ].compact.join(SEPARATOR) + end + default_paths = nil if native_pkg_config pc_path = run_command(native_pkg_config.to_s, @@ -315,9 +323,6 @@ def compute_default_path mingw_pkgconfig_path = Pathname.new(mingw_bin_path) + "../lib/pkgconfig" default_paths.unshift(mingw_pkgconfig_path.cleanpath.to_s) end - libdir = ENV["PKG_CONFIG_LIBDIR"] - default_paths.unshift(libdir) if libdir - paths = [] if /-darwin\d[\d\.]*\z/ =~ RUBY_PLATFORM and /\A(\d+\.\d+)/ =~ run_command("sw_vers", "-productVersion") From c6a8ecca70b4ed3b7bacf002785e9672b4050be9 Mon Sep 17 00:00:00 2001 From: Oskar Eichler <62393985+OskarEichler@users.noreply.github.com> Date: Fri, 28 Aug 2026 15:18:51 +0300 Subject: [PATCH 2/2] Add regression coverage for let explicit pkg_config_libdir replace default search paths --- test/test-pkg-config.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/test-pkg-config.rb b/test/test-pkg-config.rb index 67893b3..222e736 100644 --- a/test/test-pkg-config.rb +++ b/test/test-pkg-config.rb @@ -21,6 +21,21 @@ def setup @glib = PackageConfig.new("glib-2.0", options) end + def test_explicit_libdir_replaces_default_paths + original_libdir = ENV["PKG_CONFIG_LIBDIR"] + original_path = ENV["PKG_CONFIG_PATH"] + ENV["PKG_CONFIG_LIBDIR"] = "/isolated/pkgconfig" + ENV["PKG_CONFIG_PATH"] = "/extra/pkgconfig" + assert_equal([ + "/extra/pkgconfig", + "/isolated/pkgconfig", + ].join(File::PATH_SEPARATOR), + PackageConfig.__send__(:compute_default_path)) + ensure + ENV["PKG_CONFIG_LIBDIR"] = original_libdir + ENV["PKG_CONFIG_PATH"] = original_path + end + def only_pkg_config_version(major, minor) pkg_config_version = `#{@pkgconf} --version`.chomp current_major, current_minor = pkg_config_version.split(".").collect(&:to_i)