@@ -99,63 +99,6 @@ function(declare_mlir_python_sources name)
99
99
endif ()
100
100
endfunction ()
101
101
102
- # Function: generate_type_stubs
103
- # Turns on automatic type stub generation (via nanobind's stubgen) for extension modules.
104
- # Arguments:
105
- # MODULE_NAME: The name of the extension module as specified in declare_mlir_python_extension.
106
- # DEPENDS_TARGET: The dso target corresponding to the extension module
107
- # (e.g., something like StandalonePythonModules.extension._standaloneDialectsNanobind.dso)
108
- # MLIR_DEPENDS_TARGET: The dso target corresponding to the main/core extension module
109
- # (e.g., something like StandalonePythonModules.extension._mlir.dso)
110
- # OUTPUT_DIR: The root output directory to emit the type stubs into.
111
- # Outputs:
112
- # NB_STUBGEN_CUSTOM_TARGET: The target corresponding to generation which other targets can depend on.
113
- function (generate_type_stubs MODULE_NAME DEPENDS_TARGET MLIR_DEPENDS_TARGET OUTPUT_DIR)
114
- cmake_parse_arguments (ARG
115
- ""
116
- ""
117
- "OUTPUTS"
118
- ${ARGN} )
119
- if (EXISTS ${nanobind_DIR} /../src/stubgen.py)
120
- set (NB_STUBGEN "${nanobind_DIR} /../src/stubgen.py" )
121
- elseif (EXISTS ${nanobind_DIR} /../stubgen.py)
122
- set (NB_STUBGEN "${nanobind_DIR} /../stubgen.py" )
123
- else ()
124
- message (FATAL_ERROR "generate_type_stubs(): could not locate 'stubgen.py'!" )
125
- endif ()
126
- file (REAL_PATH "${NB_STUBGEN} " NB_STUBGEN)
127
-
128
- set (_module "${MLIR_PYTHON_PACKAGE_PREFIX} ._mlir_libs.${MODULE_NAME} " )
129
- file (REAL_PATH "${MLIR_BINARY_DIR} /${MLIR_BINDINGS_PYTHON_INSTALL_PREFIX} /.." _import_path)
130
-
131
- set (NB_STUBGEN_CMD
132
- "${Python_EXECUTABLE} "
133
- "${NB_STUBGEN} "
134
- --module
135
- "${_module} "
136
- -i
137
- "${_import_path} "
138
- --recursive
139
- --include -private
140
- --output -dir
141
- "${OUTPUT_DIR} "
142
- --quiet )
143
-
144
- list (TRANSFORM ARG_OUTPUTS PREPEND "${OUTPUT_DIR} /" OUTPUT_VARIABLE _generated_type_stubs)
145
- add_custom_command (
146
- OUTPUT ${_generated_type_stubs}
147
- COMMAND ${NB_STUBGEN_CMD}
148
- WORKING_DIRECTORY "${CMAKE_CURRENT_FUNCTION_LIST_DIR} "
149
- DEPENDS
150
- "${MLIR_DEPENDS_TARGET} .extension._mlir.dso"
151
- "${MLIR_DEPENDS_TARGET} .sources.MLIRPythonSources.Core.Python"
152
- "${DEPENDS_TARGET} "
153
- )
154
- set (_name "MLIRPythonModuleStubs_${_module} " )
155
- add_custom_target ("${_name} " ALL DEPENDS ${_generated_type_stubs} )
156
- set (NB_STUBGEN_CUSTOM_TARGET "${_name} " PARENT_SCOPE)
157
- endfunction ()
158
-
159
102
# Function: declare_mlir_python_extension
160
103
# Declares a buildable python extension from C++ source files. The built
161
104
# module is considered a python source file and included as everything else.
@@ -172,12 +115,11 @@ endfunction()
172
115
# on. These will be collected for all extensions and put into an
173
116
# aggregate dylib that is linked against.
174
117
# PYTHON_BINDINGS_LIBRARY: Either pybind11 or nanobind.
175
- # GENERATE_TYPE_STUBS: List of generated type stubs expected from stubgen relative to _mlir_libs.
176
118
function (declare_mlir_python_extension name )
177
119
cmake_parse_arguments (ARG
178
120
""
179
121
"ROOT_DIR;MODULE_NAME;ADD_TO_PARENT;PYTHON_BINDINGS_LIBRARY"
180
- "SOURCES;PRIVATE_LINK_LIBS;EMBED_CAPI_LINK_LIBS;GENERATE_TYPE_STUBS "
122
+ "SOURCES;PRIVATE_LINK_LIBS;EMBED_CAPI_LINK_LIBS"
181
123
${ARGN} )
182
124
183
125
if (NOT ARG_ROOT_DIR)
@@ -193,13 +135,12 @@ function(declare_mlir_python_extension name)
193
135
set_target_properties (${name} PROPERTIES
194
136
# Yes: Leading-lowercase property names are load bearing and the recommended
195
137
# way to do this: https://gitlab.kitware.com/cmake/cmake/-/issues/19261
196
- EXPORT_PROPERTIES "mlir_python_SOURCES_TYPE;mlir_python_EXTENSION_MODULE_NAME;mlir_python_EMBED_CAPI_LINK_LIBS;mlir_python_DEPENDS;mlir_python_BINDINGS_LIBRARY;mlir_python_GENERATE_TYPE_STUBS "
138
+ EXPORT_PROPERTIES "mlir_python_SOURCES_TYPE;mlir_python_EXTENSION_MODULE_NAME;mlir_python_EMBED_CAPI_LINK_LIBS;mlir_python_DEPENDS;mlir_python_BINDINGS_LIBRARY"
197
139
mlir_python_SOURCES_TYPE extension
198
140
mlir_python_EXTENSION_MODULE_NAME "${ARG_MODULE_NAME} "
199
141
mlir_python_EMBED_CAPI_LINK_LIBS "${ARG_EMBED_CAPI_LINK_LIBS} "
200
142
mlir_python_DEPENDS ""
201
143
mlir_python_BINDINGS_LIBRARY "${ARG_PYTHON_BINDINGS_LIBRARY} "
202
- mlir_python_GENERATE_TYPE_STUBS "${ARG_GENERATE_TYPE_STUBS} "
203
144
)
204
145
205
146
# Set the interface source and link_libs properties of the target
@@ -302,32 +243,6 @@ function(add_mlir_python_modules name)
302
243
)
303
244
add_dependencies (${modules_target} ${_extension_target} )
304
245
mlir_python_setup_extension_rpath(${_extension_target} )
305
- get_target_property (_generate_type_stubs ${sources_target} mlir_python_GENERATE_TYPE_STUBS)
306
- if (_generate_type_stubs)
307
- generate_type_stubs(
308
- ${_module_name}
309
- ${_extension_target}
310
- ${name}
311
- "${CMAKE_CURRENT_BINARY_DIR} /_mlir_libs"
312
- OUTPUTS "${_generate_type_stubs} "
313
- )
314
- add_dependencies ("${modules_target} " "${NB_STUBGEN_CUSTOM_TARGET} " )
315
- set (_stubgen_target "${MLIR_PYTHON_PACKAGE_PREFIX} .${_module_name} _type_stub_gen" )
316
- declare_mlir_python_sources(
317
- ${_stubgen_target}
318
- ROOT_DIR "${CMAKE_CURRENT_BINARY_DIR} /_mlir_libs"
319
- ADD_TO_PARENT "${sources_target} "
320
- SOURCES "${_generate_type_stubs} "
321
- )
322
- set (_pure_sources_target "${modules_target} .sources.${sources_target} _type_stub_gen" )
323
- add_mlir_python_sources_target(${_pure_sources_target}
324
- INSTALL_COMPONENT ${modules_target}
325
- INSTALL_DIR "${ARG_INSTALL_PREFIX} /_mlir_libs"
326
- OUTPUT_DIRECTORY "${ARG_ROOT_PREFIX} /_mlir_libs"
327
- SOURCES_TARGETS ${_stubgen_target}
328
- )
329
- add_dependencies (${modules_target} ${_pure_sources_target} )
330
- endif ()
331
246
else ()
332
247
message (SEND_ERROR "Unrecognized source type '${_source_type} ' for python source target ${sources_target} " )
333
248
return ()
@@ -763,28 +678,26 @@ function(add_mlir_python_extension libname extname)
763
678
# the super project handle compile options as it wishes.
764
679
get_property (NB_LIBRARY_TARGET_NAME TARGET ${libname} PROPERTY LINK_LIBRARIES )
765
680
target_compile_options (${NB_LIBRARY_TARGET_NAME}
766
- PRIVATE
767
- -Wall -Wextra -Wpedantic
768
- -Wno-c++98-compat-extra-semi
769
- -Wno-cast-qual
770
- -Wno-covered-switch-default
771
- -Wno-deprecated-literal-operator
772
- -Wno-nested-anon-types
773
- -Wno-unused-parameter
774
- -Wno-zero-length -array
775
- ${eh_rtti_enable} )
681
+ PRIVATE
682
+ -Wall -Wextra -Wpedantic
683
+ -Wno-c++98-compat-extra-semi
684
+ -Wno-cast-qual
685
+ -Wno-covered-switch-default
686
+ -Wno-nested-anon-types
687
+ -Wno-unused-parameter
688
+ -Wno-zero-length -array
689
+ ${eh_rtti_enable} )
776
690
777
691
target_compile_options (${libname}
778
- PRIVATE
779
- -Wall -Wextra -Wpedantic
780
- -Wno-c++98-compat-extra-semi
781
- -Wno-cast-qual
782
- -Wno-covered-switch-default
783
- -Wno-deprecated-literal-operator
784
- -Wno-nested-anon-types
785
- -Wno-unused-parameter
786
- -Wno-zero-length -array
787
- ${eh_rtti_enable} )
692
+ PRIVATE
693
+ -Wall -Wextra -Wpedantic
694
+ -Wno-c++98-compat-extra-semi
695
+ -Wno-cast-qual
696
+ -Wno-covered-switch-default
697
+ -Wno-nested-anon-types
698
+ -Wno-unused-parameter
699
+ -Wno-zero-length -array
700
+ ${eh_rtti_enable} )
788
701
endif ()
789
702
790
703
if (APPLE )
0 commit comments