Skip to content

Commit bda808f

Browse files
committed
wip: use mini_portile 2.8.5.rc2 to simplify extconf
1 parent 355978f commit bda808f

File tree

2 files changed

+29
-89
lines changed

2 files changed

+29
-89
lines changed

ext/nokogiri/extconf.rb

+28-88
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
REQUIRED_LIBXML_VERSION = "2.6.21"
1616
RECOMMENDED_LIBXML_VERSION = "2.9.3"
1717

18-
REQUIRED_MINI_PORTILE_VERSION = "~> 2.8.2" # keep this version in sync with the one in the gemspec
18+
REQUIRED_MINI_PORTILE_VERSION = "2.8.5.rc2" # keep this version in sync with the one in the gemspec
1919
REQUIRED_PKG_CONFIG_VERSION = "~> 1.1"
2020

2121
# Keep track of what versions of what libraries we build against
@@ -429,7 +429,6 @@ def process_recipe(name, version, static_p, cross_p, cacheable_p = true)
429429
require "rubygems"
430430
gem("mini_portile2", REQUIRED_MINI_PORTILE_VERSION) # gemspec is not respected at install time
431431
require "mini_portile2"
432-
message("Using mini_portile version #{MiniPortile::VERSION}\n")
433432

434433
unless ["libxml2", "libxslt"].include?(name)
435434
OTHER_LIBRARY_VERSIONS[name] = version
@@ -540,7 +539,6 @@ def recipe.port_path
540539
chdir_for_build { recipe.cook }
541540
FileUtils.touch(checkpoint)
542541
end
543-
recipe.activate
544542
end
545543
end
546544

@@ -804,6 +802,9 @@ def configure
804802
end
805803
end
806804

805+
zlib_recipe.mkmf_config(pkg: "zlib", static: (static_p && "z"))
806+
ensure_func("gzdopen", "zlib.h")
807+
807808
unless nix?
808809
libiconv_recipe = process_recipe(
809810
"libiconv",
@@ -829,7 +830,12 @@ def configure
829830
"LDFLAGS=",
830831
]
831832
end
833+
834+
# libiconv does not ship with a pkg-config file
835+
libiconv_recipe.mkmf_config(static: (static_p && "iconv"))
836+
ensure_func("iconv_open", "iconv.h")
832837
end
838+
833839
elsif darwin? && !have_header("iconv.h")
834840
abort(<<~EOM.chomp)
835841
-----
@@ -845,30 +851,6 @@ def configure
845851
EOM
846852
end
847853

848-
if zlib_recipe
849-
append_cppflags("-I#{zlib_recipe.path}/include")
850-
$LIBPATH = ["#{zlib_recipe.path}/lib"] | $LIBPATH
851-
ensure_package_configuration(
852-
opt: "zlib",
853-
pc: "zlib",
854-
lib: "z",
855-
headers: "zlib.h",
856-
func: "gzdopen",
857-
)
858-
end
859-
860-
if libiconv_recipe
861-
append_cppflags("-I#{libiconv_recipe.path}/include")
862-
$LIBPATH = ["#{libiconv_recipe.path}/lib"] | $LIBPATH
863-
ensure_package_configuration(
864-
opt: "iconv",
865-
pc: "iconv",
866-
lib: "iconv",
867-
headers: "iconv.h",
868-
func: "iconv_open",
869-
)
870-
end
871-
872854
libxml2_recipe = process_recipe("libxml2", dependencies["libxml2"]["version"], static_p, cross_build_p) do |recipe|
873855
source_dir = arg_config("--with-xml2-source-dir")
874856
if source_dir
@@ -924,6 +906,9 @@ def configure
924906
]
925907
end
926908

909+
libxml2_recipe.mkmf_config(pkg: "libxml-2.0", static: (static_p && "xml2"))
910+
ensure_func("xmlParseDoc", "libxml/parser.h")
911+
927912
libxslt_recipe = process_recipe("libxslt", dependencies["libxslt"]["version"], static_p, cross_build_p) do |recipe|
928913
source_dir = arg_config("--with-xslt-source-dir")
929914
if source_dir
@@ -963,72 +948,27 @@ def configure
963948
]
964949
end
965950

966-
append_cppflags("-DNOKOGIRI_PACKAGED_LIBRARIES")
967-
append_cppflags("-DNOKOGIRI_PRECOMPILED_LIBRARIES") if cross_build_p
951+
libxslt_recipe.mkmf_config(pkg: "libxslt", static: (static_p && "xslt"))
952+
ensure_func("xsltParseStylesheetDoc", "libxslt/xslt.h")
968953

