diff --git a/MODULE.bazel b/MODULE.bazel index 427043db6..123bb1916 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -9,6 +9,7 @@ bazel_dep(name = "rules_license", version = "1.0.0") bazel_dep(name = "rules_java", version = "9.3.0") bazel_dep(name = "rules_cc", version = "0.2.14") bazel_dep(name = "rules_shell", version = "0.6.1") +bazel_dep(name = "libxml2", version = "2.15.3") bazel_dep(name = "stardoc", version = "0.8.0", dev_dependency = True) @@ -58,6 +59,7 @@ python.toolchain( bazel_dep(name = "rules_proto", version = "7.1.0", repo_name = "rules_proto") maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven") + # Maven for android_ide_common need to be separated into their own separate maven_install for now # due to compatibility issues with newer versions. maven.install( diff --git a/prereqs.bzl b/prereqs.bzl index a4fa5d29a..297a64bde 100644 --- a/prereqs.bzl +++ b/prereqs.bzl @@ -212,6 +212,18 @@ def rules_android_prereqs(dev_mode = False): ], ) + maybe( + http_archive, + name = "libxml2", + sha256 = "0da50c1415f4ec0364569d2119b1436ba837b31df44af28569d234272c23cf1f", + strip_prefix = "libxml2-v2.15.3", + build_file = Label("//third_party/libxml2:BUILD.bazel"), + patches = [Label("//third_party/libxml2:00_config_h.patch")], + urls = [ + "https://gitlab.gnome.org/GNOME/libxml2/-/archive/v2.15.3/libxml2-v2.15.3.tar.gz", + ], + ) + _apksig_archive() _com_android_dex_archive() diff --git a/third_party/libxml2/00_config_h.patch b/third_party/libxml2/00_config_h.patch new file mode 100644 index 000000000..fc215ee70 --- /dev/null +++ b/third_party/libxml2/00_config_h.patch @@ -0,0 +1,76 @@ +This patch injects the libxml2 config.h file required for the build. It was generated using the +overlay from the Bazel Central Registry from +https://github.com/bazelbuild/bazel-central-registry/tree/main/modules/libxml2/2.15.3/overlay/config.h + +To update or regenerate this patch: +1. Download config.h from https://raw.githubusercontent.com/bazelbuild/bazel-central-registry/main/modules/libxml2//overlay/config.h +2. Run: diff -u --label /dev/null /dev/null --label b/config.h config.h > 00_config_h.patch +3. Re-add this comments to the patch file. + +--- /dev/null ++++ b/config.h +@@ -0,0 +1,64 @@ ++/* config.h. Generated from config.h.in by configure. */ ++/* config.h.in. Generated from configure.ac by autoheader. */ ++ ++/* Define to 1 if you have the header file. */ ++#define HAVE_DLFCN_H 1 ++ ++/* Define to 1 if you have the header file. */ ++#define HAVE_INTTYPES_H 1 ++ ++/* Define to 1 if you have the header file. */ ++#define HAVE_STDINT_H 1 ++ ++/* Define to 1 if you have the header file. */ ++#define HAVE_STDIO_H 1 ++ ++/* Define to 1 if you have the header file. */ ++#define HAVE_STDLIB_H 1 ++ ++/* Define to 1 if you have the header file. */ ++#define HAVE_STRING_H 1 ++ ++/* Define to 1 if you have the header file. */ ++#define HAVE_SYS_STAT_H 1 ++ ++/* Define to 1 if you have the header file. */ ++#define HAVE_SYS_TYPES_H 1 ++ ++/* Define to the sub-directory where libtool stores uninstalled libraries. */ ++#define LT_OBJDIR ".libs/" ++ ++/* Name of package */ ++#define PACKAGE "libxml2" ++ ++/* Define to the address where bug reports for this package should be sent. */ ++#define PACKAGE_BUGREPORT "" ++ ++/* Define to the full name of this package. */ ++#define PACKAGE_NAME "libxml2" ++ ++/* Define to the full name and version of this package. */ ++#define PACKAGE_STRING "libxml2 2.15.3" ++ ++/* Define to the one symbol short name of this package. */ ++#define PACKAGE_TARNAME "libxml2" ++ ++/* Define to the home page for this package. */ ++#define PACKAGE_URL "" ++ ++/* Define to the version of this package. */ ++#define PACKAGE_VERSION "2.15.3" ++ ++/* Define to 1 if all of the C90 standard headers exist (not just the ones ++ required in a freestanding environment). This macro is provided for ++ backward compatibility; new code need not use it. */ ++#define STDC_HEADERS 1 ++ ++/* Version number of package */ ++#define VERSION "2.15.3" ++ ++/* System configuration directory (/etc) */ ++#define XML_SYSCONFDIR "/usr/local/etc" ++ ++/* TLS specifier */ ++/* #undef XML_THREAD_LOCAL */ diff --git a/third_party/libxml2/BUILD.bazel b/third_party/libxml2/BUILD.bazel new file mode 100644 index 000000000..915f08b94 --- /dev/null +++ b/third_party/libxml2/BUILD.bazel @@ -0,0 +1,165 @@ +# Copied from https://github.com/bazelbuild/bazel-central-registry/blob/main/modules/libxml2/2.15.3/overlay/BUILD.bazel. + +load("@rules_cc//cc:cc_binary.bzl", "cc_binary") +load("@rules_cc//cc:cc_library.bzl", "cc_library") +load("@rules_cc//cc:cc_test.bzl", "cc_test") + +config_setting( + name = "is_windows_clang_mingw", + constraint_values = ["@platforms//os:windows"], + flag_values = {"@rules_cc//cc/compiler:compiler": "clang"}, +) + +config_setting( + name = "is_windows_clang_cl", + constraint_values = ["@platforms//os:windows"], + flag_values = {"@rules_cc//cc/compiler:compiler": "clang-cl"}, +) + +config_setting( + name = "is_windows_msvc", + constraint_values = ["@platforms//os:windows"], + flag_values = {"@rules_cc//cc/compiler:compiler": "msvc-cl"}, +) + +UNIX_DEFINES = [ + "HAVE_DECL_GETENTROPY", + "HAVE_DECL_GLOB", + "HAVE_DECL_MMAP", + "HAVE_DLOPEN", + "HAVE_FUNC_ATTRIBUTE_DESTRUCTOR", + "HAVE_PTHREAD_H", + "HAVE_STRINGS_H", + "HAVE_UNISTD_H", +] + +cc_library( + name = "xml2", + srcs = [ + "HTMLparser.c", + "HTMLtree.c", + "SAX2.c", + "buf.c", + "c14n.c", + "catalog.c", + "chvalid.c", + "debugXML.c", + "dict.c", + "encoding.c", + "entities.c", + "error.c", + "globals.c", + "hash.c", + "list.c", + "nanohttp.c", + "parser.c", + "parserInternals.c", + "pattern.c", + "relaxng.c", + "schematron.c", + "threads.c", + "tree.c", + "uri.c", + "valid.c", + "xinclude.c", + "xlink.c", + "xmlIO.c", + "xmlmemory.c", + "xmlmodule.c", + "xmlreader.c", + "xmlregexp.c", + "xmlsave.c", + "xmlschemas.c", + "xmlschemastypes.c", + "xmlstring.c", + "xmlwriter.c", + "xpath.c", + "xpointer.c", + ] + glob(["include/private/*.h"]), + hdrs = glob([ + "include/libxml/*.h", + "*.h", + ]), + defines = select({ + "@platforms//os:linux": UNIX_DEFINES + [ + "HAVE_POLL_H", + ], + "@platforms//os:macos": UNIX_DEFINES, + "@platforms//os:windows": [ + "LIBXML_STATIC", + '"XML_THREAD_LOCAL=__declspec(thread)"', + ], + "//conditions:default": [], + }), + includes = ["include"], + linkopts = select({ + ":is_windows_clang_cl": [ + "bcrypt.lib", + ], + ":is_windows_msvc": [ + "bcrypt.lib", + ], + ":is_windows_clang_mingw": [ + "-lbcrypt", + ], + "//conditions:default": [ + "-lm", + "-pthread", + "-ldl", + ], + }), + textual_hdrs = [ + "codegen/charset.inc", + "codegen/escape.inc", + "codegen/html5ent.inc", + "codegen/ranges.inc", + "codegen/unicode.inc", + ], + visibility = ["//visibility:public"], +) + +alias( + name = "libxml2", + actual = ":xml2", + visibility = ["//visibility:public"], +) + +cc_binary( + name = "xmllint", + srcs = [ + "lintmain.c", + "shell.c", + "xmllint.c", + ], + visibility = ["//visibility:public"], + deps = ["//:libxml2"], +) + +cc_binary( + name = "xmlcatalog", + srcs = ["xmlcatalog.c"], + visibility = ["//visibility:public"], + deps = ["//:libxml2"], +) + +DATA = glob([ + "test/**", +]) + +[ + cc_test( + name = test.removeprefix("test") + "_test", + srcs = [test + ".c"], + data = DATA, + deps = ["//:libxml2"], + ) + for test in [ + "testapi", + "testchar", + "testdict", + "testlimits", + # TODO(zbarsky): Figure out why these two fail in BCR CI but work locally... + # "testparser", + # "testrecurse", + ] +] diff --git a/toolchains/android/toolchain.bzl b/toolchains/android/toolchain.bzl index 98fb7773e..8789dbd90 100644 --- a/toolchains/android/toolchain.bzl +++ b/toolchains/android/toolchain.bzl @@ -269,6 +269,12 @@ _ATTRS = dict( default = "//toolchains/android:unzip", executable = True, ), + xmllint_tool = attr.label( + cfg = "exec", + default = "@libxml2//:xmllint", + allow_files = True, + executable = True, + ), xsltproc_tool = attr.label( cfg = "exec", default = Label("//tools/android/xslt:xslt"),