Skip to content

[mlir][python] Fail fast when nanobind is missing for Python bindings - #174649

Merged
uenoku merged 1 commit into
llvm:mainfrom
uenoku:dev/hidetou/python-cmake
Jan 8, 2026
Merged

uenoku merged 1 commit into
llvm:mainfrom
uenoku:dev/hidetou/python-cmake

Conversation

@uenoku

@uenoku uenoku commented Jan 6, 2026

Copy link
Copy Markdown
Member

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.

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.
@uenoku
uenoku requested a review from makslevental January 6, 2026 21:04
@llvmbot llvmbot added the mlir label Jan 6, 2026
@llvmbot

llvmbot commented Jan 6, 2026

Copy link
Copy Markdown
Member

@llvm/pr-subscribers-mlir

Author: Hideto Ueno (uenoku)

Changes

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

@makslevental makslevental left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the right choice but let's see if anyone opposes (a couple of days) before we merge.

@makslevental

Copy link
Copy Markdown
Contributor

@uenoku cool feel free to merge whenever

@uenoku
uenoku merged commit 3c84812 into llvm:main Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants