Skip to content

[lldb] Add build option to specify the libxml 2 version #142183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 30, 2025

Conversation

Steelskin
Copy link
Contributor

The Swift Windows toolchain uses its own static build of libxml 2, which is more recent than 2.8, resulting in the provided libxml 2 to be rejected. This change allows to specify a custom version for libxml 2, while defaulting to 2.8.

The Swift Windows toolchain uses its own static build of libxml 2, which
is more recent than 2.8, resulting in the provided libxml 2 to be
rejected. This change allows to specify a custom version for libxml 2,
while defaulting to 2.8.
@Steelskin Steelskin requested a review from JDevlieghere as a code owner May 30, 2025 16:32
@llvmbot llvmbot added the lldb label May 30, 2025
@llvmbot
Copy link
Member

llvmbot commented May 30, 2025

@llvm/pr-subscribers-lldb

Author: Fabrice de Gans (Steelskin)

Changes

The Swift Windows toolchain uses its own static build of libxml 2, which is more recent than 2.8, resulting in the provided libxml 2 to be rejected. This change allows to specify a custom version for libxml 2, while defaulting to 2.8.


Full diff: https://github.com/llvm/llvm-project/pull/142183.diff

1 Files Affected:

  • (modified) lldb/cmake/modules/LLDBConfig.cmake (+3-1)
diff --git a/lldb/cmake/modules/LLDBConfig.cmake b/lldb/cmake/modules/LLDBConfig.cmake
index cfd626c9358a1..f25ad1333468c 100644
--- a/lldb/cmake/modules/LLDBConfig.cmake
+++ b/lldb/cmake/modules/LLDBConfig.cmake
@@ -51,13 +51,15 @@ macro(add_optional_dependency variable description package found)
   message(STATUS "${description}: ${${variable}}")
 endmacro()
 
+option(LLDB_LIBXML2_VERSION "Sepcify the version of libxml 2 to use with LLDB" "2.8")
+
 add_optional_dependency(LLDB_ENABLE_SWIG "Enable SWIG to generate LLDB bindings" SWIG SWIG_FOUND VERSION 4)
 add_optional_dependency(LLDB_ENABLE_LIBEDIT "Enable editline support in LLDB" LibEdit LibEdit_FOUND)
 add_optional_dependency(LLDB_ENABLE_CURSES "Enable curses support in LLDB" CursesAndPanel CURSESANDPANEL_FOUND)
 add_optional_dependency(LLDB_ENABLE_LZMA "Enable LZMA compression support in LLDB" LibLZMA LIBLZMA_FOUND)
 add_optional_dependency(LLDB_ENABLE_LUA "Enable Lua scripting support in LLDB" LuaAndSwig LUAANDSWIG_FOUND)
 add_optional_dependency(LLDB_ENABLE_PYTHON "Enable Python scripting support in LLDB" PythonAndSwig PYTHONANDSWIG_FOUND)
-add_optional_dependency(LLDB_ENABLE_LIBXML2 "Enable Libxml 2 support in LLDB" LibXml2 LIBXML2_FOUND VERSION 2.8)
+add_optional_dependency(LLDB_ENABLE_LIBXML2 "Enable Libxml 2 support in LLDB" LibXml2 LIBXML2_FOUND VERSION ${LLDB_LIBXML2_VERSION})
 add_optional_dependency(LLDB_ENABLE_FBSDVMCORE "Enable libfbsdvmcore support in LLDB" FBSDVMCore FBSDVMCore_FOUND QUIET)
 
 option(LLDB_USE_ENTITLEMENTS "When codesigning, use entitlements if available" ON)

@JDevlieghere
Copy link
Member

Could the problem be that the statically linked libxml2 is reporting the wrong version or something? We don't pass the EXACT flag, which means that CMake will find a version that "is compatible" [1]. The latter is intentionally vague and I couldn't immediately find the corresponding logic for libxml2. However, on my linux machine, CMake happily picks up libxml 2.12.7 with the existing logic.

[1] https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-version-selection

@Steelskin
Copy link
Contributor Author

This is how the version file is configured in libxml2: https://github.com/GNOME/libxml2/blob/0740a367a570c40246fe8077c2d172b63693f105/CMakeLists.txt#L596

write_basic_package_version_file(
	${CMAKE_CURRENT_BINARY_DIR}/libxml2-config-version.cmake
	VERSION ${PROJECT_VERSION}
	COMPATIBILITY ExactVersion
)

The problem is the COMPATIBILITY ExactVersion part. I have been told there are also ABI incompatibilities with different libxml 2 versions for the Swift build but I am not familiar with the details.

@JDevlieghere
Copy link
Member

Ack. My apt package doesn't install libxml2-config-version.cmake so I assume CMake is falling back on some standard logic for finding it and that would explain why CMake is happy to use 2.12 on my system.

That said, it seems like this is done intentionally, and this is working around that (e.g. the ABI incompatibility you mentioned). That might be fine for how we use libxml2 in lldb but let's make it clear that folks are doing this at their own risk. Can you update the description or add a comment with something along those lines?

@Steelskin
Copy link
Contributor Author

Ack. My apt package doesn't install libxml2-config-version.cmake so I assume CMake is falling back on some standard logic for finding it and that would explain why CMake is happy to use 2.12 on my system.

That said, it seems like this is done intentionally, and this is working around that (e.g. the ABI incompatibility you mentioned). That might be fine for how we use libxml2 in lldb but let's make it clear that folks are doing this at their own risk. Can you update the description or add a comment with something along those lines?

I updated the comment and marked the new cache variable as advanced.

Copy link
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@compnerd compnerd merged commit a080c74 into llvm:main May 30, 2025
10 checks passed
Steelskin added a commit to Steelskin/llvm-project that referenced this pull request May 30, 2025
The Swift Windows toolchain uses its own static build of libxml 2, which
is more recent than 2.8, resulting in the provided libxml 2 to be
rejected. This change allows to specify a custom version for libxml 2,
while defaulting to 2.8.

(cherry-picked from commit llvm/llvm-project@a080c74)
@Steelskin Steelskin deleted the fabrice/option-lldb-libxml2-version branch June 3, 2025 21:09
Steelskin added a commit to Steelskin/llvm-project that referenced this pull request Jun 3, 2025
The Swift Windows toolchain uses its own static build of libxml 2, which
is more recent than 2.8, resulting in the provided libxml 2 to be
rejected. This change allows to specify a custom version for libxml 2,
while defaulting to 2.8.

(cherry-picked from commit llvm/llvm-project@a080c74)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants