This is an automated email from the ASF dual-hosted git repository.

tqchen pushed a commit to branch static-libxml2
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/static-libxml2 by this push:
     new a97a6b4472 [BUILD] Expand comment around static libxml2 substitution
a97a6b4472 is described below

commit a97a6b44725974e80da55fafbab33388fc55bd47
Author: tqchen <[email protected]>
AuthorDate: Mon Jun 1 15:15:41 2026 +0000

    [BUILD] Expand comment around static libxml2 substitution
    
    Document why the LLVM_LIBS filter substitutes the in-tree LibXml2
    target for the system libxml2 entry that llvm-config returns:
    
    - LLVM uses libxml2 only in WindowsManifest / WindowsResource code
      paths. On Linux these objects are never pulled in by TVM, so the
      filter is belt-and-braces (--as-needed would drop the dep anyway).
    - On Windows the same code paths ARE exercised by TVM's PE/COFF
      codegen, so the filter is the load-bearing mechanism that frees
      tvm_compiler.dll from a runtime xml2.dll dependency.
    - The regex [Xx][Mm][Ll]2 covers the common shapes (-lxml2, full
      paths to libxml2.a/.so/xml2.lib, case variants); broaden if a
      future toolchain returns a different name.
    
    No functional change.
---
 cmake/modules/LLVM.cmake | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/cmake/modules/LLVM.cmake b/cmake/modules/LLVM.cmake
index adeaa420bb..5c2fd6af76 100644
--- a/cmake/modules/LLVM.cmake
+++ b/cmake/modules/LLVM.cmake
@@ -57,15 +57,34 @@ if(NOT ${USE_LLVM} MATCHES ${IS_FALSE_PATTERN})
     src/target/hexagon/llvm/*.cc
   )
 
-  # When USE_STATIC_LIBXML2_FROM_SOURCE=ON, fetch libxml2 in-tree (no 
submodule) and
-  # replace any system libxml2 reference that llvm-config emitted with the
-  # in-tree static target. This keeps libtvm.so free of a runtime libxml2 dep.
+  # When USE_STATIC_LIBXML2_FROM_SOURCE=ON, fetch libxml2 in-tree (no
+  # submodule) and substitute the in-tree static `LibXml2` target for the
+  # system libxml2 reference that `llvm-config --system-libs` emits.
+  #
+  # Why this is needed (and is platform-asymmetric):
+  #   - LLVM uses libxml2 only inside lib/WindowsManifest and
+  #     lib/Object/WindowsResource — code paths that parse Windows
+  #     `.manifest` XML / PE resource files.
+  #   - On Linux, TVM never references those LLVM objects, so static-
+  #     archive lazy linking + `-Wl,--as-needed` drop the `-lxml2`
+  #     reference naturally. This filter is then belt-and-braces.
+  #   - On Windows, TVM's PE/COFF codegen path DOES exercise the
+  #     WindowsManifest code, so libxml2 symbols are actually
+  #     referenced. Without this substitution, `tvm_compiler.dll`
+  #     would acquire a runtime dependency on `xml2.dll` (the version
+  #     that mamba / system ship). This filter is the actual mechanism
+  #     that makes the Windows static build self-contained.
+  #
+  # The regex `[Xx][Mm][Ll]2` matches the common shapes llvm-config can
+  # emit across toolchains: `-lxml2`, full paths like
+  # `/usr/lib/.../libxml2.a` or `/path/.../xml2.lib`, and case-varying
+  # Windows entries. If a future toolchain returns libxml2 via a
+  # different name (e.g. `libxml2_static.lib`), broaden this regex
+  # accordingly.
   if(USE_STATIC_LIBXML2_FROM_SOURCE)
     include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/utils/CompileStaticLibXml2.cmake)
     _libxml2compile()
-    # Drop any -lxml2 / *libxml2* / *xml2* entries llvm-config injected.
     list(FILTER LLVM_LIBS EXCLUDE REGEX "[Xx][Mm][Ll]2")
-    # Link the in-tree static target instead.
     list(APPEND LLVM_LIBS LibXml2)
     message(STATUS "USE_STATIC_LIBXML2_FROM_SOURCE=ON: replaced system xml2 
with in-tree LibXml2")
   endif()

Reply via email to