add_custom_target(MLIRBindingsPythonExtension)
################################################################################
-# Generate dialect-specific bindings.
-################################################################################
-
-add_mlir_dialect_python_bindings(MLIRBindingsPythonStandardOps
- StandardOps.td
- std)
-add_dependencies(MLIRBindingsPythonExtension MLIRBindingsPythonStandardOps)
-
-################################################################################
# Copy python source tree.
################################################################################
endforeach()
################################################################################
+# Generate dialect-specific bindings.
+################################################################################
+
+add_mlir_dialect_python_bindings(MLIRBindingsPythonStandardOps
+ StandardOps.td
+ std)
+add_dependencies(MLIRBindingsPythonSources MLIRBindingsPythonStandardOps)
+
+################################################################################
# Build core python extension
################################################################################
add_mlir_python_extension(MLIRCoreBindingsPythonExtension _mlir
"passmanager",
]
-# The _dlloader takes care of platform specific setup before we try to
-# load a shared library.
-from . import _dlloader
-_dlloader.preload_dependency("MLIRPublicAPI")
+# Packaged installs have a top-level _mlir_libs package with symbols:
+# load_extension(name): Loads a named extension module
+# preload_dependency(public_name): Loads a shared-library/DLL into the
+# namespace. TODO: Remove this in favor of a more robust mechanism.
+# Conditionally switch based on whether we are in a package context.
+try:
+ import _mlir_libs
+except ModuleNotFoundError:
+ # Assume that we are in-tree.
+ # The _dlloader takes care of platform specific setup before we try to
+ # load a shared library.
+ from ._dlloader import preload_dependency as _preload_dependency
+ def _load_extension(name):
+ import importlib
+ return importlib.import_module(name) # i.e. '_mlir' at the top level
+else:
+ # Packaged distribution.
+ _load_extension = _mlir_libs.load_extension
+ _preload_dependency = _mlir_libs.preload_dependency
+
+_preload_dependency("MLIRPublicAPI")
# Expose the corresponding C-Extension module with a well-known name at this
# top-level module. This allows relative imports like the following to
# function:
# from .. import _cext
# This reduces coupling, allowing embedding of the python sources into another
# project that can just vary based on this top-level loader module.
-import _mlir as _cext
+_cext = _load_extension("_mlir")
def _reexport_cext(cext_module_name, target_module_name):
"""Re-exports a named sub-module of the C-Extension into another module.