[Mlir-commits] [mlir] [mlir][python] Fail fast when nanobind is missing for Python bindings (PR #174649)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Jan 6 13:05:05 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Hideto Ueno (uenoku)

<details>
<summary>Changes</summary>

Remove problematic `return()` statements from mlir_configure_python_dev_packages macro and convert nanobind detection to FATAL_ERROR.

Using `return()` in a CMake macro is problematic because it returns from the calling scope, not the macro itself, causing the parent CMakeLists.txt to silently skip subsequent configuration steps. This leads to confusing build failures when Python bindings are enabled but nanobind is missing.

With this change, users get an immediate error with clear instructions to install nanobind or set nanobind_DIR, rather than silent configuration failures.

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


1 Files Affected:

- (modified) mlir/cmake/modules/MLIRDetectPythonEnv.cmake (+2-4) 


``````````diff
diff --git a/mlir/cmake/modules/MLIRDetectPythonEnv.cmake b/mlir/cmake/modules/MLIRDetectPythonEnv.cmake
index 098d12aedeb91..01dd7437cc8fc 100644
--- a/mlir/cmake/modules/MLIRDetectPythonEnv.cmake
+++ b/mlir/cmake/modules/MLIRDetectPythonEnv.cmake
@@ -60,8 +60,7 @@ macro(mlir_configure_python_dev_packages)
         OUTPUT_VARIABLE PACKAGE_DIR
         ERROR_QUIET)
       if(NOT STATUS EQUAL "0")
-        message(STATUS "not found (install via 'pip install nanobind' or set nanobind_DIR)")
-        return()
+        message(FATAL_ERROR "not found (install via 'pip install nanobind' or set nanobind_DIR)")
       endif()
       message(STATUS "found (${PACKAGE_DIR})")
       set(nanobind_DIR "${PACKAGE_DIR}")
@@ -73,8 +72,7 @@ macro(mlir_configure_python_dev_packages)
         OUTPUT_VARIABLE PACKAGE_DIR
         ERROR_QUIET)
       if(NOT STATUS EQUAL "0")
-        message(STATUS "not found (install via 'pip install nanobind' or set nanobind_DIR)")
-        return()
+        message(FATAL_ERROR "not found (install via 'pip install nanobind' or set nanobind_DIR)")
       endif()
       set(nanobind_INCLUDE_DIR "${PACKAGE_DIR}")
     endif()

``````````

</details>


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


More information about the Mlir-commits mailing list