Skip to content

Commit

Permalink
Merge pull request #59 from robbat2/nokogiri-rpath
Browse files Browse the repository at this point in the history
Fix nokogiri rpath build.
  • Loading branch information
rubys authored Jun 1, 2017
2 parents c0501d4 + b4359b1 commit 9d13287
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 17 deletions.
30 changes: 22 additions & 8 deletions nokogumbo-import/.travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
language: ruby
# Start OSX builds before Linux, because they take longer.
os:
- osx
- linux
rvm: # http://rubies.travis-ci.org/
- 1.9.3
- 2.0.0
- 2.1.10
- 2.2.6
- 2.3.3
- 2.4.0
- 1.9
- 2.0
- 2.1
- 2.2
- 2.3
- 2.4
matrix:
exclude:
- os: osx
rvm: 1.9
- os: osx
rvm: 2.0
- os: osx
env: WITH_LIBXML=false V=1
env:
- WITH_LIBXML=true
- WITH_LIBXML=false
- WITH_LIBXML=true V=1
- WITH_LIBXML=false V=1
before_script: |
if [ "$WITH_LIBXML" == "false" ]; then
sudo apt-get remove libxml2-dev
fi
sudo: required
cache: bundler
7 changes: 6 additions & 1 deletion nokogumbo-import/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ DLEXT = RbConfig::CONFIG['DLEXT']
EXT = 'ext/nokogumboc'
file "#{EXT}/nokogumboc.#{DLEXT}" => ["#{EXT}/Makefile","#{EXT}/nokogumbo.c"] do
Dir.chdir 'ext/nokogumboc' do
sh 'make'
# Make it possible to get quiet or verbose Make
job = %w{make}
%w{V Q}.each do |k|
job << "#{k}="+ENV[k] if ENV[k]
end
sh job.join(' ')
end
end

Expand Down
40 changes: 32 additions & 8 deletions nokogumbo-import/ext/nokogumboc/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
require 'mkmf'
$CFLAGS += " -std=c99"
$CFLAGS += ' -std=c99'

if have_library('xml2', 'xmlNewDoc')
if have_library('xml2', 'xmlNewDoc')
# libxml2 libraries from http://www.xmlsoft.org/
pkg_config('libxml-2.0')

# nokogiri configuration from gem install
nokogiri_lib = Gem.find_files('nokogiri').
select { |name| name.match(%r{gems/nokogiri-([\d.]+)/lib/nokogiri}) }.
sort_by {|name| name[/nokogiri-([\d.]+)/,1].split('.').map(&:to_i)}.last
nokogiri_lib = Gem
.find_files('nokogiri')
.select { |name| name.match(%r{gems/nokogiri-([\d.]+)/lib/nokogiri}) }
.sort_by { |name| name[/nokogiri-([\d.]+)/, 1].split('.').map(&:to_i) }
.last
if nokogiri_lib
nokogiri_ext = nokogiri_lib.sub(%r(lib/nokogiri(.rb)?$), 'ext/nokogiri')
nokogiri_ext = nokogiri_lib.sub(%r{lib/nokogiri(.rb)?$}, 'ext/nokogiri')

# if that doesn't work, try workarounds found in Nokogiri's extconf
unless find_header('nokogiri.h', nokogiri_ext)
Expand All @@ -19,6 +21,28 @@

# if found, enable direct calls to Nokogiri (and libxml2)
$CFLAGS += ' -DNGLIB' if find_header('nokogiri.h', nokogiri_ext)

# If libnokogiri is not on the build path, we need to add it.
unless have_library('nokogiri', 'Nokogiri_wrap_xml_document')
nokogiri_libfile = 'nokogiri.' + RbConfig::CONFIG['DLEXT']
nokogiri_libpath = File.join(nokogiri_ext, nokogiri_libfile)
if File.exist? nokogiri_libpath
$LDFLAGS += " -Wl,-rpath #{nokogiri_ext} -L#{nokogiri_ext} "
# GNU ld:
# '-lFOO' => looks for a file named 'libFOO.a' or 'libFOO.so*'
# '-l:FOO' => looks for a file named exactly 'FOO'
# OSX/Mach ld:
# - '-l:' is not supported.
# - Only links '.dylib', not '.bundle'
#
# Nokogiri does NOT have a lib prefix, so we need to be creative in
# testing; and might have either .dylib or .bundle suffixes.
$LIBS += ' ' + nokogiri_libpath + ' ' \
if %w(so dylib).include? RbConfig::CONFIG['DLEXT']
else
puts 'WARNING! Could not find Nokogiri_wrap_xml_document symbol; build might fail.'
end
end
end
end

Expand All @@ -28,12 +52,12 @@
unless File.exist? "#{rakehome}/ext/nokogumboc/gumbo.h"
require 'fileutils'
FileUtils.cp Dir["#{rakehome}/gumbo-parser/src/*"],
"#{rakehome}/ext/nokogumboc"
"#{rakehome}/ext/nokogumboc"

case RbConfig::CONFIG['target_os']
when 'mingw32', /mswin/
FileUtils.cp Dir["#{rakehome}/gumbo-parser/visualc/include/*"],
"#{rakehome}/ext/nokogumboc"
"#{rakehome}/ext/nokogumboc"
end

$srcs = $objs = nil
Expand Down

0 comments on commit 9d13287

Please sign in to comment.