Skip to content
This repository has been archived by the owner on Aug 26, 2023. It is now read-only.

update extconf.rb to use Nokogiri's CPPFLAGS #163

Merged
merged 2 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Support Mageia distros when libxml2/libxslt system libraries are install. #165 (Thank you,
@pterjan!)

### Improved
- Update extconf.rb to use Nokogiri v1.11's CPPFLAGS for more reliable installation.


## [2.0.4] - 2020-11-27
### Fixed
- Fixed a bug where `Nokogiri::HTML5.fragment(nil)` would raise an error. Now
Expand Down
70 changes: 44 additions & 26 deletions ext/nokogumbo/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,41 +61,60 @@ def download_headers
have_libxml2 = false
have_ng = false

def windows?
::RUBY_PLATFORM =~ /mingw|mswin/
end

def modern_nokogiri?
nokogiri_version = Gem::Version.new(Nokogiri::VERSION)
requirement = windows? ? ">= 1.11.2" : ">= 1.11.0.rc4"
Gem::Requirement.new(requirement).satisfied_by?(nokogiri_version)
end

if !prohibited
if Nokogiri::VERSION_INFO.include?('libxml') and
Nokogiri::VERSION_INFO['libxml']['source'] == 'packaged'
# Nokogiri has libxml2 built in. Find the headers.
libxml2_path = File.join(Nokogiri::VERSION_INFO['libxml']['libxml2_path'],
'include/libxml2')
if find_header('libxml/tree.h', libxml2_path)
have_libxml2 = true
if modern_nokogiri?
append_cflags(Nokogiri::VERSION_INFO["nokogiri"]["cppflags"])
append_ldflags(Nokogiri::VERSION_INFO["nokogiri"]["ldflags"]) # may be nil for nokogiri pre-1.11.2
have_libxml2 = have_func("xmlNewDoc", "libxml/tree.h")
end

if !have_libxml2
if Nokogiri::VERSION_INFO.include?('libxml') and
Nokogiri::VERSION_INFO['libxml']['source'] == 'packaged'
# Nokogiri has libxml2 built in. Find the headers.
libxml2_path = File.join(Nokogiri::VERSION_INFO['libxml']['libxml2_path'],
'include/libxml2')
if find_header('libxml/tree.h', libxml2_path)
have_libxml2 = true
else
# Unfortunately, some versions of Nokogiri delete these files.
# https://github.com/sparklemotion/nokogiri/pull/1788
# Try to download them
libxml2_path = download_headers
unless libxml2_path.nil?
have_libxml2 = find_header('libxml/tree.h', libxml2_path)
end
end
else
# Unfortunately, some versions of Nokogiri delete these files.
# https://github.com/sparklemotion/nokogiri/pull/1788
# Try to download them
libxml2_path = download_headers
unless libxml2_path.nil?
have_libxml2 = find_header('libxml/tree.h', libxml2_path)
# Nokogiri is compiled with system headers.
# Hack to work around broken mkmf on macOS
# (https://bugs.ruby-lang.org/issues/14992 fixed now)
if RbConfig::MAKEFILE_CONFIG['LIBPATHENV'] == 'DYLD_LIBRARY_PATH'
RbConfig::MAKEFILE_CONFIG['LIBPATHENV'] = 'DYLD_FALLBACK_LIBRARY_PATH'
end
end
else
# Nokogiri is compiled with system headers.
# Hack to work around broken mkmf on macOS
# (https://bugs.ruby-lang.org/issues/14992 fixed now)
if RbConfig::MAKEFILE_CONFIG['LIBPATHENV'] == 'DYLD_LIBRARY_PATH'
RbConfig::MAKEFILE_CONFIG['LIBPATHENV'] = 'DYLD_FALLBACK_LIBRARY_PATH'
end

pkg_config('libxml-2.0')
have_libxml2 = have_library('xml2', 'xmlNewDoc')
pkg_config('libxml-2.0')
have_libxml2 = have_library('xml2', 'xmlNewDoc')
end
end

if required and !have_libxml2
abort "libxml2 required but could not be located"
end


if have_libxml2
# Find nokogiri.h
have_ng = find_header('nokogiri.h', File.join(NG_SPEC.gem_dir, 'ext/nokogiri'))
have_ng = have_header('nokogiri.h') || find_header('nokogiri.h', File.join(NG_SPEC.gem_dir, 'ext/nokogiri'))
end
end

Expand All @@ -105,7 +124,6 @@ def download_headers

# Symlink gumbo-parser source files.
ext_dir = File.dirname(__FILE__)
gumbo_src = File.join(ext_dir, 'gumbo_src')

Dir.chdir(ext_dir) do
$srcs = Dir['*.c', '../../gumbo-parser/src/*.c']
Expand Down