[llvm] [bazel] Build WindowsManifest with libxml2 (PR #224917)

Fabian Meumertzheim via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 20 04:39:28 PDT 2026


https://github.com/fmeum created https://github.com/llvm/llvm-project/pull/224917

The Bazel build didn't provide a way to enable `LLVM_ENABLE_LIBXML2`, so `llvm-mt` always failed with `llvm-mt: error: no libxml2` and lld-link fell back to `mt.exe` for manifest merging (`/MANIFESTINPUT:` with more than one input, `/MANIFESTUAC`).

This adds a `libxml2` wrapper to the `third-party` package in the same way as the existing `zlib` and `zstd` wrappers, makes `WindowsManifest` depend on it and provides the BCR `libxml2` module as `@llvm_libxml2`. It can be disabled with `-- at llvm-project//third-party:llvm_enable_libxml2=false`.

Measured on a standalone `llvm-mt` built with ThinLTO in opt mode, libxml2 adds about 490 KiB (macOS arm64) to 550 KiB (Linux x86_64, musl) to the stripped binary.


>From 5765d11d296fb7aed6f48bcebab2feeae46d5f2a Mon Sep 17 00:00:00 2001
From: Fabian Meumertzheim <fabian at meumertzhe.im>
Date: Sun, 20 Sep 2026 13:39:16 +0200
Subject: [PATCH] [bazel] Build WindowsManifest with libxml2

The Bazel build didn't provide a way to enable LLVM_ENABLE_LIBXML2, so
llvm-mt always failed with "no libxml2" and lld-link fell back to
mt.exe for manifest merging.

Add a libxml2 wrapper to the third-party package in the same way as the
zlib and zstd wrappers, make WindowsManifest depend on it and provide the
BCR libxml2 module as @llvm_libxml2. It can be disabled with
-- at llvm-project//third-party:llvm_enable_libxml2=false.
---
 utils/bazel/MODULE.bazel                      |  1 +
 .../llvm-project-overlay/llvm/BUILD.bazel     |  4 +++
 .../third-party/BUILD.bazel                   | 28 +++++++++++++++++++
 3 files changed, 33 insertions(+)

diff --git a/utils/bazel/MODULE.bazel b/utils/bazel/MODULE.bazel
index 783cfca05d14a..0cf21c0cb3dc1 100644
--- a/utils/bazel/MODULE.bazel
+++ b/utils/bazel/MODULE.bazel
@@ -23,6 +23,7 @@ bazel_dep(name = "bazel_skylib", version = "1.9.0")
 bazel_dep(name = "platforms", version = "1.1.0")
 bazel_dep(name = "zlib-ng", version = "2.3.3", repo_name = "llvm_zlib")
 bazel_dep(name = "zstd", version = "1.5.7.bcr.1", repo_name = "llvm_zstd")
+bazel_dep(name = "libxml2", version = "2.15.3", repo_name = "llvm_libxml2")
 bazel_dep(name = "gmp", version = "6.3.0.bcr.1")
 bazel_dep(name = "mpc", version = "1.4.1.bcr.2")
 bazel_dep(name = "mpfr", version = "4.2.2.bcr.1")
diff --git a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
index b7765075c72fb..d168c5ddad827 100644
--- a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
@@ -4750,6 +4750,10 @@ cc_library(
     deps = [
         ":Support",
         ":config",
+        # We unconditionally depend on the custom LLVM libxml2 wrapper. This
+        # will be an empty library unless libxml2 is enabled, in which case it
+        # will both provide the necessary dependencies and configuration defines.
+        "//third-party:libxml2",
     ],
 )
 
diff --git a/utils/bazel/llvm-project-overlay/third-party/BUILD.bazel b/utils/bazel/llvm-project-overlay/third-party/BUILD.bazel
index e2131005a693c..bcc8705c1b475 100644
--- a/utils/bazel/llvm-project-overlay/third-party/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/third-party/BUILD.bazel
@@ -62,3 +62,31 @@ cc_library_wrapper(
         "//conditions:default": [],
     }),
 )
+
+bool_flag(
+    name = "llvm_enable_libxml2",
+    build_setting_default = True,
+)
+
+config_setting(
+    name = "llvm_libxml2_enabled",
+    flag_values = {":llvm_enable_libxml2": "true"},
+)
+
+cc_library_wrapper(
+    name = "libxml2",
+    defines = select({
+        ":llvm_libxml2_enabled": [
+            "LLVM_ENABLE_LIBXML2=1",
+        ],
+        "//conditions:default": [
+            "LLVM_ENABLE_LIBXML2=0",
+        ],
+    }),
+    deps = select({
+        ":llvm_libxml2_enabled": [
+            "@llvm_libxml2//:libxml2",
+        ],
+        "//conditions:default": [],
+    }),
+)



More information about the llvm-commits mailing list