From a2aa62da61dbda176b2a9e4d5bc99cad515d8302 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Sun, 18 Oct 2026 06:37:59 +0900 Subject: [PATCH 1/3] Treat clang-cl as MSVC on mswin A mswin Ruby built with clang-cl has `clang-cl` in `RbConfig::CONFIG["CC"]`, so `PKGConfig.msvc?` returned false and libs came out as `-L`/`-l` instead of `/libpath:` and `foo.lib`. Extensions using them failed to link. Co-Authored-By: Claude Opus 5.5 --- lib/pkg-config.rb | 3 ++- test/test-pkg-config.rb | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/pkg-config.rb b/lib/pkg-config.rb index 542d67c..98fc5b3 100644 --- a/lib/pkg-config.rb +++ b/lib/pkg-config.rb @@ -34,7 +34,8 @@ def set_override_variable(key, value) end def msvc? - /mswin/.match(RUBY_PLATFORM) and /^cl\b/.match(RbConfig::CONFIG["CC"]) + /mswin/.match(RUBY_PLATFORM) and + /^(?:clang-)?cl\b/.match(RbConfig::CONFIG["CC"]) end def package_config(package) diff --git a/test/test-pkg-config.rb b/test/test-pkg-config.rb index 67893b3..9529c96 100644 --- a/test/test-pkg-config.rb +++ b/test/test-pkg-config.rb @@ -344,4 +344,26 @@ def test_mixed "-DFOO", "-Wall", "-Wl,--as-needed"])) end end + + sub_test_case(".msvc?") do + def assert_msvc(expected, cc) + original_cc = RbConfig::CONFIG["CC"] + RbConfig::CONFIG["CC"] = cc + assert_equal(expected, !!PKGConfig.msvc?) + ensure + RbConfig::CONFIG["CC"] = original_cc + end + + def mswin? + RUBY_PLATFORM.include?("mswin") + end + + def test_cl + assert_msvc(mswin?, "cl -nologo -source-charset:utf-8") + end + + def test_clang_cl + assert_msvc(mswin?, "clang-cl -nologo -source-charset:utf-8") + end + end end From 788f8494f50afadefc2666cadc32eb818378571b Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Sun, 18 Oct 2026 18:14:10 +0900 Subject: [PATCH 2/3] Remove the msvc? tests They only exercised the regexp by swapping `RbConfig::CONFIG["CC"]`. Co-Authored-By: Claude Opus 5.5 --- test/test-pkg-config.rb | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/test/test-pkg-config.rb b/test/test-pkg-config.rb index 9529c96..67893b3 100644 --- a/test/test-pkg-config.rb +++ b/test/test-pkg-config.rb @@ -344,26 +344,4 @@ def test_mixed "-DFOO", "-Wall", "-Wl,--as-needed"])) end end - - sub_test_case(".msvc?") do - def assert_msvc(expected, cc) - original_cc = RbConfig::CONFIG["CC"] - RbConfig::CONFIG["CC"] = cc - assert_equal(expected, !!PKGConfig.msvc?) - ensure - RbConfig::CONFIG["CC"] = original_cc - end - - def mswin? - RUBY_PLATFORM.include?("mswin") - end - - def test_cl - assert_msvc(mswin?, "cl -nologo -source-charset:utf-8") - end - - def test_clang_cl - assert_msvc(mswin?, "clang-cl -nologo -source-charset:utf-8") - end - end end From 6fde07b73bf1e9dee6fbc50ac6bee81fc0eae999 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Sun, 18 Oct 2026 18:14:54 +0900 Subject: [PATCH 3/3] Use \A to anchor the CC match Co-Authored-By: Claude Opus 5.5 --- lib/pkg-config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pkg-config.rb b/lib/pkg-config.rb index 98fc5b3..93d9ed2 100644 --- a/lib/pkg-config.rb +++ b/lib/pkg-config.rb @@ -35,7 +35,7 @@ def set_override_variable(key, value) def msvc? /mswin/.match(RUBY_PLATFORM) and - /^(?:clang-)?cl\b/.match(RbConfig::CONFIG["CC"]) + /\A(?:clang-)?cl\b/.match(RbConfig::CONFIG["CC"]) end def package_config(package)