#3 Remove rubygem-pkg-config.
Opened 10 months ago by jaruga. Modified 10 months ago
rpms/ jaruga/rubygem-nokogiri feature/remove-rubygem-pkg-config  into  master

file modified
+10 -3

@@ -1,7 +1,7 @@ 

  %global	mainver		1.8.4

  #%%global	prever		.rc3

  

- %global	mainrel		1

+ %global	mainrel		2

  %global	prerpmver		%(echo "%{?prever}" | sed -e 's|\\.||g')

  

  %global	gem_name	nokogiri

@@ -11,7 +11,7 @@ 

  Summary:	An HTML, XML, SAX, and Reader parser

  Name:		rubygem-%{gem_name}

  Version:	%{mainver}

- Release:	%{?prever:0.}%{mainrel}%{?prever:.%{prerpmver}}%{?dist}.1

+ Release:	%{?prever:0.}%{mainrel}%{?prever:.%{prerpmver}}%{?dist}

  Group:		Development/Languages

  License:	MIT

  URL:		http://nokogiri.rubyforge.org/nokogiri/

@@ -32,7 +32,6 @@ 

  ##

  ## Others

  BuildRequires:	gcc

- BuildRequires:	rubygem(pkg-config)

  BuildRequires:	libxml2-devel

  BuildRequires:	libxslt-devel

  BuildRequires:	ruby-devel

@@ -109,6 +108,11 @@ 

  mkdir -p ./%{gem_dir}

  # 1.6.0 needs this

  export NOKOGIRI_USE_SYSTEM_LIBRARIES=yes

+ # mkmf.rb pkg_config method in extconf.rb does not work on -Wunused-parameter

+ # environment, even when pkg-config command works.

+ # A workflow to use pkg-config command correctly until below patch is applied.

+ # https://github.com/ruby/ruby/commit/4f03a23

+ %global optflags %{?optflags} -Wno-unused-parameter

  

  %gem_install

  

@@ -218,6 +222,9 @@ 

  %{gem_dir}/doc/%{gem_name}-%{mainver}%{?prever}/

  

  %changelog

+ * Fri Aug 17 2018 Jun Aruga <jaruga@redhat.com> - 1.8.4-2

+ - Remove rubygem-pkg-config.

+ 

  * Sat Jul 14 2018 Fedora Release Engineering <releng@fedoraproject.org> - 1.8.4-1.1

  - Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild

  

I wondered why installed pkg-config command does not work on building nokogiri, and we have to use rubygem-pkg-config.
On building nokogiri, the pkg_config method returns always nil.
But when I run the method directly, it works.
And there was a bug.
It happens when -Wunused-parameter is enabled.

[mockbuild@3dc040faf5a944ef92f6d73c9f175968 nokogiri-1.8.4]$ pkg-config --libs libxml-2.0
-lxml2
[mockbuild@3dc040faf5a944ef92f6d73c9f175968 nokogiri-1.8.4]$ pkg-config --libs libxslt
-lxslt -lm -lxml2
[mockbuild@3dc040faf5a944ef92f6d73c9f175968 nokogiri-1.8.4]$ pkg-config --libs libexslt
-lexslt -lxslt -lm -lgcrypt -ldl -lgpg-error -lxml2

[mockbuild@3dc040faf5a944ef92f6d73c9f175968 nokogiri-1.8.4]$ ruby -e 'require "mkmf"; p(pkg_config("libxml-2.0"))'
["", "", "-lxml2"]
[mockbuild@3dc040faf5a944ef92f6d73c9f175968 nokogiri-1.8.4]$ ruby -e 'require "mkmf"; p(pkg_config("libxslt"))'
["", "", "-lxslt -lm -lxml2"]
[mockbuild@3dc040faf5a944ef92f6d73c9f175968 nokogiri-1.8.4]$ ruby -e 'require "mkmf"; p(pkg_config("libexslt"))'
["", "", "-lexslt -lxslt -lm -lgcrypt -ldl -lgpg-error -lxml2"]

Maybe the bug was injected on Ruby 2.3.0.
https://github.com/ruby/ruby/commit/aceb11d

And will be fixed on Ruby 2.6.
https://github.com/ruby/ruby/commit/4f03a23

This pull-request is the temporary solution.

Scratch build: ok
https://koji.fedoraproject.org/koji/taskinfo?taskID=29149461

The detail.

Internally mkmf.rb pkg_config runs below steps.

  1. Create below conftest.c
#include "ruby.h"

int main(int argc, char **argv)
{
  return 0;
}
  1. Then run gcc to check the flags of package config.
    When "{:werror => true}", if even exit status is zero, if there is a stderr text, it is recognized as a error.

  2. As a result, pkg_config method returns nil.

$ gcc -o conftest -I/usr/include -I/usr/include/ruby/backward -I/usr/include -Iext/nokogiri -I/usr/include/libxml2    -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fPIC  -g -DXP_UNIX -Wall -Wcast-qual -Wwrite-strings -Wextra -Wmissing-noreturn -Winline  conftest.c  -L. -L/usr/lib64 -L. -Wl,-z,relro   -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -fstack-protector -rdynamic -Wl,-export-dynamic   -m64   -lxml2 -lruby -lxslt -lm -lxml2   -lc
conftest.c: In function 'main':
conftest.c:3:14: warning: unused parameter 'argc' [-Wunused-parameter]
 int main(int argc, char **argv)
          ~~~~^~~~
conftest.c:3:27: warning: unused parameter 'argv' [-Wunused-parameter]
 int main(int argc, char **argv)
                    ~~~~~~~^~~~

So we have rubygem-pkg-config, and even the maintainer of rubygem-pkg-config is me, so what is a problem?

And, on second thought, this must be fixed in ruby side. If "pkg_config" method does not work, it must be fixed there.

The reason was because a person asked to me create Rails 5.2 software collection including rubygem-nokogiri. And they have to create rubygem-pkg-config that thy have not prepared.

But you are right. Thinking again, the issue of pkg_config should be fixed on ruby side.
Ideally below issue could be backported.

https://github.com/ruby/ruby/commit/4f03a23
https://bugs.ruby-lang.org/issues/13069

Thank you for the opinion.
Feel free to close this ticket.

Asking the patch to merge to ruby to ruby_2_5 branch.
https://github.com/ruby/ruby/pull/1936