Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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(
Expand Down
12 changes: 12 additions & 0 deletions prereqs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
76 changes: 76 additions & 0 deletions third_party/libxml2/00_config_h.patch
Original file line number Diff line number Diff line change
@@ -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/<VERSION>/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 <dlfcn.h> header file. */
+#define HAVE_DLFCN_H 1
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdio.h> header file. */
+#define HAVE_STDIO_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/types.h> 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 */
165 changes: 165 additions & 0 deletions third_party/libxml2/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
]
]
6 changes: 6 additions & 0 deletions toolchains/android/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down