Project

General

Profile

Actions

Feature #18490

closed

MakeMakefile.pkg_config should accept multiple options

Added by mdalessio (Mike Dalessio) 4 months ago. Updated 3 months ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:107128]

Description

Summary

When building static libraries it is sometimes necessary to pass multiple flags to pkg-config. Currently, MakeMakefile.pkg_config does not allow this.

A PR has been submitted at https://github.com/ruby/ruby/pull/5436

Real-world example

One example of this is the libmagic library which is wrapped by the ruby-magic gem. The ruby-magic gem's extconf.rb needs to pass two options to pkg-config, so that the command executed should be:

pkg-config --libs --static libmagic

(Note that passing only --libs then only --static and merging the results is not sufficient; both must be passed on the same invocation.)

MakeMakefile.pkg_config only supports passing one option to pkg-config today.

Historical context

Prior to Ruby 3.1.0, it was possible to work around this limitation by crafting an options string like so:

pkg_config('libmagic', 'libs --static')

The option parameter would be interpolated into the command template as variable opt:

"#{$PKGCONFIG} --#{opt} #{pkg}

resulting in the desired command string of pkg-config --libs --static libmagic.

However, with commit https://github.com/ruby/ruby/commit/dff8d12 this hack stopped working because the underlying ruby code is now:

xpopen([*envs, $PKGCONFIG, "--#{opt}", pkg], err:[:child, :out], &:read)

which results in pkg-config returning an error:

"Unknown option --libs --static\n"

Updated by mdalessio (Mike Dalessio) 4 months ago

Pinging @nobu (Nobuyoshi Nakada) for feedback as he is the primary maintainer of mkmf

Updated by nobu (Nobuyoshi Nakada) 4 months ago

Thank you for the report and patch.
It seems fine.
Could you split adding tests of existing methods from the new feature?

Updated by mdalessio (Mike Dalessio) 4 months ago

Thank you for taking the time to review. I've split the commit as you requested:

https://github.com/ruby/ruby/pull/5436/commits

Updated by mdalessio (Mike Dalessio) 4 months ago

@nobu (Nobuyoshi Nakada), I wanted to check if there was any other feedback on this feature? Thank you again for your time.

Updated by matz (Yukihiro Matsumoto) 4 months ago

  • Assignee set to nobu (Nobuyoshi Nakada)

Accepted.

Matz.

Actions #6

Updated by nobu (Nobuyoshi Nakada) 3 months ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF