From 9e863cd44945345f22a28cdd3ea12aaa7963345e Mon Sep 17 00:00:00 2001 From: erwei-xilinx Date: Thu, 16 Jan 2025 07:26:29 -0800 Subject: [PATCH] [mlir][python][cmake] Allows for specifying `NB_DOMAIN` in `add_mlir_python_extension` (#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) --- mlir/CMakeLists.txt | 2 ++ mlir/cmake/modules/AddMLIRPython.cmake | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/mlir/CMakeLists.txt b/mlir/CMakeLists.txt index a888ac243b044..9e786154a2b40 100644 --- a/mlir/CMakeLists.txt +++ b/mlir/CMakeLists.txt @@ -174,6 +174,8 @@ configure_file( # disable all package setup and control it themselves. #------------------------------------------------------------------------------- +set(MLIR_BINDINGS_PYTHON_NB_DOMAIN "mlir" + CACHE STRING "nanobind domain for MLIR python bindings.") set(MLIR_ENABLE_BINDINGS_PYTHON 0 CACHE BOOL "Enables building of Python bindings.") set(MLIR_DETECT_PYTHON_ENV_PRIME_SEARCH 1 CACHE BOOL diff --git a/mlir/cmake/modules/AddMLIRPython.cmake b/mlir/cmake/modules/AddMLIRPython.cmake index 0679db9cf93e1..815f65b106d94 100644 --- a/mlir/cmake/modules/AddMLIRPython.cmake +++ b/mlir/cmake/modules/AddMLIRPython.cmake @@ -667,7 +667,7 @@ function(add_mlir_python_extension libname extname) ) elseif(ARG_PYTHON_BINDINGS_LIBRARY STREQUAL "nanobind") nanobind_add_module(${libname} - NB_DOMAIN mlir + NB_DOMAIN ${MLIR_BINDINGS_PYTHON_NB_DOMAIN} FREE_THREADED ${ARG_SOURCES} )