Skip to content

Commit

Permalink
ext: enable libxml2 "legacy" support
Browse files Browse the repository at this point in the history
- zlib
- liblzma
- HTTP

libxml2 v2.13.0 turned these off by default, so this commit re-enables
them.

I'm proposing to support this functionality in Nokogiri 1.x releases,
but remove it (possibly with an option to re-enable it) in Nokogiri
2.x. See #3168 for discussion.
  • Loading branch information
flavorjones committed Jun 22, 2024
1 parent 7e98917 commit 3be3004
Showing 1 changed file with 90 additions and 74 deletions.
164 changes: 90 additions & 74 deletions ext/nokogiri/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,6 @@
Look for headers in DIRECTORY.
Related to zlib:
--with-zlib-dir=DIRECTORY
Look for zlib headers and library in DIRECTORY.
--with-zlib-lib=DIRECTORY
Look for zlib library in DIRECTORY.
--with-zlib-include=DIRECTORY
Look for zlib headers in DIRECTORY.
Related to iconv:
--with-iconv-dir=DIRECTORY
Look for iconv headers and library in DIRECTORY.
--with-iconv-lib=DIRECTORY
Look for iconv library in DIRECTORY.
--with-iconv-include=DIRECTORY
Look for iconv headers in DIRECTORY.
Related to libxml2:
--with-xml2-dir=DIRECTORY
Expand All @@ -95,6 +71,10 @@
--with-xml2-source-dir=DIRECTORY
(dev only) Build libxml2 from the source code in DIRECTORY
--disable-xml2-legacy
Do not build libxml2 with zlib, liblzma, or HTTP support. This will become the default
in a future version of Nokogiri.
Related to libxslt:
Expand Down Expand Up @@ -123,6 +103,30 @@
Look for exslt headers in DIRECTORY.
Related to iconv:
--with-iconv-dir=DIRECTORY
Look for iconv headers and library in DIRECTORY.
--with-iconv-lib=DIRECTORY
Look for iconv library in DIRECTORY.
--with-iconv-include=DIRECTORY
Look for iconv headers in DIRECTORY.
Related to zlib (ignored if `--disable-xml2-legacy` is used):
--with-zlib-dir=DIRECTORY
Look for zlib headers and library in DIRECTORY.
--with-zlib-lib=DIRECTORY
Look for zlib library in DIRECTORY.
--with-zlib-include=DIRECTORY
Look for zlib headers in DIRECTORY.
Flags only used when building and using the packaged libraries:
--disable-static
Expand Down Expand Up @@ -181,6 +185,10 @@ def config_system_libraries?
end
end

def config_with_xml2_legacy?
enable_config("xml2-legacy", true)
end

def windows?
RbConfig::CONFIG["target_os"].match?(/mingw|mswin/)
end
Expand Down Expand Up @@ -707,13 +715,15 @@ def needs_darwin_linker_hack

if config_system_libraries?
message "Building nokogiri using system libraries.\n"
ensure_package_configuration(
opt: "zlib",
pc: "zlib",
lib: "z",
headers: "zlib.h",
func: "gzdopen",
)
if config_with_xml2_legacy?
ensure_package_configuration(
opt: "zlib",
pc: "zlib",
lib: "z",
headers: "zlib.h",
func: "gzdopen",
)
end
ensure_package_configuration(
opt: "xml2",
pc: "libxml-2.0",
Expand Down Expand Up @@ -757,58 +767,60 @@ def needs_darwin_linker_hack
require "yaml"
dependencies = YAML.load_file(File.join(PACKAGE_ROOT_DIR, "dependencies.yml"))

dir_config("zlib")
dir_config("zlib") if config_with_xml2_legacy?

if cross_build_p || windows?
zlib_recipe = process_recipe("zlib", dependencies["zlib"]["version"], static_p, cross_build_p) do |recipe|
recipe.files = [{
url: zlib_source(recipe.version),
sha256: dependencies["zlib"]["sha256"],
}]
if windows?
class << recipe
attr_accessor :cross_build_p

def configure
Dir.chdir(work_path) do
mk = File.read("win32/Makefile.gcc")
File.open("win32/Makefile.gcc", "wb") do |f|
f.puts "BINARY_PATH = #{path}/bin"
f.puts "LIBRARY_PATH = #{path}/lib"
f.puts "INCLUDE_PATH = #{path}/include"
mk.sub!(/^PREFIX\s*=\s*$/, "PREFIX = #{host}-") if cross_build_p
f.puts mk
if config_with_xml2_legacy?
zlib_recipe = process_recipe("zlib", dependencies["zlib"]["version"], static_p, cross_build_p) do |recipe|
recipe.files = [{
url: zlib_source(recipe.version),
sha256: dependencies["zlib"]["sha256"],
}]
if windows?
class << recipe
attr_accessor :cross_build_p

def configure
Dir.chdir(work_path) do
mk = File.read("win32/Makefile.gcc")
File.open("win32/Makefile.gcc", "wb") do |f|
f.puts "BINARY_PATH = #{path}/bin"
f.puts "LIBRARY_PATH = #{path}/lib"
f.puts "INCLUDE_PATH = #{path}/include"
mk.sub!(/^PREFIX\s*=\s*$/, "PREFIX = #{host}-") if cross_build_p
f.puts mk
end
end
end
end

def configured?
Dir.chdir(work_path) do
!!(File.read("win32/Makefile.gcc") =~ /^BINARY_PATH/)
def configured?
Dir.chdir(work_path) do
!!(File.read("win32/Makefile.gcc") =~ /^BINARY_PATH/)
end
end
end

def compile
execute("compile", "make -f win32/Makefile.gcc")
end
def compile
execute("compile", "make -f win32/Makefile.gcc")
end

def install
execute("install", "make -f win32/Makefile.gcc install")
def install
execute("install", "make -f win32/Makefile.gcc install")
end
end
end
recipe.cross_build_p = cross_build_p
else
class << recipe
def configure
env = {}
env["CFLAGS"] = concat_flags(ENV["CFLAGS"], "-fPIC", "-g")
env["CHOST"] = host
execute("configure", ["./configure", "--static", configure_prefix], { env: env })
if darwin?
# needed as of zlib 1.2.13
Dir.chdir(work_path) do
makefile = File.read("Makefile").gsub(/^AR=.*$/, "AR=#{host}-libtool")
File.open("Makefile", "w") { |m| m.write(makefile) }
recipe.cross_build_p = cross_build_p
else
class << recipe
def configure
env = {}
env["CFLAGS"] = concat_flags(ENV["CFLAGS"], "-fPIC", "-g")
env["CHOST"] = host
execute("configure", ["./configure", "--static", configure_prefix], { env: env })
if darwin?
# needed as of zlib 1.2.13
Dir.chdir(work_path) do
makefile = File.read("Makefile").gsub(/^AR=.*$/, "AR=#{host}-libtool")
File.open("Makefile", "w") { |m| m.write(makefile) }
end
end
end
end
Expand Down Expand Up @@ -901,6 +913,10 @@ def configure
cppflags = concat_flags(cppflags, "-DNOKOGIRI_PRECOMPILED_LIBRARIES")
end

if config_with_xml2_legacy?
recipe.configure_options << "--with-legacy"
end

if zlib_recipe
recipe.configure_options << "--with-zlib=#{zlib_recipe.path}"
end
Expand Down

0 comments on commit 3be3004

Please sign in to comment.