Precompiled Ruby bakes the build machine's PKG_CONFIG into rbconfig.rb, breaking native gems that use mkmf's pkg_config eg. ruby-magic
#10913
SummaryPrecompiled rubies from $ ruby -rrbconfig -e 'p RbConfig::CONFIG["PKG_CONFIG"], RbConfig::MAKEFILE_CONFIG["PKG_CONFIG"]'
"/Users/runner/work/ruby/ruby/.build/4.0.5-macos-yjit/tools/bin/pkgconf"
"/Users/runner/work/ruby/ruby/.build/4.0.5-macos-yjit/tools/bin/pkgconf"That path does not exist on an end-user machine. Any gem whose Environment
Reproduction$ which pkg-config
/opt/homebrew/bin/pkg-config
$ gem install ruby-magic -v 0.6.0
...
checking for pkg-config for .../ports/arm64-apple-darwin23/libmagic/5.44/lib/pkgconfig/libmagic.pc... not found
extconf.rb:322:in '<main>': Please install the `pkg-config` utility! (RuntimeError)Note that $ pkg-config --exists .../libmagic/5.44/lib/pkgconfig/libmagic.pc; echo $?
0ruby-magic's error text is its own (it turns a nil return from Root cause
Too much detail
def build_env(extra = {})
{
"PATH" => [File.join(@tools_prefix, "bin"), ENV["PATH"]].compact.join(File::PATH_SEPARATOR),
"PKG_CONFIG" => pkgconf,
"MAKEFLAGS" => "-j#{jobs}"
}.merge(extra.reject { |_key, value| value.to_s.empty? })
endRuby's It's fatal rather than degraded because if pkgconfig = with_config("#{pkg}-config") and find_executable0(pkgconfig)
elsif ($PKGCONFIG ||=
(pkgconfig = with_config("pkg-config") {config_string("PKG_CONFIG") || ENV["PKG_CONFIG"] || "pkg-config"}) &&
find_executable0(pkgconfig) && pkgconfig) and
xsystem([*envs, $PKGCONFIG, "--exists", pkg])
Note this also makes the Also worth knowing: mkmf's Suggested fixIn [CONFIG, MAKEFILE_CONFIG].each do |config|
config["PKG_CONFIG"] = ""
end
$ ruby -rmkmf -e 'RbConfig::MAKEFILE_CONFIG["PKG_CONFIG"] = ""
p(config_string("PKG_CONFIG") || ENV["PKG_CONFIG"] || "pkg-config")'
"pkg-config"Hard-coding Workaround for anyone hitting this now$ bundle config set --local build.ruby-magic "--with-pkg-config=$(which pkg-config)"
|
Replies: 1 comment
|
Thanks for the exceptionally detailed report. This was exactly the root cause. The fix landed in jdx/ruby#55: the portability patch now removes I rebuilt the current supported patch releases from the fixed commit: The floating release tags now point at those fixed builds. I also tested the published macOS Anyone with an already-installed affected Ruby will need to uninstall and reinstall that version to pick up the rebuilt artifact. Historical patch releases have not been rebuilt yet. This comment was generated by an AI coding assistant. |
Thanks for the exceptionally detailed report. This was exactly the root cause.
The fix landed in jdx/ruby#55: the portability patch now removes
PKG_CONFIGfrom bothRbConfig::CONFIGandRbConfig::MAKEFILE_CONFIG, allowing mkmf to honorENV["PKG_CONFIG"]or findpkg-configonPATH.I rebuilt the current supported patch releases from the fixed commit:
The floating release tags now point at those fixed builds. I also tested the published macOS
4.0.5artifact through mise withruby.compile = false: bothPKG_CONFIGkeys were absent,ruby-magic0.6.0 built successfully using Homebrewpkg-config, and its native extension loaded correctly.A…