0
votes

I have found all of the answers of how to install libxml-ruby with the gem install command:

gem install libxml-ruby -v '3.1.0' -- --with-xml2-config=/usr/local/opt/libxml2/bin/xml2-config --with-xml2-dir=/usr/local/opt/libxml2 --with-xml2-lib=/usr/local/opt/libxml2/lib --with-xml2-include=/usr/local/opt/libxml2/include

Works beautifully! But then running this right afterward:

bundle install

gives the unhelpful error:

Fetching libxml-ruby 3.1.0
Installing libxml-ruby 3.1.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/me/myApp/code/myApp/.gems/ruby/2.6.0/gems/libxml-ruby-3.1.0/ext/libxml
/Users/me/.rbenv/versions/2.6.3/bin/ruby -I /Users/me/.rbenv/versions/2.6.3/lib/ruby/2.6.0 -r ./siteconf20191215-25200-16wtr3.rb extconf.rb --with-xml2-config\=/usr/local/opt/libxml2/bin/xml2-config\
--with-xml2-dir\=/usr/local/opt/libxml2\ --with-xml2-lib\=/usr/local/opt/libxml2/lib\ --with-xml2-include\=/usr/local/opt/libxml2/include
/Users/me/.rbenv/versions/2.6.3/bin/ruby: warning: shebang line ending with \r may cause problems
checking for libxml/xmlversion.h in /opt/include/libxml2,/opt/local/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2... *** 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=/Users/me/.rbenv/versions/2.6.3/bin/$(RUBY_BASE_NAME)
    --with-xml2-config

OK, it looks like the libxml2 options are not being included in the call the bundler uses to install. So let's do this:

bundle config build.libxml-ruby --with-xml2-config=/usr/local/opt/libxml2/bin/xml2-config --with-xml2-dir=/usr/local/opt/libxml2 --with-xml2-lib=/usr/local/opt/libxml2/lib --with-xml2-include=/usr/local/opt/libxml2/include

That should work, right? Well no it doesn't. I am dead in the water until I can get Bundler to do what it is supposed to do.

There is no good answer for why Bundler fails here. The gem install line works. Bundler fails.

Inside the mkmf.log file is this:

find_header: checking for libxml/xmlversion.h in /opt/include/libxml2,/opt/local/include/libxml2,/usr/local/include/libxml2,/usr/include/libxml2... -------------------- no

And then several failures that all relate to not being able to find that header file.

It's looking in /opt/, instead of /usr/local/opt. I don't know how to make Bundler look in the correct place if it won't respect the bundle config commands.

1

1 Answers

1
votes

Since Bundler wouldn't honor the paths I was passing in, I looked at the paths where it was looking for xmlversion.h.

I went into /usr/local/include. That's where all my Homebrew links are. I created a symlink to the Mac OS-provided libxml directory:

ln -s /usr/local/opt/libxml2/include/libxml2/libxml libxml

/usr/local/opt seems like a strange place for a system directory, but I'm tired of messing with it.

Once I did this, and went back into my app directory, bundle install worked. Well, I mean it broke again but it was on therubyracer this time. So it at least jumped this hurdle.