Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify library dependencies in native gems #2146

Merged
merged 3 commits into from
Dec 25, 2020
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
1,962 changes: 1,015 additions & 947 deletions LICENSE-DEPENDENCIES.md

Large diffs are not rendered by default.

18 changes: 14 additions & 4 deletions ext/nokogiri/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
REQUIRED_MINI_PORTILE_VERSION = "~> 2.5.0"
REQUIRED_PKG_CONFIG_VERSION = "~> 1.1"

# Keep track of what versions of what libraries we build against
OTHER_LIBRARY_VERSIONS = {}

NOKOGIRI_HELP_MESSAGE = <<~HELP
USAGE: ruby #{$0} [options]

Expand Down Expand Up @@ -339,6 +342,10 @@ def process_recipe(name, version, static_p, cross_p)
require 'mini_portile2'
message "Using mini_portile version #{MiniPortile::VERSION}\n"

if name != "libxml2" && name != "libxslt"
OTHER_LIBRARY_VERSIONS[name] = version
end

MiniPortile.new(name, version).tap do |recipe|
recipe.target = File.join(PACKAGE_ROOT_DIR, "ports")
# Prefer host_alias over host in order to use i586-mingw32msvc as
Expand Down Expand Up @@ -695,8 +702,8 @@ def configure
]
end

append_cflags("-DNOKOGIRI_PACKAGED_LIBRARIES")
append_cflags("-DNOKOGIRI_PRECOMPILED_LIBRARIES") if cross_build_p
append_cppflags("-DNOKOGIRI_PACKAGED_LIBRARIES")
append_cppflags("-DNOKOGIRI_PRECOMPILED_LIBRARIES") if cross_build_p

$LIBPATH = ["#{zlib_recipe.path}/lib"] | $LIBPATH if zlib_recipe
$LIBPATH = ["#{libiconv_recipe.path}/lib"] | $LIBPATH if libiconv_recipe
Expand Down Expand Up @@ -724,8 +731,8 @@ def configure
end
end

# Defining a macro that expands to a C string; double quotes are significant.
$CPPFLAGS << ' ' << "-DNOKOGIRI_#{recipe.name.upcase}_PATCHES=\"#{recipe.patch_files.map { |path| File.basename(path) }.join(' ')}\"".inspect
patches_string = recipe.patch_files.map { |path| File.basename(path) }.join(' ')
append_cppflags(%Q[-DNOKOGIRI_#{recipe.name.upcase}_PATCHES="\\\"#{patches_string}\\\""])

case libname
when 'xml2'
Expand Down Expand Up @@ -770,6 +777,9 @@ def configure

have_func('vasprintf')

other_library_versions_string = OTHER_LIBRARY_VERSIONS.map { |k,v| [k,v].join(":") }.join(",")
append_cppflags(%Q[-DNOKOGIRI_OTHER_LIBRARY_VERSIONS="\\\"#{other_library_versions_string}\\\""])

unless using_system_libraries?
if cross_build_p
# When precompiling native gems, copy packaged libraries' headers to ext/nokogiri/include
Expand Down
4 changes: 4 additions & 0 deletions ext/nokogiri/nokogiri.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ void Init_nokogiri()
rb_const_set(mNokogiri, rb_intern("LIBXML_ICONV_ENABLED"), Qfalse);
#endif

#ifdef NOKOGIRI_OTHER_LIBRARY_VERSIONS
rb_const_set(mNokogiri, rb_intern("OTHER_LIBRARY_VERSIONS"), NOKOGIRI_STR_NEW2(NOKOGIRI_OTHER_LIBRARY_VERSIONS));
#endif

xmlInitParser();

init_xml_document();
Expand Down
11 changes: 9 additions & 2 deletions lib/nokogiri/version/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,16 @@ def to_hash
end

vi["warnings"] = warnings
end

if defined?(Nokogiri::OTHER_LIBRARY_VERSIONS)
# see extconf for how this string is assembled: "lib1name:lib1version,lib2name:lib2version"
vi["other_libraries"] = Hash[*Nokogiri::OTHER_LIBRARY_VERSIONS.split(/[,:]/)]
elsif jruby?
vi["xerces"] = Nokogiri::XERCES_VERSION
vi["nekohtml"] = Nokogiri::NEKO_VERSION
vi["other_libraries"] = {}.tap do |ol|
ol["xerces"] = Nokogiri::XERCES_VERSION
ol["nekohtml"] = Nokogiri::NEKO_VERSION
end
end
end
end
Expand Down
5 changes: 0 additions & 5 deletions rakelib/cross-ruby.rake
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,6 @@ else
ext.cross_platform = CROSS_RUBIES.map(&:platform).uniq
ext.cross_config_options << "--enable-cross-build"
ext.cross_compiling do |spec|
libs = dependencies.map { |name, dep| "#{name}-#{dep["version"]}" }.join(', ')
spec.post_install_message = <<~EOS
Nokogiri is built with the packaged libraries: #{libs}.
EOS

spec.files.reject! { |path| File.fnmatch?('ports/*', path) }
spec.dependencies.reject! { |dep| dep.name=='mini_portile2' }

Expand Down
4 changes: 2 additions & 2 deletions test/test_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def test_version_info_basics

def test_version_info_for_xerces
skip("xerces is only used for JRuby") unless Nokogiri.jruby?
assert_equal(Nokogiri::XERCES_VERSION, version_info["xerces"])
assert_equal(Nokogiri::XERCES_VERSION, version_info["other_libraries"]["xerces"])
end

def test_version_info_for_nekohtml
skip("nekohtml is only used for JRuby") unless Nokogiri.jruby?
assert_equal(Nokogiri::NEKO_VERSION, version_info["nekohtml"])
assert_equal(Nokogiri::NEKO_VERSION, version_info["other_libraries"]["nekohtml"])
end

def test_version_info_for_libxml
Expand Down