https://github.com/efferre79 updated 
https://github.com/llvm/llvm-project/pull/86931

>From 51670af1137a60ec2edacaa4fe0338d99549dd1b Mon Sep 17 00:00:00 2001
From: efferre79 <[email protected]>
Date: Thu, 19 Mar 2026 22:53:24 +0100
Subject: [PATCH] [libclang/python] export libclang version to the bindings

---
 clang/bindings/python/clang/cindex.py              |  6 ++++++
 clang/bindings/python/tests/cindex/test_version.py | 13 +++++++++++++
 clang/docs/ReleaseNotes.rst                        |  2 ++
 3 files changed, 21 insertions(+)
 create mode 100755 clang/bindings/python/tests/cindex/test_version.py

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index c34a1c0db01e9..48b3f5bfef6b6 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -4339,6 +4339,7 @@ def set_property(self, property, value):
     ("clang_getCanonicalCursor", [Cursor], Cursor),
     ("clang_getCanonicalType", [Type], Type),
     ("clang_getChildDiagnostics", [Diagnostic], c_object_p),
+    ("clang_getClangVersion", [], _CXString),
     ("clang_getCompletionAvailability", [c_void_p], c_int),
     ("clang_getCompletionBriefComment", [c_void_p], _CXString),
     ("clang_getCompletionChunkCompletionString", [c_void_p, c_int], 
c_object_p),
@@ -4649,6 +4650,11 @@ def get_cindex_library(self) -> CDLL:
 
         return library
 
+    def get_version(self):
+        """
+        Returns the libclang version string used by the bindings
+        """
+        return _CXString.from_result(self.lib.clang_getClangVersion())
 
 conf = Config()
 
diff --git a/clang/bindings/python/tests/cindex/test_version.py 
b/clang/bindings/python/tests/cindex/test_version.py
new file mode 100755
index 0000000000000..d5aa6ab1670b5
--- /dev/null
+++ b/clang/bindings/python/tests/cindex/test_version.py
@@ -0,0 +1,13 @@
+import unittest
+import re
+from clang.cindex import Config
+
+class TestClangVersion(unittest.TestCase):
+
+    def test_get_version_format(self):
+        conf = Config()
+        version = conf.get_version()
+
+        self.assertTrue(version.startswith("clang version"))
+        self.assertRegex(version, r"^clang version \d+\.\d+\.\d+")
+
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 45234c316eba8..7535825433983 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -544,6 +544,8 @@ Python Binding Changes
   ``CodeCompletionResults.results`` should be changed to directly use
   ``CodeCompletionResults``: it nows supports ``__len__`` and ``__getitem__``,
   so it can be used the same as ``CodeCompletionResults.results``.
+- Added a new helper method get_version() for the class Config to read the
+  version string of the libclang in use
 
 OpenMP Support
 --------------

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to