# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/config/config.gni")
import("//build/ohos.gni")
# Execute the script and extract libxml2
action("libxml2_install_action") {
script = "//third_party/libxml2/install.py"
outputs = [
"${target_gen_dir}/libxml2-2.14.0/config.h.cmake.in",
"${target_gen_dir}/libxml2-2.14.0/include/libxml/xmlversion.h.in",
"${target_gen_dir}/libxml2-2.14.0/HTMLparser.c",
"${target_gen_dir}/libxml2-2.14.0/HTMLtree.c",
"${target_gen_dir}/libxml2-2.14.0/SAX2.c",
"${target_gen_dir}/libxml2-2.14.0/buf.c",
"${target_gen_dir}/libxml2-2.14.0/c14n.c",
"${target_gen_dir}/libxml2-2.14.0/catalog.c",
"${target_gen_dir}/libxml2-2.14.0/chvalid.c",
"${target_gen_dir}/libxml2-2.14.0/debugXML.c",
"${target_gen_dir}/libxml2-2.14.0/dict.c",
"${target_gen_dir}/libxml2-2.14.0/encoding.c",
"${target_gen_dir}/libxml2-2.14.0/entities.c",
"${target_gen_dir}/libxml2-2.14.0/error.c",
"${target_gen_dir}/libxml2-2.14.0/globals.c",
"${target_gen_dir}/libxml2-2.14.0/hash.c",
"${target_gen_dir}/libxml2-2.14.0/list.c",
"${target_gen_dir}/libxml2-2.14.0/nanohttp.c",
"${target_gen_dir}/libxml2-2.14.0/parser.c",
"${target_gen_dir}/libxml2-2.14.0/parserInternals.c",
"${target_gen_dir}/libxml2-2.14.0/pattern.c",
"${target_gen_dir}/libxml2-2.14.0/relaxng.c",
"${target_gen_dir}/libxml2-2.14.0/schematron.c",
"${target_gen_dir}/libxml2-2.14.0/threads.c",
"${target_gen_dir}/libxml2-2.14.0/tree.c",
"${target_gen_dir}/libxml2-2.14.0/uri.c",
"${target_gen_dir}/libxml2-2.14.0/valid.c",
"${target_gen_dir}/libxml2-2.14.0/xinclude.c",
"${target_gen_dir}/libxml2-2.14.0/xlink.c",
"${target_gen_dir}/libxml2-2.14.0/xmlIO.c",
"${target_gen_dir}/libxml2-2.14.0/xmlmemory.c",
"${target_gen_dir}/libxml2-2.14.0/xmlmodule.c",
"${target_gen_dir}/libxml2-2.14.0/xmlreader.c",
"${target_gen_dir}/libxml2-2.14.0/xmlregexp.c",
"${target_gen_dir}/libxml2-2.14.0/xmlsave.c",
"${target_gen_dir}/libxml2-2.14.0/xmlschemas.c",
"${target_gen_dir}/libxml2-2.14.0/xmlschemastypes.c",
"${target_gen_dir}/libxml2-2.14.0/xmlstring.c",
"${target_gen_dir}/libxml2-2.14.0/xmlunicode.c",
"${target_gen_dir}/libxml2-2.14.0/xmlwriter.c",
"${target_gen_dir}/libxml2-2.14.0/xpath.c",
"${target_gen_dir}/libxml2-2.14.0/xpointer.c",
"${target_gen_dir}/libxml2-2.14.0/xzlib.c",
"${target_gen_dir}/libxml2-2.14.0/shell.c",
"${target_gen_dir}/libxml2-2.14.0/xmllint.c",
]
inputs = [ "//third_party/libxml2/libxml2-2.14.0.tar.xz" ]
inputs += [
"Backport-CVE-2025-32414-python-Read-at-most-len-4-ch-c.patch",
"Backport-CVE-2025-32415-schemas-Fix-heap-buffer-over-c.patch",
"Fix_XML_PARSE_NOBLANKS_dropping_non-whitespace_text.patch",
"Backport-CVE-2025-6021-tree-Fix-integer-overflow-in-xmlBuildQName-c.patch",
"Fix-relaxng-is-parsed-to-an-infinite-attrs-next-loop.patch",
"Backport-CVE-2025-6170-Fix-potential-buffer-overflow-of-interactive-shell.patch",
"Fix-CVE-2025-49794-CVE-2025-49796-memory-safety-issues-in-xmlSchematronReportOutput.patch",
"Fix-CVE-2025-49795-null-pointer-dereference-leading-to-DoS.patch",
"Fix-CVE-2025-8732-Prevent-infinite-recursion-in-xmlCatalogList.patch",
"Fix-CVE-2026-0990-catalog-prevent-inf-recursion-in-xmlCatalogXMLResolveURI.patch",
"Fix-CVE-2026-0992-catalog-Ignore-repeated-nextCatalog-entries.patch",
"Fix-CVE-2026-0989-Add-RelaxNG-include-limit.patch",
"Fix-CVE-2026-1757-shell-free-cmdline-before-continue.patch",
"Fix-CVE-2026-6732-Fix-Crash-parser.c.patch",
"Fix-CVE-2026-11979-xmlcatalog-overflow-check-for-large-shell-commands.patch"
]
args = [
"--gen-dir",
rebase_path("${target_gen_dir}", root_build_dir),
"--source-file",
rebase_path("//third_party/libxml2"),
]
}
# This is the configuration needed to use libxml2.
config("libxml2_config") {
include_dirs = [
get_label_info(":libxml2_generate_header", "target_out_dir") + "/include",
get_label_info(":libxml2_install_action", "target_gen_dir") +
"/libxml2-2.14.0/include",
]
}
# This is the configuration used to build libxml2 itself. It should not be needed outside of this
# library.
#
# This has to be a config instead of flags directly specified on the libxml2 target so the -Wno-*
# flags are ordered after the -Werror flags from the default configs.
config("libxml2_private_config") {
visibility = [ ":*" ]
cflags = [
"-Wno-empty-body",
"-Wno-incompatible-pointer-types",
"-Wno-missing-field-initializers",
"-Wno-self-assign",
"-Wno-sign-compare",
"-Wno-tautological-pointer-compare",
"-Wno-unused-function",
"-Wno-enum-compare",
"-Wno-int-conversion",
"-Wno-uninitialized",
"-Wno-implicit-fallthrough",
]
defines = [
"HAVE_CONFIG_H",
"_REENTRANT",
]
if (is_linux) {
defines += [ "_GNU_SOURCE" ]
}
}
# This is the configuration needed to use static libxml2.
config("libxml2_static_config") {
include_dirs = [
get_label_info(":libxml2_generate_header", "target_out_dir") + "/include",
get_label_info(":libxml2_install_action", "target_gen_dir") +
"/libxml2-2.14.0/include",
]
if (is_mingw) {
defines = [ "LIBXML_STATIC" ]
} else {
defines = [
"HAVE_CONFIG_H",
"_REENTRANT",
]
}
}
config("libxml2_static_private_config") {
cflags = [
"-Wno-implicit-fallthrough",
"-Wno-implicit-function-declaration",
"-Wno-int-conversion",
"-Wno-uninitialized",
"-Wno-sometimes-uninitialized",
]
cflags_cc = [ "-std=c++17" ]
}
ohos_shared_library("libxml2") {
branch_protector_ret = "pac_ret"
output_values = get_target_outputs(":libxml2_install_action")
sources = filter_exclude(output_values,
[
"*.h.cmake.in",
"*.h.in",
])
public_configs = [ ":libxml2_config" ]
configs = [ ":libxml2_private_config" ]
if (is_linux) {
libs = [ "dl" ]
}
if (is_mingw) {
libs = [
"bcrypt",
"ws2_32",
]
}
if (current_os == "ios") {
ldflags = [
"-Wl",
"-install_name",
"@rpath/libxml2_shared.framework/libxml2_shared",
]
output_name = "xml2_shared"
}
deps = [
":libxml2_generate_header",
":libxml2_install_action",
]
innerapi_tags = [
"chipsetsdk",
"platformsdk",
"sasdk",
]
install_images = [
"updater",
"system",
]
part_name = "libxml2"
subsystem_name = "thirdparty"
}
if (current_os == "ios") {
ohos_combine_darwin_framework("libxml2_shared") {
deps = [ ":libxml2" ]
subsystem_name = "thirdparty"
part_name = "libxml2"
}
}
ohos_static_library("static_libxml2") {
branch_protector_ret = "pac_ret"
output_values = get_target_outputs(":libxml2_install_action")
sources = filter_exclude(output_values,
[
"*.h.cmake.in",
"*.h.in",
])
public_configs = [ ":libxml2_static_config" ]
configs = [ ":libxml2_static_private_config" ]
if (is_mingw) {
libs = [
"bcrypt",
"ws2_32",
]
}
deps = [
":libxml2_generate_header",
":libxml2_install_action",
]
part_name = "libxml2"
subsystem_name = "thirdparty"
}
action("libxml2_generate_header") {
script = "generate_header.py"
config_in_path = get_label_info(":libxml2_install_action", "target_gen_dir") +
"/libxml2-2.14.0/config.h.cmake.in"
xmlversion_in_path =
get_label_info(":libxml2_install_action", "target_gen_dir") +
"/libxml2-2.14.0/include/libxml/xmlversion.h.in"
config_json_path = "config_linux.json"
xml_version_json_path = "xml_version.json"
if (is_mingw) {
config_json_path = "config_win.json"
}
inputs = [
config_in_path,
xmlversion_in_path,
config_json_path,
xml_version_json_path,
]
config_path = get_label_info(":libxml2_generate_header", "target_out_dir") +
"/include/config.h"
xmlversion_path =
get_label_info(":libxml2_generate_header", "target_out_dir") +
"/include/libxml/xmlversion.h"
outputs = [
config_path,
xmlversion_path,
]
args = [
"--config-input-path",
rebase_path(config_in_path, root_build_dir),
"--config-path",
rebase_path(config_path, root_build_dir),
"--xmlversion-input-path",
rebase_path(xmlversion_in_path, root_build_dir),
"--xmlversion-path",
rebase_path(xmlversion_path, root_build_dir),
"--config-json",
rebase_path(config_json_path, root_build_dir),
"--xmlversion-json",
rebase_path(xml_version_json_path, root_build_dir),
]
deps = [ ":libxml2_install_action" ]
}