From e0db2f78955cd1dd3a1503e4a2858871a0b9d15f Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Mon, 8 Mar 2021 08:30:51 -0500 Subject: [PATCH] fix: use Nokogiri's LDFLAGS to link against precompiled libs This is necessary on Windows where unresolved symbols aren't allowed. We also limit compatibility with Nokogiri's precompiled libraries to Nokogiri >= 1.11.2 on Windows for this reason. Related to: - https://github.com/sparklemotion/nokogiri/pull/2145 - https://github.com/sparklemotion/nokogiri/issues/2167 - https://github.com/sparklemotion/nokogiri/pull/2202 --- nokogumbo-import/ext/nokogumbo/extconf.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/nokogumbo-import/ext/nokogumbo/extconf.rb b/nokogumbo-import/ext/nokogumbo/extconf.rb index d5262573e8..b33cff6bcd 100644 --- a/nokogumbo-import/ext/nokogumbo/extconf.rb +++ b/nokogumbo-import/ext/nokogumbo/extconf.rb @@ -61,15 +61,21 @@ 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) - Gem::Requirement.new(">= 1.11.0.rc4").satisfied_by?(nokogiri_version) + requirement = windows? ? ">= 1.11.2" : ">= 1.11.0.rc4" + Gem::Requirement.new(requirement).satisfied_by?(nokogiri_version) end if !prohibited if modern_nokogiri? append_cflags(Nokogiri::VERSION_INFO["nokogiri"]["cppflags"]) - have_libxml2 = have_header('libxml/tree.h') + 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