[Mlir-commits] [mlir] 13b5e39 - [MLIR][Python] Skip stubgen while any sanitizer is enabled (#164661)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Oct 22 22:49:11 PDT 2025
Author: Twice
Date: 2025-10-23T13:49:07+08:00
New Revision: 13b5e396a007d119a65e0ba41b1f3604369376aa
URL: https://github.com/llvm/llvm-project/commit/13b5e396a007d119a65e0ba41b1f3604369376aa
DIFF: https://github.com/llvm/llvm-project/commit/13b5e396a007d119a65e0ba41b1f3604369376aa.diff
LOG: [MLIR][Python] Skip stubgen while any sanitizer is enabled (#164661)
The intention of this PR is described
https://github.com/llvm/llvm-project/issues/164197#issuecomment-3432843709
(and
https://github.com/llvm/llvm-project/issues/164197#issuecomment-3432935838).
When sanitizers are enabled, some additional setup (such as preloading
certain libraries) seems to be required for the stubgen step to work
properly
(https://github.com/llvm/llvm-project/issues/164197#issuecomment-3432924034).
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.
Added:
Modified:
mlir/examples/standalone/python/CMakeLists.txt
mlir/python/CMakeLists.txt
Removed:
################################################################################
diff --git a/mlir/examples/standalone/python/CMakeLists.txt b/mlir/examples/standalone/python/CMakeLists.txt
index 905c944939756..df19fa86067eb 100644
--- a/mlir/examples/standalone/python/CMakeLists.txt
+++ b/mlir/examples/standalone/python/CMakeLists.txt
@@ -74,7 +74,12 @@ add_mlir_python_common_capi_library(StandalonePythonCAPI
set(StandalonePythonModules_ROOT_PREFIX "${MLIR_BINARY_DIR}/${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX}")
-if(NOT CMAKE_CROSSCOMPILING)
+set(_mlir_python_stubgen_enabled ON)
+if(CMAKE_CROSSCOMPILING OR (NOT LLVM_USE_SANITIZER STREQUAL ""))
+ set(_mlir_python_stubgen_enabled OFF)
+endif()
+
+if(_mlir_python_stubgen_enabled)
# Everything here is very tightly coupled. See the ample descriptions at the bottom of
# mlir/python/CMakeLists.txt.
@@ -141,7 +146,7 @@ set(_declared_sources
)
# For an external projects build, the MLIRPythonExtension.Core.type_stub_gen
# target already exists and can just be added to DECLARED_SOURCES.
-if(EXTERNAL_PROJECT_BUILD AND (NOT CMAKE_CROSSCOMPILING))
+if(EXTERNAL_PROJECT_BUILD AND _mlir_python_stubgen_enabled)
list(APPEND _declared_sources MLIRPythonExtension.Core.type_stub_gen)
endif()
@@ -153,7 +158,7 @@ add_mlir_python_modules(StandalonePythonModules
StandalonePythonCAPI
)
-if(NOT CMAKE_CROSSCOMPILING)
+if(_mlir_python_stubgen_enabled)
if(NOT EXTERNAL_PROJECT_BUILD)
add_dependencies(StandalonePythonModules "${_mlir_typestub_gen_target}")
endif()
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