libxml2: rework (#5284)

* libxml2: rework

* improve configs

* remove pkgconfig

* xz: add mingw@msys

* add check for iphoneos

* fix mingw static build
pull/5286/head
star9029 2 months ago committed by GitHub
parent b0001567aa
commit d522547ea0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 39
      packages/l/libxml2/configs.lua
  2. 210
      packages/l/libxml2/xmake.lua
  3. 8
      packages/x/xz/xmake.lua

@ -0,0 +1,39 @@
local libxml2_configs = {
catalog = "Add the Catalog support",
-- debug = "Add the debugging module",
html = "Add the HTML support",
http = "Add the HTTP support",
iconv = "Add ICONV support",
icu = "Add ICU support",
iso8859x = "Add ISO8859X support if no iconv",
legacy = "Add deprecated APIs for compatibility",
lzma = "Use liblzma",
modules = "Add the dynamic modules support",
output = "Add the serialization support",
pattern = "Add the xmlPattern selection interface",
programs = "Build programs",
push = "Add the PUSH parser interfaces",
python = "Build Python bindings",
readline = "readline support for xmllint shell",
regexps = "Add Regular Expressions support",
sax1 = "Add the older SAX1 interface",
threads = "Add multithread support",
tls = "Enable thread-local storage",
valid = "Add the DTD validation support",
xpath = "Add the XPATH support",
zlib = "Use libz",
c14n = "Add the Canonicalization support",
history = "history support for xmllint shell",
reader = "Add the xmlReader parsing interface",
schemas = "Add Relax-NG and Schemas support",
schematron = "Add Schematron support",
thread_alloc = "Add per-thread malloc hooks",
writer = "Add the xmlWriter saving interface",
xinclude = "Add the XInclude support",
xptr = "Add the XPointer support",
}
function get_libxml2_configs()
return libxml2_configs
end

@ -3,174 +3,116 @@ package("libxml2")
set_description("The XML C parser and toolkit of Gnome.") set_description("The XML C parser and toolkit of Gnome.")
set_license("MIT") set_license("MIT")
add_urls("https://download.gnome.org/sources/libxml2/$(version).tar.xz", {version = function (version) return format("%d.%d/libxml2-%s", version:major(), version:minor(), version) end}) add_urls("https://gitlab.gnome.org/GNOME/libxml2/-/archive/$(version)/libxml2-$(version).tar.bz2",
add_urls("https://gitlab.gnome.org/GNOME/libxml2.git") "https://gitlab.gnome.org/GNOME/libxml2.git",
add_versions("2.10.3", "5d2cc3d78bec3dbe212a9d7fa629ada25a7da928af432c93060ff5c17ee28a9c") "https://github.com/GNOME/libxml2.git")
add_versions("2.13.2", "e7c8f5e0b5542159e0ddc409c22c9164304b581eaa9930653a76fb845b169263")
add_configs("iconv", {description = "Enable libiconv support.", default = false, type = "boolean"}) add_versions("v2.13.4", "ba783b43e8b3475cbd2b1ef40474da6a4465105ee9818d76cd3ac7863550afce")
add_configs("python", {description = "Enable the python interface.", default = false, type = "boolean"}) add_versions("v2.13.2", "5091cf2767c3f7ba08bf59fbe85b01db36ca21abdcb37deea964fcb26a4391fb")
add_versions("v2.12.9", "3cd02671b20954865f5b3e90f192d8cc4d815b2362c2ff9a0b450b41648dac58")
add_versions("v2.11.9", "b9ed243467f82306da608a7a735ed55d90c7aaab0d3c6cf61284c43daa77cfee")
add_includedirs("include/libxml2") includes(path.join(os.scriptdir(), "configs.lua"))
if is_plat("windows") then for name, desc in pairs(get_libxml2_configs()) do
add_configs(name, {description = desc, default = false, type = "boolean"})
end
add_configs("tools", {description = "Build tools", default = false, type = "boolean"})
add_configs("all", {description = "Enable all configs, exclude python", default = false, type = "boolean"})
if is_plat("windows", "mingw") then
add_syslinks("wsock32", "ws2_32", "bcrypt") add_syslinks("wsock32", "ws2_32", "bcrypt")
else elseif is_plat("linux", "bsd") then
add_links("xml2") add_syslinks("m")
end end
if is_plat("linux") then if is_plat("linux") then
add_extsources("pkgconfig::libxml-2.0", "apt::libxml2-dev", "pacman::libxml2") add_extsources("pkgconfig::libxml-2.0", "apt::libxml2-dev", "pacman::libxml2")
add_syslinks("m")
end end
on_load("windows", "macosx", "linux", "iphoneos", "android", "bsd", function (package) add_includedirs("include/libxml2")
if package:is_plat("windows") then
if not package:config("shared") then add_deps("cmake")
package:add("defines", "LIBXML_STATIC")
end if on_check then
else on_check("iphoneos", function (package)
if package:gitref() then raise("All version unsupported now. see https://gitlab.gnome.org/GNOME/libxml2/-/issues/774\nYou can use `libxml2 master` branch to build or open a pull request to patch it.")
package:add("deps", "autoconf", "automake", "libtool", "pkg-config") end)
end
end end
if package:config("python") then
if package:is_cross() then on_load(function (package)
raise("libxml2 python interface does not support cross-compilation") if package:is_plat("windows", "mingw") and not package:config("shared") then
package:add("defines", "LIBXML_STATIC")
end end
if not package:config("iconv") then
raise("libxml2 python interface requires iconv to be enabled") if package:config("all") then
for name, _ in pairs(import("configs").get_libxml2_configs()) do
if name ~= "python" then
package:config_set(name, true)
end end
package:add("deps", "python 3.x")
end end
if package:config("iconv") then
package:add("deps", "libiconv")
end end
end)
on_install("windows", function (package) if package:config("threads") and package:is_plat("linux", "bsd") then
os.cd("win32") package:add("syslinks", "pthread")
local args = {"configure.js", "iso8859x=yes", "lzma=no", "zlib=no", "compiler=msvc"}
table.insert(args, "cruntime=/" .. package:config("vs_runtime"))
table.insert(args, "debug=" .. (package:debug() and "yes" or "no"))
table.insert(args, "iconv=" .. (package:config("iconv") and "yes" or "no"))
table.insert(args, "python=" .. (package:config("python") and "yes" or "no"))
table.insert(args, "prefix=" .. package:installdir())
if package:config("iconv") then
table.insert(args, "include=" .. package:dep("libiconv"):installdir("include"))
table.insert(args, "lib=" .. package:dep("libiconv"):installdir("lib"))
end
os.vrunv("cscript", args)
import("package.tools.nmake").install(package, {"/f", "Makefile.msvc"})
os.tryrm(path.join(package:installdir("bin"), "run*.exe"))
os.tryrm(path.join(package:installdir("bin"), "test*.exe"))
os.tryrm(path.join(package:installdir("lib"), "libxml2_a_dll.lib"))
if package:config("shared") then
os.tryrm(path.join(package:installdir("lib"), "libxml2_a.lib"))
else
os.tryrm(path.join(package:installdir("lib"), "libxml2.lib"))
os.tryrm(path.join(package:installdir("bin"), "libxml2.dll"))
end end
package:addenv("PATH", package:installdir("bin"))
if package:config("python") then
os.cd("../python")
io.replace("libxml_wrap.h", "XML_IGNORE_PEDANTIC_WARNINGS", "XML_IGNORE_DEPRECATION_WARNINGS")
io.replace("setup.py", "[xml_includes]", "[xml_includes,\"" .. package:dep("libiconv"):installdir("include"):gsub("\\", "\\\\") .. "\"]", {plain = true})
io.replace("setup.py", "WITHDLLS = 1", "WITHDLLS = 0", {plain = true})
if not package:config("shared") then
io.replace("setup.py", "libdirs = [", format("libdirs = [\n'%s',", package:dep("libiconv"):installdir("lib"):gsub("\\", "\\\\")), {plain = true})
io.replace("setup.py", "platformLibs = []", "platformLibs = ['iconv','wsock32','ws2_32']", {plain = true})
io.replace("setup.py", "\"xml2\"", "\"xml2_a\"", {plain = true})
io.replace("setup.py", "macros = []", "macros = [('LIBXML_STATIC','1')]", {plain = true})
else
os.cp(path.join(package:installdir("bin"), "libxml2.dll"), path.join(package:installdir("lib"), "site-packages", "libxml2.dll"))
end
os.mkdir(path.join(package:installdir("lib"), "site-packages"))
os.vrunv("python", {"-m", "pip", "install", "--prefix=" .. package:installdir(), "."}, {envs = {PYTHONPATH = path.join(package:installdir("lib"), "site-packages")}})
package:addenv("PYTHONPATH", path.join(package:installdir("lib"), "site-packages"))
end
end)
on_install("macosx", "linux", "iphoneos", "android@!windows", "bsd", function (package) if package:config("tools") then
if package:is_plat("iphoneos") then package:config_set("programs", true)
io.replace("dict.c", "defined(HAVE_GETENTROPY)", "0", {plain = true}) -- getentropy is private on iOS package:addenv("PATH", "bin")
end
import("package.tools.autoconf")
local configs = {"--disable-dependency-tracking",
"--without-lzma",
"--without-zlib"}
if package:config("shared") then
table.insert(configs, "--enable-shared=yes")
table.insert(configs, "--enable-static=no")
else
table.insert(configs, "--enable-shared=no")
table.insert(configs, "--enable-static=yes")
end end
if package:config("iconv") then if package:config("iconv") then
local iconvdir package:add("deps", "libiconv")
local iconv = package:dep("libiconv"):fetch()
if iconv then
iconvdir = table.wrap(iconv.sysincludedirs or iconv.includedirs)[1]
end
if iconvdir then
table.insert(configs, "--with-iconv=" .. path.directory(iconvdir))
else
table.insert(configs, "--with-iconv")
end end
else if package:config("icu") then
table.insert(configs, "--without-iconv") package:add("deps", "icu4c")
end end
if package:config("pic") ~= false then if package:config("lzma") then
table.insert(configs, "--with-pic") package:add("deps", "xz")
end end
local envs = autoconf.buildenvs(package) if package:config("zlib") then
if package:config("python") then package:add("deps", "zlib")
table.insert(configs, "--with-python")
table.insert(configs, "--with-ftp")
table.insert(configs, "--with-legacy")
local python = package:dep("python"):fetch()
if python then
local cflags, ldflags
for _, includedir in ipairs(python.sysincludedirs or python.includedirs) do
cflags = (cflags or "") .. " -I" .. includedir
end end
for _, linkdir in ipairs(python.linkdirs) do if package:config("readline") and package:is_plat("linux", "macosx") then
ldflags = (ldflags or "") .. " -L" .. linkdir package:add("deps", "readline")
end end
envs.PYTHON_CFLAGS = cflags if package:config("python") then
envs.PYTHON_LIBS = ldflags assert(package:config("shared"), "package(libxml2) python interface require shared lib")
if package:is_cross() then
raise("libxml2 python interface does not support cross-compilation")
end end
else if not package:config("iconv") then
table.insert(configs, "--without-python") raise("libxml2 python interface requires iconv to be enabled")
end end
autoconf.install(package, configs, {envs = envs}) package:add("deps", "python 3.x")
package:addenv("PATH", package:installdir("bin")) package:addenv("PYTHONPATH", package:installdir("python"))
if package:config("python") then
os.cd("python")
io.replace("setup.py", "[xml_includes]", "[xml_includes,\"" .. package:dep("libiconv"):installdir("include") .. "\"]", {plain = true})
if not package:config("shared") then
io.replace("setup.py", "libdirs = [", format("libdirs = [\n'%s',", package:dep("libiconv"):installdir("lib")), {plain = true})
io.replace("setup.py", "platformLibs = [\"m\",\"z\"]", "platformLibs = [\"iconv\",\"m\"]", {plain = true})
else
io.replace("setup.py", "platformLibs = [\"m\",\"z\"]", "platformLibs = [\"m\"]", {plain = true})
end end
local python = package:dep("python") end)
local pythonver = nil
if python:is_system() then on_install(function (package)
pythonver = import("core.base.semver").new(python:fetch().version) local configs = {"-DLIBXML2_WITH_TESTS=OFF"}
else table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
pythonver = python:version() table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
for name, _ in pairs(import("configs").get_libxml2_configs()) do
local enabled = (package:config(name) and "ON" or "OFF")
table.insert(configs, format("-DLIBXML2_WITH_%s=%s", name:upper(), enabled))
end end
os.vrunv("python3", {"-m", "pip", "install", "--prefix=" .. package:installdir(), "."}, {envs = {PYTHONPATH = path.join(package:installdir("lib"), format("python%s.%s", pythonver:major(), pythonver:minor()), "site-packages")}})
package:addenv("PYTHONPATH", path.join(package:installdir("lib"), format("python%s.%s", pythonver:major(), pythonver:minor()), "site-packages")) local opt = {}
local lzma = package:dep("xz")
if lzma and not lzma:config("shared") then
opt.cxflags = "-DLZMA_API_STATIC"
end end
import("package.tools.cmake").install(package, configs, opt)
end) end)
on_test(function (package) on_test(function (package)
assert(package:has_cfuncs("xmlInitParser", {includes = "libxml/parser.h"}))
if package:config("python") then if package:config("python") then
if package:is_plat("windows") then if package:is_plat("windows") then
os.vrun("python -c \"import libxml2\"") os.vrun([[python -c "import libxml2"]])
else else
os.vrun("python3 -c \"import libxml2\"") os.vrun([[python3 -c "import libxml2"]])
end end
end end
assert(package:has_cfuncs("xmlNewNode", {includes = {"libxml/parser.h", "libxml/tree.h"}}))
end) end)

@ -16,11 +16,7 @@ package("xz")
end end
end) end)
on_install("windows", "mingw@windows", function (package) on_install("windows", "mingw@windows,msys", function (package)
local configs = {}
if package:config("shared") then
configs.kind = "shared"
end
io.writefile("xmake.lua", [[ io.writefile("xmake.lua", [[
add_rules("mode.release", "mode.debug") add_rules("mode.release", "mode.debug")
target("lzma") target("lzma")
@ -52,7 +48,7 @@ package("xz")
add_headerfiles("src/liblzma/api/*.h") add_headerfiles("src/liblzma/api/*.h")
add_headerfiles("src/liblzma/api/(lzma/*.h)") add_headerfiles("src/liblzma/api/(lzma/*.h)")
]]) ]])
import("package.tools.xmake").install(package, configs) import("package.tools.xmake").install(package)
end) end)
on_install("macosx", "linux", "mingw@linux,macosx", function (package) on_install("macosx", "linux", "mingw@linux,macosx", function (package)

Loading…
Cancel
Save