Skip to content

Commit 497989f

Browse files
committed
Update AddMLIRPython.cmake
1 parent debc3aa commit 497989f

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

mlir/cmake/modules/AddMLIRPython.cmake

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function(declare_mlir_python_sources name)
9999
endif()
100100
endfunction()
101101

102-
function(generate_type_stubs module_name depends_target output_dir)
102+
function(generate_type_stubs module_name depends_target mlir_depends_target output_dir)
103103
if(EXISTS ${nanobind_DIR}/../src/stubgen.py)
104104
set(NB_STUBGEN "${nanobind_DIR}/../src/stubgen.py")
105105
elseif(EXISTS ${nanobind_DIR}/../stubgen.py)
@@ -108,11 +108,12 @@ function(generate_type_stubs module_name depends_target output_dir)
108108
message(FATAL_ERROR "generate_type_stubs(): could not locate 'stubgen.py'!")
109109
endif()
110110

111+
set(_module "${MLIR_PYTHON_PACKAGE_PREFIX}._mlir_libs.${module_name}")
111112
set(NB_STUBGEN_CMD
112113
"${Python_EXECUTABLE}"
113114
"${NB_STUBGEN}"
114115
--module
115-
"${MLIR_PYTHON_PACKAGE_PREFIX}._mlir_libs.${module_name}"
116+
"${_module}"
116117
-i
117118
"${MLIR_BINARY_DIR}/${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX}/.."
118119
--recursive
@@ -125,8 +126,8 @@ function(generate_type_stubs module_name depends_target output_dir)
125126
OUTPUT ${NB_STUBGEN_OUTPUT}
126127
COMMAND ${NB_STUBGEN_CMD}
127128
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
128-
DEPENDS ${depends_target})
129-
set(_name "MLIRPythonModuleStubs_${module_name}")
129+
DEPENDS "${mlir_depends_target}" "${depends_target}")
130+
set(_name "MLIRPythonModuleStubs_${_module}")
130131
add_custom_target("${_name}" ALL DEPENDS ${NB_STUBGEN_OUTPUT})
131132
set(NB_STUBGEN_CUSTOM_TARGET "${_name}" PARENT_SCOPE)
132133
endfunction()
@@ -278,9 +279,11 @@ function(add_mlir_python_modules name)
278279
generate_type_stubs(
279280
${_module_name}
280281
${_extension_target}
282+
"${modules_target}.extension._mlir.dso"
281283
"${CMAKE_CURRENT_SOURCE_DIR}/mlir/_mlir_libs/_mlir"
282284
)
283-
declare_mlir_python_sources("_${_module_name}_type_stub_gen"
285+
declare_mlir_python_sources(
286+
"${MLIR_PYTHON_PACKAGE_PREFIX}.${_module_name}_type_stub_gen"
284287
ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir"
285288
ADD_TO_PARENT "${sources_target}"
286289
SOURCES_GLOB "_mlir_libs/${_module_name}/**/*.pyi"

mlir/examples/standalone/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ add_subdirectory(include)
5252
add_subdirectory(lib)
5353
if(MLIR_ENABLE_BINDINGS_PYTHON)
5454
message(STATUS "Enabling Python API")
55+
set(MLIR_PYTHON_PACKAGE_PREFIX "mlir_standalone" CACHE STRING "" FORCE)
56+
set(MLIR_BINDINGS_PYTHON_INSTALL_PREFIX "python_packages/standalone/mlir_standalone" CACHE STRING "" FORCE)
5557
add_subdirectory(python)
5658
endif()
5759
add_subdirectory(test)

mlir/examples/standalone/python/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ declare_mlir_python_extension(StandalonePythonSources.NanobindExtension
4848

4949
add_mlir_python_common_capi_library(StandalonePythonCAPI
5050
INSTALL_COMPONENT StandalonePythonModules
51-
INSTALL_DESTINATION python_packages/standalone/mlir_standalone/_mlir_libs
52-
OUTPUT_DIRECTORY "${MLIR_BINARY_DIR}/python_packages/standalone/mlir_standalone/_mlir_libs"
51+
INSTALL_DESTINATION "${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX}/_mlir_libs"
52+
OUTPUT_DIRECTORY "${MLIR_BINARY_DIR}/${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX}/_mlir_libs"
5353
RELATIVE_INSTALL_ROOT "../../../.."
5454
DECLARED_SOURCES
5555
StandalonePythonSources
@@ -64,14 +64,14 @@ add_mlir_python_common_capi_library(StandalonePythonCAPI
6464
################################################################################
6565

6666
add_mlir_python_modules(StandalonePythonModules
67-
ROOT_PREFIX "${MLIR_BINARY_DIR}/python_packages/standalone/mlir_standalone"
68-
INSTALL_PREFIX "python_packages/standalone/mlir_standalone"
67+
ROOT_PREFIX "${MLIR_BINARY_DIR}/${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX}"
68+
INSTALL_PREFIX "${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX}"
6969
DECLARED_SOURCES
7070
StandalonePythonSources
7171
# TODO: Remove this in favor of showing fine grained registration once
7272
# available.
7373
MLIRPythonExtension.RegisterEverything
74-
MLIRPythonSources
74+
MLIRPythonSources.Core
7575
COMMON_CAPI_LINK_LIBS
7676
StandalonePythonCAPI
7777
)

0 commit comments

Comments
 (0)