[Mlir-commits] [mlir] [mlir][python][NFC] Clean up nanobind compile options (PR #206559)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Jun 29 12:01:33 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Diego Caballero (dcaballe)

<details>
<summary>Changes</summary>

Follow-up to #<!-- -->204230.

Refactor nanobind warning suppression flags into `build_nanobind_lib`.
Drop duplicate RTTI and exception flags.

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


1 Files Affected:

- (modified) mlir/cmake/modules/AddMLIRPython.cmake (+34-20) 


``````````diff
diff --git a/mlir/cmake/modules/AddMLIRPython.cmake b/mlir/cmake/modules/AddMLIRPython.cmake
index 3a4a6cbe5c3c7..8e061efbaf089 100644
--- a/mlir/cmake/modules/AddMLIRPython.cmake
+++ b/mlir/cmake/modules/AddMLIRPython.cmake
@@ -329,6 +329,17 @@ function(_mlir_python_install_sources name source_root_dir destination)
   )
 endfunction()
 
+# Define exception handling and RTTI flags.
+function(_mlir_python_eh_rtti_flags out_var)
+  set(eh_rtti_enable)
+  if(MSVC)
+    set(eh_rtti_enable /EHsc /GR)
+  elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL)
+    set(eh_rtti_enable -frtti -fexceptions)
+  endif()
+  set(${out_var} "${eh_rtti_enable}" PARENT_SCOPE)
+endfunction()
+
 function(build_nanobind_lib)
   cmake_parse_arguments(ARG
     ""
@@ -360,6 +371,27 @@ function(build_nanobind_lib)
     PRIVATE
     NB_DOMAIN=${ARG_MLIR_BINDINGS_PYTHON_NB_DOMAIN}
   )
+
+  if(NOT MLIR_DISABLE_CONFIGURE_PYTHON_DEV_PACKAGES
+     AND (LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL))
+    # Avoid some warnings from upstream nanobind.
+    # If a superproject set MLIR_DISABLE_CONFIGURE_PYTHON_DEV_PACKAGES, let
+    # the super project handle compile options as it wishes.
+    _mlir_python_eh_rtti_flags(eh_rtti_enable)
+    target_compile_options(${NB_LIBRARY_TARGET_NAME}
+      PRIVATE
+        -Wno-c++98-compat-extra-semi
+        -Wno-cast-qual
+        -Wno-covered-switch-default
+        -Wno-deprecated-literal-operator
+        -Wno-nested-anon-types
+        -Wno-unused-parameter
+        -Wno-zero-length-array
+        -Wno-missing-field-initializers
+        ${eh_rtti_enable})
+  endif()
+
+  # Apply caller-provided extra options last so they have higher precedence.
   target_compile_options(${NB_LIBRARY_TARGET_NAME}
     PRIVATE
       ${ARG_EXTRA_COMPILE_OPTIONS}
@@ -960,12 +992,7 @@ function(add_mlir_python_extension libname extname nb_library_target_name)
 
   # The extension itself must be compiled with RTTI and exceptions enabled.
   # Also, some warning classes triggered by nanobind are disabled.
-  set(eh_rtti_enable)
-  if (MSVC)
-    set(eh_rtti_enable /EHsc /GR)
-  elseif(LLVM_COMPILER_IS_GCC_COMPATIBLE OR CLANG_CL)
-    set(eh_rtti_enable -frtti -fexceptions)
-  endif ()
+  _mlir_python_eh_rtti_flags(eh_rtti_enable)
 
   if(ARG__PRIVATE_SUPPORT_LIB)
     add_library(${libname} SHARED ${ARG_SOURCES})
@@ -1021,18 +1048,6 @@ function(add_mlir_python_extension libname extname nb_library_target_name)
     # Avoid some warnings from upstream nanobind.
     # If a superproject set MLIR_DISABLE_CONFIGURE_PYTHON_DEV_PACKAGES, let
     # the super project handle compile options as it wishes.
-    target_compile_options(${nb_library_target_name}
-      PRIVATE
-        -Wno-c++98-compat-extra-semi
-        -Wno-cast-qual
-        -Wno-covered-switch-default
-        -Wno-deprecated-literal-operator
-        -Wno-nested-anon-types
-        -Wno-unused-parameter
-        -Wno-zero-length-array
-        -Wno-missing-field-initializers
-        ${eh_rtti_enable})
-
     target_compile_options(${libname}
       PRIVATE
         -Wno-c++98-compat-extra-semi
@@ -1042,8 +1057,7 @@ function(add_mlir_python_extension libname extname nb_library_target_name)
         -Wno-nested-anon-types
         -Wno-unused-parameter
         -Wno-zero-length-array
-        -Wno-missing-field-initializers
-        ${eh_rtti_enable})
+        -Wno-missing-field-initializers)
   endif()
 
   if(APPLE)

``````````

</details>


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


More information about the Mlir-commits mailing list