Skip to content

Commit 00cc500

Browse files
PragmaTwiceLukacma
authored andcommitted
[MLIR][Python] Skip stubgen while any sanitizer is enabled (llvm#164661)
The intention of this PR is described llvm#164197 (comment) (and llvm#164197 (comment)). When sanitizers are enabled, some additional setup (such as preloading certain libraries) seems to be required for the stubgen step to work properly (llvm#164197 (comment)). 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.
1 parent b0b03e8 commit 00cc500

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

mlir/examples/standalone/python/CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,12 @@ add_mlir_python_common_capi_library(StandalonePythonCAPI
7474

7575
set(StandalonePythonModules_ROOT_PREFIX "${MLIR_BINARY_DIR}/${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX}")
7676

77-
if(NOT CMAKE_CROSSCOMPILING)
77+
set(_mlir_python_stubgen_enabled ON)
78+
if(CMAKE_CROSSCOMPILING OR (NOT LLVM_USE_SANITIZER STREQUAL ""))
79+
set(_mlir_python_stubgen_enabled OFF)
80+
endif()
81+
82+
if(_mlir_python_stubgen_enabled)
7883
# Everything here is very tightly coupled. See the ample descriptions at the bottom of
7984
# mlir/python/CMakeLists.txt.
8085

@@ -141,7 +146,7 @@ set(_declared_sources
141146
)
142147
# For an external projects build, the MLIRPythonExtension.Core.type_stub_gen
143148
# target already exists and can just be added to DECLARED_SOURCES.
144-
if(EXTERNAL_PROJECT_BUILD AND (NOT CMAKE_CROSSCOMPILING))
149+
if(EXTERNAL_PROJECT_BUILD AND _mlir_python_stubgen_enabled)
145150
list(APPEND _declared_sources MLIRPythonExtension.Core.type_stub_gen)
146151
endif()
147152

@@ -153,7 +158,7 @@ add_mlir_python_modules(StandalonePythonModules
153158
StandalonePythonCAPI
154159
)
155160

156-
if(NOT CMAKE_CROSSCOMPILING)
161+
if(_mlir_python_stubgen_enabled)
157162
if(NOT EXTERNAL_PROJECT_BUILD)
158163
add_dependencies(StandalonePythonModules "${_mlir_typestub_gen_target}")
159164
endif()

mlir/python/CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -894,9 +894,16 @@ if(NOT LLVM_ENABLE_IDE)
894894
)
895895
endif()
896896

897+
set(_mlir_python_stubgen_enabled ON)
897898
# Stubgen doesn't work when cross-compiling (stubgen will run in the host interpreter and then fail
898899
# to find the extension module for the host arch).
899-
if(NOT CMAKE_CROSSCOMPILING)
900+
# Note: Stubgen requires some extra handling to work properly when sanitizers are enabled,
901+
# so we skip running it in that case now.
902+
if(CMAKE_CROSSCOMPILING OR (NOT LLVM_USE_SANITIZER STREQUAL ""))
903+
set(_mlir_python_stubgen_enabled OFF)
904+
endif()
905+
906+
if(_mlir_python_stubgen_enabled)
900907
# _mlir stubgen
901908
# Note: All this needs to come before add_mlir_python_modules(MLIRPythonModules so that the install targets for the
902909
# generated type stubs get created.
@@ -985,7 +992,7 @@ endif()
985992
################################################################################
986993

987994
set(_declared_sources MLIRPythonSources MLIRPythonExtension.RegisterEverything)
988-
if(NOT CMAKE_CROSSCOMPILING)
995+
if(_mlir_python_stubgen_enabled)
989996
list(APPEND _declared_sources MLIRPythonExtension.Core.type_stub_gen)
990997
endif()
991998

@@ -998,7 +1005,7 @@ add_mlir_python_modules(MLIRPythonModules
9981005
COMMON_CAPI_LINK_LIBS
9991006
MLIRPythonCAPI
10001007
)
1001-
if(NOT CMAKE_CROSSCOMPILING)
1008+
if(_mlir_python_stubgen_enabled)
10021009
add_dependencies(MLIRPythonModules "${_mlir_typestub_gen_target}")
10031010
if(MLIR_INCLUDE_TESTS)
10041011
add_dependencies(MLIRPythonModules "${_mlirPythonTestNanobind_typestub_gen_target}")

0 commit comments

Comments
 (0)