rubys / nokogumbo

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

Cannot install on Mac OS X #178

Closed jlacivita closed 3 years ago

jlacivita commented 3 years ago

Hello,

I've tried doing

gem install nokogumbo --verbose

On Mac OS 10.14, and now upgraded to 11.4 (Big Sur), and in both cases, I cannot successfully install.

$ gem install nokogumbo --verbose
HEAD https://index.rubygems.org/
200 OK
GET https://index.rubygems.org/info/nokogumbo
200 OK
GET https://index.rubygems.org/info/nokogiri
200 OK
GET https://index.rubygems.org/info/mini_portile2
200 OK
GET https://index.rubygems.org/info/racc
200 OK
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/LICENSE.txt
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/README.md
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/ext/nokogumbo/extconf.rb
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/ext/nokogumbo/nokogumbo.c
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/ascii.c
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/ascii.h
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/attribute.c
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/attribute.h
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/char_ref.c
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/char_ref.h
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/error.c
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/error.h
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/foreign_attrs.c
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/gumbo.h
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/insertion_mode.h
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/macros.h
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/parser.c
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/parser.h
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/replacement.h
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/string_buffer.c
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/string_buffer.h
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/string_piece.c
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/svg_attrs.c
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/svg_tags.c
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/tag.c
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/tag_lookup.c
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/tag_lookup.h
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/token_buffer.c
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/token_buffer.h
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/token_type.h
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/tokenizer.c
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/tokenizer.h
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/tokenizer_states.h
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/utf8.c
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/utf8.h
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/util.c
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/util.h
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/vector.c
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/gumbo-parser/src/vector.h
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/lib/nokogumbo.rb
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/lib/nokogumbo/html5.rb
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/lib/nokogumbo/html5/document.rb
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/lib/nokogumbo/html5/document_fragment.rb
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/lib/nokogumbo/html5/node.rb
/usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/lib/nokogumbo/version.rb
Building native extensions. This could take a while...
current directory: /usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/ext/nokogumbo
["/usr/local/opt/ruby/bin/ruby", "-I", "/usr/local/Cellar/ruby/3.0.2/lib/ruby/3.0.0", "-r", "./siteconf20210709-30872-k2vrt7.rb", "extconf.rb"]
checking for whether -I/usr/local/lib/ruby/gems/3.0.0/gems/nokogiri-1.11.7-x86_64-darwin/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
    --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/Cellar/ruby/3.0.2/bin/$(RUBY_BASE_NAME)
    --with-libxml2
    --without-libxml2
/usr/local/Cellar/ruby/3.0.2/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/Cellar/ruby/3.0.2/lib/ruby/3.0.0/mkmf.rb:597:in `block in try_compile'
    from /usr/local/Cellar/ruby/3.0.2/lib/ruby/3.0.0/mkmf.rb:544:in `with_werror'
    from /usr/local/Cellar/ruby/3.0.2/lib/ruby/3.0.0/mkmf.rb:597:in `try_compile'
    from /usr/local/Cellar/ruby/3.0.2/lib/ruby/3.0.0/mkmf.rb:661:in `try_cflags'
    from /usr/local/Cellar/ruby/3.0.2/lib/ruby/3.0.0/mkmf.rb:667:in `block (2 levels) in append_cflags'
    from /usr/local/Cellar/ruby/3.0.2/lib/ruby/3.0.0/mkmf.rb:971:in `block in checking_for'
    from /usr/local/Cellar/ruby/3.0.2/lib/ruby/3.0.0/mkmf.rb:361:in `block (2 levels) in postpone'
    from /usr/local/Cellar/ruby/3.0.2/lib/ruby/3.0.0/mkmf.rb:331:in `open'
    from /usr/local/Cellar/ruby/3.0.2/lib/ruby/3.0.0/mkmf.rb:361:in `block in postpone'
    from /usr/local/Cellar/ruby/3.0.2/lib/ruby/3.0.0/mkmf.rb:331:in `open'
    from /usr/local/Cellar/ruby/3.0.2/lib/ruby/3.0.0/mkmf.rb:357:in `postpone'
    from /usr/local/Cellar/ruby/3.0.2/lib/ruby/3.0.0/mkmf.rb:970:in `checking_for'
    from /usr/local/Cellar/ruby/3.0.2/lib/ruby/3.0.0/mkmf.rb:666:in `block in append_cflags'
    from /usr/local/Cellar/ruby/3.0.2/lib/ruby/3.0.0/mkmf.rb:665:in `each'
    from /usr/local/Cellar/ruby/3.0.2/lib/ruby/3.0.0/mkmf.rb:665:in `append_cflags'
    from extconf.rb:76:in `<main>'
ERROR:  Error installing nokogumbo:
    ERROR: Failed to build gem native extension.

    current directory: /usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5/ext/nokogumbo
/usr/local/opt/ruby/bin/ruby -I /usr/local/Cellar/ruby/3.0.2/lib/ruby/3.0.0 -r ./siteconf20210709-30872-k2vrt7.rb extconf.rb
Building has failed. See above output for more information on the failure.
To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /usr/local/lib/ruby/gems/3.0.0/extensions/x86_64-darwin-19/3.0.0/nokogumbo-2.0.5/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /usr/local/lib/ruby/gems/3.0.0/gems/nokogumbo-2.0.5 for inspection.
Results logged to /usr/local/lib/ruby/gems/3.0.0/extensions/x86_64-darwin-19/3.0.0/nokogumbo-2.0.5/gem_make.out

The log file contains:

ld: library not found for -lSystem
clang: error: linker command failed with exit code 1 (use -v to see invocation)
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */

I have Xcode installed, as well as the developer tools.

Ruby version is 3.0.2.

Any ideas what's up?

jlacivita commented 3 years ago

In case it's helpful:

RbConfig::CONFIG["CFLAGS"]:

-O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens  -fno-common -pipe

RbConfig::CONFIG["LDFLAGS"]:

-L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl@1.1/lib -L/usr/local/opt/readline/lib
flavorjones commented 3 years ago

:wave: Hey again. We need to figure out where the -lSystem argument to the linker is coming from.

Can you please show the output from nokogiri -v?

flavorjones commented 3 years ago

One other request: can you please jump into irb for the same version of Ruby you're using (3.0.2) and share the output from:

require 'yaml'
puts RbConfig::CONFIG.to_yaml

This will tell us if there's something in how your Ruby was compiled/linked that's injecting -lSystem into the mkmf tests.

jlacivita commented 3 years ago

Okay... it was definitely some Apple / Xcode problem.

I noticed that after I installed the developer tools, I was still getting prompted to re-install them every time I ran `gem install nokogumbo.

Closer inspection showed me that a bad path was being generated for the Xcode sdk path, it had the word "export" jammed on to the end, e.g.:

make: error: sh -c '/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdkexport -find make 2> /dev/null' failed with exit code 16384: (null) (errno=No such file or directory)
xcode-select: Failed to locate 'make', requesting installation of command line developer tools.

No matter what I did with xcode-select this error wouldn't go away.

Then I found someone who just overrode the SDK Path via ENV variables:

export SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk

And that solved my problem. 🤦‍♂️

flavorjones commented 3 years ago

@jlacivita OK, thanks for closing the loop here. Sorry you had a bad experience, but I'm glad you figured it out.