[Mlir-commits] [mlir] [mlir][python] Fail fast when nanobind is missing for Python bindings (PR #174649)
Hideto Ueno
llvmlistbot at llvm.org
Tue Jan 6 13:04:34 PST 2026
https://github.com/uenoku created https://github.com/llvm/llvm-project/pull/174649
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.
>From 931dc7b89dca0cf1970b3bad7564b20a0a947503 Mon Sep 17 00:00:00 2001
From: Hideto Ueno <uenoku.tokotoko at gmail.com>
Date: Tue, 6 Jan 2026 13:00:28 -0800
Subject: [PATCH] [mlir][python] Fail fast when nanobind is missing for Python
bindings
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.
---
mlir/cmake/modules/MLIRDetectPythonEnv.cmake | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
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()
More information about the Mlir-commits
mailing list