Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[install] OpenBSD: Failed to build gem native extension on Ruby 3.0.3 #2487

Closed
basicfeatures opened this issue Mar 29, 2022 · 10 comments · Fixed by #2505
Closed

[install] OpenBSD: Failed to build gem native extension on Ruby 3.0.3 #2487

basicfeatures opened this issue Mar 29, 2022 · 10 comments · Fixed by #2505

Comments

@basicfeatures
Copy link

Hello!

I'm using OpenBSD 7.0's official Ruby 3.0.3 package. I've replaced GCC with Clang in my environment, and restricted installs to user accounts for added security.

% pkg_add ruby-3.0.3

% echo "path+=(/home/basic/.local/share/gem/ruby/3.0/bin)" >> ~/.zprofile
% source ~/.zprofile

% cc --version
OpenBSD clang version 11.1.0
Target: amd64-unknown-openbsd7.0
Thread model: posix
InstalledDir: /usr/bin

% gem env
RubyGems Environment:
  - RUBYGEMS VERSION: 3.2.32
  - RUBY VERSION: 3.0.3 (2021-11-24 patchlevel 157) [x86_64-openbsd]
  - INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/3.0
  - USER INSTALLATION DIRECTORY: /home/basic/.local/share/gem/ruby/3.0
  - RUBY EXECUTABLE: /usr/local/bin/ruby30
  - GIT EXECUTABLE: /usr/local/bin/git
  - EXECUTABLE DIRECTORY: /usr/local/bin
  - SPEC CACHE DIRECTORY: /home/basic/.local/share/gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /etc
  - RUBYGEMS PLATFORMS:
     - ruby
     - x86_64-openbsd
  - GEM PATHS:
     - /usr/local/lib/ruby/gems/3.0
     - /home/basic/.local/share/gem/ruby/3.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /home/basic/.local/share/gem/ruby/3.0/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin
     - /usr/X11R6/bin
     - /usr/local/bin
     - /usr/local/sbin

% env
USER=basic
LOGNAME=basic
HOME=/home/basic
PATH=/home/basic/.local/share/gem/ruby/3.0/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin
SHELL=/usr/local/bin/zsh
PWD=/home/basic
CC=/usr/bin/clang
CXX=/usr/bin/clang++
_=/usr/bin/env

% gem install --user-install nokogiri
Building native extensions. This could take a while...
ERROR:  Error installing nokogiri:
        ERROR: Failed to build gem native extension.

    current directory: /home/basic/.local/share/gem/ruby/3.0/gems/nokogiri-1.13.3/ext/nokogiri
/usr/local/bin/ruby30 -I /usr/local/lib/ruby/3.0 -r ./siteconf20220329-4996-vp25d.rb extconf.rb
checking for whether -I/usr/local/include is accepted as CPPFLAGS... yes
checking for whether -std=c99 is accepted as CFLAGS... no
checking for whether -Wno-declaration-after-statement is accepted as CFLAGS... no
checking for whether -g is accepted as CFLAGS... no
checking for whether -Winline is accepted as CFLAGS... no
checking for whether -Wmissing-noreturn is accepted as CFLAGS... no
Building nokogiri using packaged libraries.
Static linking is enabled.
Cross build is disabled.
Using mini_portile version 2.8.0
checking for iconv... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/usr/local/bin/$(RUBY_BASE_NAME)30
        --help
        --clean
        --enable-system-libraries
        --disable-system-libraries
        --use-system-libraries
        --prevent-strip
        --enable-system-libraries
        --disable-system-libraries
        --use-system-libraries
        --enable-system-libraries
        --disable-system-libraries
        --use-system-libraries
        --enable-static
        --disable-static
        --enable-cross-build
        --disable-cross-build
        --with-zlib-dir
        --without-zlib-dir
        --with-zlib-include
        --without-zlib-include=${zlib-dir}/include
        --with-zlib-lib
        --without-zlib-lib=${zlib-dir}/lib
        --with-xml2-source-dir
extconf.rb:266:in `have_package_configuration': wrong number of arguments (given 1, expected 0; required keywords: lib, func, headers) (ArgumentError)
        from extconf.rb:402:in `block in iconv_configure_flags'
        from extconf.rb:294:in `preserving_globals'
        from extconf.rb:402:in `iconv_configure_flags'
        from extconf.rb:803:in `block in <main>'
        from extconf.rb:438:in `block in process_recipe'
        from <internal:kernel>:90:in `tap'
        from extconf.rb:427:in `process_recipe'
        from extconf.rb:781:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /home/basic/.local/share/gem/ruby/3.0/extensions/x86_64-openbsd/3.0/nokogiri-1.13.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/basic/.local/share/gem/ruby/3.0/gems/nokogiri-1.13.3 for inspection.
