[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:05:32 PDT 2025
https://github.com/PragmaTwice created https://github.com/llvm/llvm-project/pull/164661
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.
>From b089f833e53264effa861dc89d4900b507497b5f Mon Sep 17 00:00:00 2001
From: PragmaTwice <twice at apache.org>
Date: Thu, 23 Oct 2025 00:58:22 +0800
Subject: [PATCH] [MLIR][Python] Skip stubgen while any sanitizer is enabled
---
mlir/python/CMakeLists.txt | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
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}")
More information about the Mlir-commits
mailing list