[Mlir-commits] [mlir] [mlir][Python] don't build libnanobind if module only has "pure" extensions (PR #175090)
Maksim Levental
llvmlistbot at llvm.org
Mon Jan 12 08:49:30 PST 2026
https://github.com/makslevental updated https://github.com/llvm/llvm-project/pull/175090
>From ddbdae79711b7ead2249ab7a3540ce153e6c1cc7 Mon Sep 17 00:00:00 2001
From: makslevental <maksim.levental at gmail.com>
Date: Thu, 8 Jan 2026 15:19:12 -0800
Subject: [PATCH 1/2] [mlir][Python] don't build libnanobind if module only has
"pure" extensions
---
mlir/cmake/modules/AddMLIRPython.cmake | 28 +++++++++++++++++++-------
1 file changed, 21 insertions(+), 7 deletions(-)
diff --git a/mlir/cmake/modules/AddMLIRPython.cmake b/mlir/cmake/modules/AddMLIRPython.cmake
index f4d078dfe7118..ba3f8de8512eb 100644
--- a/mlir/cmake/modules/AddMLIRPython.cmake
+++ b/mlir/cmake/modules/AddMLIRPython.cmake
@@ -393,13 +393,28 @@ function(add_mlir_python_modules name)
set(ARG_MLIR_BINDINGS_PYTHON_NB_DOMAIN "mlir")
endif()
+ # Collect up all the transitive extension targets.
+ _flatten_mlir_python_targets(_flat_targets ${ARG_DECLARED_SOURCES})
+
+ # Modules with only pure extensions shouldn't build libnanobind.
+ set(_needs_build_nanobind_lib OFF)
+ foreach(sources_target ${_flat_targets})
+ get_target_property(_source_type ${sources_target} mlir_python_SOURCES_TYPE)
+ if((_source_type STREQUAL "support") OR (_source_type STREQUAL "extension"))
+ set(_needs_build_nanobind_lib ON)
+ break()
+ endif()
+ endforeach()
+
# This call sets NB_LIBRARY_TARGET_NAME.
- build_nanobind_lib(
- INSTALL_COMPONENT ${name}
- INSTALL_DESTINATION "${ARG_INSTALL_PREFIX}/_mlir_libs"
- OUTPUT_DIRECTORY "${ARG_ROOT_PREFIX}/_mlir_libs"
- MLIR_BINDINGS_PYTHON_NB_DOMAIN ${ARG_MLIR_BINDINGS_PYTHON_NB_DOMAIN}
- )
+ if(_needs_build_nanobind_lib)
+ build_nanobind_lib(
+ INSTALL_COMPONENT ${name}
+ INSTALL_DESTINATION "${ARG_INSTALL_PREFIX}/_mlir_libs"
+ OUTPUT_DIRECTORY "${ARG_ROOT_PREFIX}/_mlir_libs"
+ MLIR_BINDINGS_PYTHON_NB_DOMAIN ${ARG_MLIR_BINDINGS_PYTHON_NB_DOMAIN}
+ )
+ endif()
# Helper to process an individual target.
function(_process_target modules_target sources_target support_libs)
@@ -442,7 +457,6 @@ function(add_mlir_python_modules name)
# Build the modules target.
add_custom_target(${name} ALL)
- _flatten_mlir_python_targets(_flat_targets ${ARG_DECLARED_SOURCES})
# Build all support libs first.
set(_mlir_python_support_libs)
>From 7a6430200fb9441fabe9091fbf22cd4f66b2bef0 Mon Sep 17 00:00:00 2001
From: Maksim Levental <maksim.levental at gmail.com>
Date: Mon, 12 Jan 2026 08:49:20 -0800
Subject: [PATCH 2/2] Update mlir/cmake/modules/AddMLIRPython.cmake
Co-authored-by: Rahul Kayaith <rkayaith at amd.com>
---
mlir/cmake/modules/AddMLIRPython.cmake | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlir/cmake/modules/AddMLIRPython.cmake b/mlir/cmake/modules/AddMLIRPython.cmake
index ba3f8de8512eb..acc85e5fa6b02 100644
--- a/mlir/cmake/modules/AddMLIRPython.cmake
+++ b/mlir/cmake/modules/AddMLIRPython.cmake
@@ -396,7 +396,7 @@ function(add_mlir_python_modules name)
# Collect up all the transitive extension targets.
_flatten_mlir_python_targets(_flat_targets ${ARG_DECLARED_SOURCES})
- # Modules with only pure extensions shouldn't build libnanobind.
+ # Modules with only pure python extensions shouldn't build libnanobind.
set(_needs_build_nanobind_lib OFF)
foreach(sources_target ${_flat_targets})
get_target_property(_source_type ${sources_target} mlir_python_SOURCES_TYPE)
More information about the Mlir-commits
mailing list