[Mlir-commits] [mlir] [mlir][python][cmake] Allows for specifying `NB_DOMAIN` in `add_mlir_python_extension` (PR #122865)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Jan 13 23:00:10 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: None (erwei-xilinx)

<details>
<summary>Changes</summary>

This PR allows the users to specify the `NB_DOMAIN` for `add_mlir_python_extension`. This allows users to avoid nanobind domain conflicts, when python bindings from multiple `mlir` projects were imported. (https://nanobind.readthedocs.io/en/latest/faq.html#how-can-i-avoid-conflicts-with-other-projects-using-nanobind)

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


1 Files Affected:

- (modified) mlir/cmake/modules/AddMLIRPython.cmake (+8-1) 


``````````diff
diff --git a/mlir/cmake/modules/AddMLIRPython.cmake b/mlir/cmake/modules/AddMLIRPython.cmake
index 0679db9cf93e19..82a93c1a3c78c9 100644
--- a/mlir/cmake/modules/AddMLIRPython.cmake
+++ b/mlir/cmake/modules/AddMLIRPython.cmake
@@ -658,6 +658,13 @@ function(add_mlir_python_extension libname extname)
     set(eh_rtti_enable -frtti -fexceptions)
   endif ()
 
+  # Avoids domain conflict with nanobind by specifying NB_DOMAIN.
+  if(NB_DOMAIN)
+    set(_nb_domain ${NB_DOMAIN})
+  else()
+    set(_nb_domain "mlir")
+  endif ()
+
   # The actual extension library produces a shared-object or DLL and has
   # sources that must be compiled in accordance with pybind11 needs (RTTI and
   # exceptions).
@@ -667,7 +674,7 @@ function(add_mlir_python_extension libname extname)
     )
   elseif(ARG_PYTHON_BINDINGS_LIBRARY STREQUAL "nanobind")
     nanobind_add_module(${libname}
-      NB_DOMAIN mlir
+      NB_DOMAIN ${_nb_domain}
       FREE_THREADED
       ${ARG_SOURCES}
     )

``````````

</details>


https://github.com/llvm/llvm-project/pull/122865


More information about the Mlir-commits mailing list