summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Marrec <julien.marrec@gmail.com>2024-02-02 09:40:38 +0100
committerNobuyoshi Nakada <nobu.nakada@gmail.com>2024-12-23 11:52:14 +0900
commitbe7e5f1f85685a757bea6c8dae4e30914a5eec67 (patch)
treee52e07f50e1e91042ab0aa024e8e9bbc4898084f
parentc695536cc8ea4be69849394b0c64c974d52c603a (diff)
Implements [Feature #3456]: Support pkgconf on windows
1. Store the `PKG_CONFIG` variable in Makefile.sub (or try to get it from the ENV var PKG_CONFIG in mkmf.rb) 2. Try to use --msvc-syntax, with a fallback to replacing -Lxxx with -libpath:xxx. --msvc-syntax has been in pkgconf since 1.4.0 (released 7 years ago). pkg-config (freedesktop), does not support it, hence the fallback. 3. The `try_ldflags` passes these `ldflags` as the `opt` parameter to the `link_command`, not as `ldflags`. Unix systems are forgiving in that regard, MSVC is not: as a result as passing them as `opt`, they (specifically the `/libpath:xxx` ones) end up passed before the `-link` command to `cl.exe` and it throws because it ignores it and therefore can't find the lib. ``` cl : Command line warning D9002 : ignoring unknown option '-libpath:C:/Users/julien/.conan2/p/libff3726d89a6255c/p/lib' ```
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/9815
-rw-r--r--lib/mkmf.rb33
-rw-r--r--win32/Makefile.sub1
2 files changed, 29 insertions, 5 deletions
diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index d970e9a6ad..0001d5926f 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -604,9 +604,9 @@ MSG
yield(opt, opts)
end
- def try_link0(src, opt = "", **opts, &b) # :nodoc:
+ def try_link0(src, opt = "", ldflags: "", **opts, &b) # :nodoc:
exe = CONFTEST+$EXEEXT
- cmd = link_command("", opt)
+ cmd = link_command(ldflags, opt)
if $universal
require 'tmpdir'
Dir.mktmpdir("mkmf_", oldtmpdir = ENV["TMPDIR"]) do |tmpdir|
@@ -750,7 +750,7 @@ MSG
# :nodoc:
def try_ldflags(flags, werror: $mswin, **opts)
- try_link(MAIN_DOES_NOTHING, flags, werror: werror, **opts)
+ try_link(MAIN_DOES_NOTHING, "", ldflags: flags, werror: werror, **opts)
end
# :startdoc:
@@ -1968,7 +1968,7 @@ SRC
if pkgconfig = with_config("#{pkg}-config") and find_executable0(pkgconfig)
# if and only if package specific config command is given
elsif ($PKGCONFIG ||=
- (pkgconfig = with_config("pkg-config") {config_string("PKG_CONFIG") || "pkg-config"}) &&
+ (pkgconfig = with_config("pkg-config") {config_string("PKG_CONFIG") || ENV["PKG_CONFIG"] || "pkg-config"}) &&
find_executable0(pkgconfig) && pkgconfig) and
xsystem([*envs, $PKGCONFIG, "--exists", pkg])
# default to pkg-config command
@@ -1980,11 +1980,34 @@ SRC
pkgconfig = nil
end
if pkgconfig
+ has_ms_win_syntax = false
+ if $mswin
+ has_ms_win_syntax = xpopen([pkgconfig, "--help"]).read.include?('msvc-syntax')
+ if has_ms_win_syntax
+ args << "--msvc-syntax"
+ else
+ Logging.message("WARNING: #{pkgconfig} does not support the --msvc-syntax. Try using a recent pkgconf instead")
+ end
+ end
get = proc {|opts|
opts = Array(opts).map { |o| "--#{o}" }
opts = xpopen([*envs, pkgconfig, *opts, *args], err:[:child, :out], &:read)
Logging.open {puts opts.each_line.map{|s|"=> #{s.inspect}"}}
- opts.strip if $?.success?
+ if $?.success?
+ opts = opts.strip
+ if $mswin and not has_ms_win_syntax
+ opts = Shellwords.shellwords(opts).map { |s|
+ if s.start_with?('-l')
+ "#{s[2..]}.lib"
+ elsif s.start_with?('-L')
+ "/libpath:#{s[2..]}"
+ else
+ s
+ end
+ }.quote.join(" ")
+ end
+ opts
+ end
}
end
orig_ldflags = $LDFLAGS
diff --git a/win32/Makefile.sub b/win32/Makefile.sub
index 2864c8ec3f..e4c64ad1b4 100644
--- a/win32/Makefile.sub
+++ b/win32/Makefile.sub
@@ -1168,6 +1168,7 @@ s,@top_srcdir@,$(srcdir),;t t
s,@try_header@,try_compile,;t t
s,@ruby_pc@,$(ruby_pc),;t t
s,@RJIT_SUPPORT@,$(RJIT_SUPPORT),;t t
+s,@PKG_CONFIG@,$(PKG_CONFIG),;t t
<<KEEP
!if "$(HAVE_BASERUBY)" != "yes" || "$(CROSS_COMPILING)" == "yes"