969-
$libs = $libs.shellsplit.tap do |libs|
970-
[libxml2_recipe, libxslt_recipe].each do |recipe|
971-
libname = recipe.name[/\Alib(.+)\z/, 1]
972-
config_basename = "#{libname}-config"
973-
File.join(recipe.path, "bin", config_basename).tap do |config|
974-
# call config scripts explicit with 'sh' for compat with Windows
975-
cflags = %x(sh #{config} --cflags).strip
976-
message("#{config_basename} cflags: #{cflags}\n")
977-
$CPPFLAGS = concat_flags(cflags, $CPPFLAGS) # prepend
978-
979-
%x(sh #{config} --libs).strip.shellsplit.each do |arg|
980-
case arg
981-
when /\A-L(.+)\z/
982-
# Prioritize ports' directories
983-
$LIBPATH = if Regexp.last_match(1).start_with?(PACKAGE_ROOT_DIR + "/")
984-
[Regexp.last_match(1)] | $LIBPATH
985-
else
986-
$LIBPATH | [Regexp.last_match(1)]
987-
end
988-
when /\A-l./
989-
libs.unshift(arg)
990-
else
991-
$LDFLAGS << " " << arg.shellescape
992-
end
993-
end
994-
end
954+
libxslt_recipe.mkmf_config(pkg: "libexslt", static: (static_p && "exslt"))
955+
ensure_func("exsltFuncRegister", "libexslt/exslt.h")
995956

996-
patches_string = recipe.patch_files.map { |path| File.basename(path) }.join(" ")
997-
append_cppflags(%[-DNOKOGIRI_#{recipe.name.upcase}_PATCHES="\\"#{patches_string}\\""])
957+
if windows?
958+
append_cppflags("-DLIBXSLT_STATIC -DLIBEXSLT_STATIC") # https://gitlab.gnome.org/GNOME/libxslt/-/merge_requests/66
959+
end
998960

999-
case libname
1000-
when "xml2"
1001-
# xslt-config --libs or pkg-config libxslt --libs does not include
1002-
# -llzma, so we need to add it manually when linking statically.
1003-
if static_p && preserving_globals { local_have_library("lzma") }
1004-
# Add it at the end; GH #988
1005-
libs << "-llzma"
1006-
end
1007-
when "xslt"
1008-
# xslt-config does not have a flag to emit options including
1009-
# -lexslt, so add it manually.
1010-
libs.unshift("-lexslt")
1011-
end
1012-
end
1013-
end.shelljoin
1014-
1015-
if static_p
1016-
static_archive_ld_flag = needs_darwin_linker_hack ? ["-load_hidden"] : []
1017-
$libs = $libs.shellsplit.map do |arg|
1018-
case arg
1019-
when "-lxml2"
1020-
static_archive_ld_flag + [File.join(libxml2_recipe.path, "lib", libflag_to_filename(arg))]
1021-
when "-lxslt", "-lexslt"
1022-
static_archive_ld_flag + [File.join(libxslt_recipe.path, "lib", libflag_to_filename(arg))]
1023-
else
1024-
arg
1025-
end
1026-
end.flatten.shelljoin
961+
# Nokogiri::VERSION_INFO metadata
962+
append_cppflags("-DNOKOGIRI_PACKAGED_LIBRARIES")
963+
append_cppflags("-DNOKOGIRI_PRECOMPILED_LIBRARIES") if cross_build_p
964+
[libxml2_recipe, libxslt_recipe].each do |recipe|
965+
patches_string = recipe.patch_files.map { |path| File.basename(path) }.join(" ")
966+
append_cppflags(%[-DNOKOGIRI_#{recipe.name.upcase}_PATCHES="\\"#{patches_string}\\""])
1027967
end
1028968

1029-
ensure_func("xmlParseDoc", "libxml/parser.h")
1030-
ensure_func("xsltParseStylesheetDoc", "libxslt/xslt.h")
1031-
ensure_func("exsltFuncRegister", "libexslt/exslt.h")
969+
# if static_p
970+
# static_archive_ld_flag = needs_darwin_linker_hack ? ["-load_hidden"] : []
971+
# end
1032972
end
1033973

1034974
libgumbo_recipe = process_recipe("libgumbo", "1.0.0-nokogiri", static_p, cross_build_p, false) do |recipe|

nokogiri.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ Gem::Specification.new do |spec|
339339
spec.requirements << "jar xerces, xercesImpl, 2.12.2" # https://search.maven.org/artifact/xerces/xercesImpl
340340
spec.requirements << "jar xml-apis, xml-apis, 1.4.01" # https://search.maven.org/artifact/xml-apis/xml-apis
341341
else
342-
spec.add_runtime_dependency("mini_portile2", "~> 2.8.2") # keep version in sync with extconf.rb
342+
spec.add_runtime_dependency("mini_portile2", "2.8.5.rc2") # keep version in sync with extconf.rb
343343
end
344344
spec.add_runtime_dependency("racc", "~> 1.4")
345345

0 commit comments

Comments
 (0)