rgrove / sanitize

Ruby HTML and CSS sanitizer.
MIT License
2.02k stars 142 forks source link

Cannot install on Mac OS X #210

Closed jlacivita closed 3 years ago

jlacivita commented 3 years ago

Hello,

I've tried doing

gem install sanitize

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

$ gem install sanitize
Building native extensions. This could take a while...
ERROR:  Error installing sanitize:
    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 ./siteconf20210708-10611-gyup1j.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>'

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?

flavorjones commented 3 years ago

@jlacivita sorry you're having problems, my guess is that this is an issue with Nokogumbo (and not sanitize).

Can you provide the output from gem install sanitize --verbose to make sure that diagnosis is correct?

flavorjones commented 3 years ago

Or, rather, I'm confident this is an issue with Nokogumbo (based on the log files). Can you respond with the output of nokogiri -v?

flavorjones commented 3 years ago

Finally - can you check how your Ruby 3.0.2 was built? If you could take a look at RbConfig::CONFIG["CFLAGS"] and RbConfig::CONFIG["LDFLAGS"] to see if we can tell where -lSystem is coming from, that might also help.

jlacivita commented 3 years ago

Hi @flavorjones, thanks for the quick response.

nokogiri doesn't run from the command line for me, maybe that's the problem?

Here's the other outputs you asked for:

$ gem install sanitize --verbose
HEAD https://index.rubygems.org/
200 OK
GET https://index.rubygems.org/info/sanitize
200 OK
GET https://index.rubygems.org/info/crass
200 OK
GET https://index.rubygems.org/info/hpricot
200 OK
GET https://index.rubygems.org/info/htmlentities
200 OK
GET https://index.rubygems.org/info/nokogiri
200 OK
GET https://index.rubygems.org/info/nokogumbo
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-15593-ksog3q.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 sanitize:
    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-15593-ksog3q.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

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

nokogiri doesn't run from the command line for me, maybe that's the problem

Likely, yes. Please uninstall all existing versions of Nokogiri to make sure you're starting from a known, clean config. Then:

If either of the first two steps fail, please open an issue with the appropriate project and we can take it from there.

@rgrove may want to close this since I think we've determined the issue isn't with Sanitize per se, but with its dependencies.

rgrove commented 3 years ago

Thanks @flavorjones!

jlacivita commented 3 years ago

Okay, I'm getting a similar error installing nokogumbo. Will follow up there

jlacivita commented 3 years ago

In case folks are following my journey :)

https://github.com/rubys/nokogumbo/issues/178