[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 22:59:20 PST 2025


https://github.com/erwei-xilinx created https://github.com/llvm/llvm-project/pull/122865

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)

>From 09dc8ab793a93fffa1cae5a591abd2b0bf8227da Mon Sep 17 00:00:00 2001
From: erwei-xilinx <erwei.wang at amd.com>
Date: Mon, 13 Jan 2025 22:50:44 -0800
Subject: [PATCH] Avoids domain conflict with nanobind by specifying NB_DOMAIN

---
 mlir/cmake/modules/AddMLIRPython.cmake | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

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}
     )



More information about the Mlir-commits mailing list