Feature #18490
closedMakeMakefile.pkg_config should accept multiple options
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) almost 3 years ago
Pinging @nobu (Nobuyoshi Nakada) for feedback as he is the primary maintainer of mkmf
Updated by nobu (Nobuyoshi Nakada) almost 3 years 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) almost 3 years ago
Thank you for taking the time to review. I've split the commit as you requested:
Updated by mdalessio (Mike Dalessio) almost 3 years 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) almost 3 years ago
- Assignee set to nobu (Nobuyoshi Nakada)
Accepted.
Matz.
Updated by nobu (Nobuyoshi Nakada) almost 3 years ago
- Status changed from Open to Closed