Results logged to /home/basic/.local/share/gem/ruby/3.0/extensions/x86_64-openbsd/3.0/nokogiri-1.13.3/gem_make.out

mkmf.log

Thanks!

@flavorjones
Copy link
Member

@basicfeatures Thanks for opening this issue! I'll circle back later today, I have a good idea of why this is happening but lack the time right now to dig in. I have some free time in the afternoon.

@basicfeatures
Copy link
Author

@flavorjones Hi! Totally understand what you mean by lack of time. However, any chance you could give me any pointers as to what you think might be wrong, so I could try look into it myself first?

@flavorjones
Copy link
Member

flavorjones commented Apr 6, 2022

@basicfeatures Sorry for the delay in replying. What I thought I remembered was incorrect (Ruby 3.1 changed some of the behavior of pkg-config, but you're on Ruby 3.0.3).

I looked this morning and this seems like it's just a bug in Nokogiri's extconf.rb that handles a rare edge case when libiconv can't be found.

Some things to try:

  • make sure you have OpenBSD's libiconv and its development headers installed
  • make sure you have OpenBSD's pkg-config installed

On my side, I'll try to configure an OpenBSD virtual machine to try to reproduce this and fix the bug.

@flavorjones
Copy link
Member

@basicfeatures I am able to reproduce what you see if I don't have libiconv installed, but then when I install it everything proceeds OK. I'm going to create a PR to update the nokogiri.org installation docs and will tag you to review it, if that's OK.

I'll also fix this issue in the extconf.rb file.

@basicfeatures
Copy link
Author

@flavorjones Greetings and thanks so much for getting back at me!

Sadly though, the issue is still the same with regards to the ruby-3.0.3 package (although everything works flawlessly with ruby-2.7.5).

If you have both rubies installed, be sure to add the symlinks from the post-install notice:

 ln -sf /usr/local/bin/ruby30 /usr/local/bin/ruby
 ln -sf /usr/local/bin/erb30 /usr/local/bin/erb
 ln -sf /usr/local/bin/irb30 /usr/local/bin/irb
 ln -sf /usr/local/bin/rdoc30 /usr/local/bin/racc
 ln -sf /usr/local/bin/rdoc30 /usr/local/bin/rdoc
 ln -sf /usr/local/bin/rdoc30 /usr/local/bin/rbs
 ln -sf /usr/local/bin/ri30 /usr/local/bin/ri
 ln -sf /usr/local/bin/rake30 /usr/local/bin/rake
 ln -sf /usr/local/bin/gem30 /usr/local/bin/gem
 ln -sf /usr/local/bin/bundle30 /usr/local/bin/bundle
 ln -sf /usr/local/bin/bundler30 /usr/local/bin/bundler
 ln -sf /usr/local/bin/typeprof30 /usr/local/bin/typeprof

@flavorjones
Copy link
Member

@basicfeatures Do you mean you get the same error message? I'm not able to reproduce using the openbsd7 vagrant image and ruby-3.0.3 if I have installed libiconv. How can I reproduce what you're seeing?

@basicfeatures
Copy link
Author

Hi there!

Yep, same thing unfortunately. Here are my exact steps on a fresh new OpenBSD 7.0 cloud instance if you'd like to try to reproduce:

% pkg_add ruby node sass zsh libiconv 
% ln -sf /usr/local/bin/ruby30 /usr/local/bin/ruby
% ln -sf /usr/local/bin/erb30 /usr/local/bin/erb
% ln -sf /usr/local/bin/irb30 /usr/local/bin/irb
% ln -sf /usr/local/bin/rdoc30 /usr/local/bin/racc
% ln -sf /usr/local/bin/rdoc30 /usr/local/bin/rdoc
% ln -sf /usr/local/bin/rdoc30 /usr/local/bin/rbs
% ln -sf /usr/local/bin/ri30 /usr/local/bin/ri
% ln -sf /usr/local/bin/rake30 /usr/local/bin/rake
% ln -sf /usr/local/bin/gem30 /usr/local/bin/gem
% ln -sf /usr/local/bin/bundle30 /usr/local/bin/bundle
% ln -sf /usr/local/bin/bundler30 /usr/local/bin/bundler
% ln -sf /usr/local/bin/typeprof30 /usr/local/bin/typeprof
% useradd -m -s /usr/local/bin/zsh dev
% passwd dev
% su dev
% cd
% echo "export CC=/usr/bin/clang" >> ~/.zprofile
% echo "export CXX=/usr/bin/clang++" >> ~/.zprofile
% bundle config set path /home/dev/.bundle/
% echo "path+=(/home/dev/.gem/ruby/3.0/bin)" >> ~/.zprofile
% echo "path+=(/home/dev/.local/share/gem/ruby/3.0/bin)" >> ~/.zprofile
% source ~/.zprofile

--

% gem install --user-install nokogiri
Building native extensions. This could take a while...
ERROR:  Error installing nokogiri:
        ERROR: Failed to build gem native extension.

    current directory: /home/dev/.local/share/gem/ruby/3.0/gems/nokogiri-1.13.3/ext/nokogiri
/usr/local/bin/ruby30 -I /usr/local/lib/ruby/3.0 -r ./siteconf20220408-36538-4xc0ux.rb extconf.rb
checking for whether -I/usr/local/include is accepted as CPPFLAGS... yes
checking for whether -std=c99 is accepted as CFLAGS... no
checking for whether -Wno-declaration-after-statement is accepted as CFLAGS... no
checking for whether -g is accepted as CFLAGS... no
checking for whether -Winline is accepted as CFLAGS... no
checking for whether -Wmissing-noreturn is accepted as CFLAGS... no
Building nokogiri using packaged libraries.
Static linking is enabled.
Cross build is disabled.
Using mini_portile version 2.8.0
checking for iconv... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/usr/local/bin/$(RUBY_BASE_NAME)30
        --help
        --clean
        --enable-system-libraries
        --disable-system-libraries
        --use-system-libraries
        --prevent-strip
        --enable-system-libraries
        --disable-system-libraries
        --use-system-libraries
        --enable-system-libraries
        --disable-system-libraries
        --use-system-libraries
        --enable-static
        --disable-static
        --enable-cross-build
        --disable-cross-build
        --with-zlib-dir
        --without-zlib-dir
        --with-zlib-include
        --without-zlib-include=${zlib-dir}/include
        --with-zlib-lib
        --without-zlib-lib=${zlib-dir}/lib
        --with-xml2-source-dir
extconf.rb:266:in `have_package_configuration': wrong number of arguments (given 1, expected 0; required keywords: lib, func, headers) (ArgumentError)
        from extconf.rb:402:in `block in iconv_configure_flags'
        from extconf.rb:294:in `preserving_globals'
        from extconf.rb:402:in `iconv_configure_flags'
        from extconf.rb:803:in `block in <main>'
        from extconf.rb:438:in `block in process_recipe'
        from <internal:kernel>:90:in `tap'
        from extconf.rb:427:in `process_recipe'
        from extconf.rb:781:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /home/dev/.local/share/gem/ruby/3.0/extensions/x86_64-openbsd/3.0/nokogiri-1.13.3/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/dev/.local/share/gem/ruby/3.0/gems/nokogiri-1.13.3 for inspection.
Results logged to /home/dev/.local/share/gem/ruby/3.0/extensions/x86_64-openbsd/3.0/nokogiri-1.13.3/gem_make.out

--

% pkg_info | grep iconv
libiconv-1.16p0     character set conversion library

@flavorjones
Copy link
Member

Can you tell me more about "OpenBSD 7.0 cloud instance"? Which cloud provider are you using, and did you select a specific flavor of the distro? I'd like to try to reproduce this.

Regardless, though, the fix in #2505 will prevent the "wrong number of arguments" error.

@basicfeatures
Copy link
Author

I'm using Vultr's Cloud Compute (Shared vCPU), no flavors just plain OpenBSD 7.0 x64.

Regardless, though, the fix in #2505 will prevent the "wrong number of arguments" error.

Very cool 👍

@basicfeatures
Copy link
Author

By the way, I was wrong about this part:

echo "export CC=/usr/bin/clang" >> ~/.zprofile
echo "export CXX=/usr/bin/clang++" >> ~/.zprofile
source ~/.zprofile

It is unnecessary and will prevent gem install --user-install nokogiri -- --use-system-libraries from working (Clang is already the default anyway):

/usr/local/lib/ruby/3.0/mkmf.rb:471:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.

Without those exports, everything works just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants