[Mlir-commits] [mlir] [MLIR][Python] Skip stubgen while any sanitizer is enabled (PR #164661)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Oct 22 10:06:19 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Twice (PragmaTwice)
<details>
<summary>Changes</summary>
The intention of this PR is described [here](https://github.com/llvm/llvm-project/issues/164197#issuecomment-3432843709).
When sanitizers are enabled, some additional setup (such as preloading certain libraries) seems to be required for the stubgen step to work properly. In this case, I chose to simply skip the stubgen process, as supporting it would likely require some extra CMake logic, and type stubs don’t appear to be particularly necessary in this configuration.
---
Full diff: https://github.com/llvm/llvm-project/pull/164661.diff
1 Files Affected:
- (modified) mlir/python/CMakeLists.txt (+10-3)
``````````diff
diff --git a/mlir/python/CMakeLists.txt b/mlir/python/CMakeLists.txt
index e79b51ad72e2b..20ed3ab41a0b4 100644
--- a/mlir/python/CMakeLists.txt
+++ b/mlir/python/CMakeLists.txt
@@ -894,9 +894,16 @@ if(NOT LLVM_ENABLE_IDE)
)
endif()
+set(_mlir_python_stubgen_enabled ON)
# Stubgen doesn't work when cross-compiling (stubgen will run in the host interpreter and then fail
# to find the extension module for the host arch).
-if(NOT CMAKE_CROSSCOMPILING)
+# Note: Stubgen requires some extra handling to work properly when sanitizers are enabled,
+# so we skip running it in that case now.
+if(CMAKE_CROSSCOMPILING OR (NOT LLVM_USE_SANITIZER STREQUAL ""))
+ set(_mlir_python_stubgen_enabled OFF)
+endif()
+
+if(_mlir_python_stubgen_enabled)
# _mlir stubgen
# Note: All this needs to come before add_mlir_python_modules(MLIRPythonModules so that the install targets for the
# generated type stubs get created.
@@ -985,7 +992,7 @@ endif()
################################################################################
set(_declared_sources MLIRPythonSources MLIRPythonExtension.RegisterEverything)
-if(NOT CMAKE_CROSSCOMPILING)
+if(_mlir_python_stubgen_enabled)
list(APPEND _declared_sources MLIRPythonExtension.Core.type_stub_gen)
endif()
@@ -998,7 +1005,7 @@ add_mlir_python_modules(MLIRPythonModules
COMMON_CAPI_LINK_LIBS
MLIRPythonCAPI
)
-if(NOT CMAKE_CROSSCOMPILING)
+if(_mlir_python_stubgen_enabled)
add_dependencies(MLIRPythonModules "${_mlir_typestub_gen_target}")
if(MLIR_INCLUDE_TESTS)
add_dependencies(MLIRPythonModules "${_mlirPythonTestNanobind_typestub_gen_target}")
``````````
</details>
https://github.com/llvm/llvm-project/pull/164661
More information about the Mlir-commits
mailing list