rubys / nokogumbo

A Nokogiri interface to the Gumbo HTML5 parser.
Apache License 2.0
186 stars 114 forks source link

Installation (2.0.5) fails on Alpine Linux #175

Closed tnir closed 3 years ago

tnir commented 3 years ago

Installing nokogumbo 2.0.5 to pristine Alpine Linux fails.

On Debian

$ docker run --rm ruby:3.0.1 gem install nokogumbo -v 2.0.5
Successfully installed nokogiri-1.11.3-x86_64-linux
Building native extensions. This could take a while...
Successfully installed nokogumbo-2.0.5
2 gems installed

On Alpine

$ docker run --rm ruby:3.0.1-alpine gem install nokogumbo -v 2.0.5
Successfully installed nokogiri-1.11.3-x86_64-linux
Building native extensions. This could take a while...
ERROR:  Error installing nokogumbo:
        ERROR: Failed to build gem native extension.

    current directory: /usr/local/bundle/gems/nokogumbo-2.0.5/ext/nokogumbo
/usr/local/bin/ruby -I /usr/local/lib/ruby/3.0.0 -r ./siteconf20210417-1-s4q1r0.rb extconf.rb
checking for whether -I/usr/local/bundle/gems/nokogiri-1.11.3-x86_64-linux/ext/nokogiri is accepted as CFLAGS... *** 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)
        --with-libxml2
        --without-libxml2
/usr/local/lib/ruby/3.0.0/mkmf.rb:471:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
        from /usr/local/lib/ruby/3.0.0/mkmf.rb:597:in `block in try_compile'
        from /usr/local/lib/ruby/3.0.0/mkmf.rb:544:in `with_werror'
        from /usr/local/lib/ruby/3.0.0/mkmf.rb:597:in `try_compile'
        from /usr/local/lib/ruby/3.0.0/mkmf.rb:661:in `try_cflags'
        from /usr/local/lib/ruby/3.0.0/mkmf.rb:667:in `block (2 levels) in append_cflags'
        from /usr/local/lib/ruby/3.0.0/mkmf.rb:971:in `block in checking_for'
        from /usr/local/lib/ruby/3.0.0/mkmf.rb:361:in `block (2 levels) in postpone'
        from /usr/local/lib/ruby/3.0.0/mkmf.rb:331:in `open'
        from /usr/local/lib/ruby/3.0.0/mkmf.rb:361:in `block in postpone'
        from /usr/local/lib/ruby/3.0.0/mkmf.rb:331:in `open'
        from /usr/local/lib/ruby/3.0.0/mkmf.rb:357:in `postpone'
        from /usr/local/lib/ruby/3.0.0/mkmf.rb:970:in `checking_for'
        from /usr/local/lib/ruby/3.0.0/mkmf.rb:666:in `block in append_cflags'
        from /usr/local/lib/ruby/3.0.0/mkmf.rb:665:in `each'
        from /usr/local/lib/ruby/3.0.0/mkmf.rb:665:in `append_cflags'
        from extconf.rb:76:in `<main>'

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

  /usr/local/bundle/extensions/x86_64-linux-musl/3.0.0/nokogumbo-2.0.5/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /usr/local/bundle/gems/nokogumbo-2.0.5 for inspection.
Results logged to /usr/local/bundle/extensions/x86_64-linux-musl/3.0.0/nokogumbo-2.0.5/gem_make.out

Note

nokogiri can be installed even on Alpine Linux as follows:

$ docker run --rm ruby:3.0.1-alpine gem install nokogiri
Successfully installed nokogiri-1.11.3-x86_64-linux
1 gem installed
flavorjones commented 3 years ago

:wave: Thank you for opening this issue and asking this question.

It looks like you don't have a compiler toolchain installed. The version of Nokogiri you're successfully installing is a precompiled version which doesn't require a C compiler toolchain; if we try that again with --platform=ruby you'll see a similar error; or alternatively if you try to install a gem with even a simple C extension, you'll see similar errors (e.g, gem install bcrypt).

If you take a look at this section in the Nokogiri installation doc you'll see how to set up your compiler toolchain for Alpine. TL;DR, apk add build-base.

Hope this helps!

flavorjones commented 3 years ago

Oh, and one more note: we're in the process of merging Nokogumbo into Nokogiri, at which point we'll be able to provide precompiled gems for Nokogumbo functionality as well. Stay tuned by following https://github.com/sparklemotion/nokogiri/issues/2204 !

tnir commented 3 years ago

Thanks!