diff --git a/mlir/cmake/modules/AddMLIRPython.cmake b/mlir/cmake/modules/AddMLIRPython.cmake --- a/mlir/cmake/modules/AddMLIRPython.cmake +++ b/mlir/cmake/modules/AddMLIRPython.cmake @@ -35,6 +35,7 @@ if(NOT ARG_ROOT_DIR) set(ARG_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") endif() + set(_install_destination "src/python/${name}") # Process the glob. set(_glob_sources) @@ -50,21 +51,44 @@ # We create a custom target to carry properties and dependencies for # generated sources. - add_custom_target(${name}) + add_library(${name} INTERFACE) set(_file_depends "${ARG_SOURCES}") list(TRANSFORM _file_depends PREPEND "${ARG_ROOT_DIR}/") set_target_properties(${name} PROPERTIES - PYTHON_SOURCES_TYPE pure - PYTHON_ROOT_DIR "${ARG_ROOT_DIR}" - PYTHON_DEST_PREFIX "${ARG_DEST_PREFIX}" - PYTHON_SOURCES "${ARG_SOURCES}" - PYTHON_FILE_DEPENDS "${_file_depends}" - PYTHON_DEPENDS "" + # Yes: Leading-lowercase property names are load bearing and the recommended + # way to do this: https://gitlab.kitware.com/cmake/cmake/-/issues/19261 + # Note that ROOT_DIR and FILE_DEPENDS are not exported because they are + # only relevant to in-tree uses. + EXPORT_PROPERTIES "mlir_python_SOURCES_TYPE;mlir_python_DEST_PREFIX;mlir_python_DEST_PREFIX;mlir_python_SOURCES;mlir_python_DEPENDS" + mlir_python_SOURCES_TYPE pure + mlir_python_ROOT_DIR "${ARG_ROOT_DIR}" + mlir_python_DEST_PREFIX "${ARG_DEST_PREFIX}" + mlir_python_SOURCES "${ARG_SOURCES}" + mlir_python_FILE_DEPENDS "${_file_depends}" + mlir_python_DEPENDS "" + ) + # Note that an "include" directory has no meaning to such faux targets, + # but it is a CMake supported way to specify a directory search list in a + # way that works both in-tree and out. It has some super powers which are + # not possible to emulate with custom properties (because of the prohibition + # on using generator expressions in exported custom properties and the + # special dispensation for $). + target_include_directories(${name} INTERFACE + "$" + "$" ) # Add to parent. if(ARG_ADD_TO_PARENT) - set_property(TARGET ${ARG_ADD_TO_PARENT} APPEND PROPERTY PYTHON_DEPENDS ${name}) + set_property(TARGET ${ARG_ADD_TO_PARENT} APPEND PROPERTY mlir_python_DEPENDS ${name}) + endif() + + # Install. + if(NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + _mlir_python_install_sources( + ${name} "${ARG_ROOT_DIR}" "${_install_destination}" + ${ARG_SOURCES} + ) endif() endfunction() @@ -72,6 +96,8 @@ # Declares a buildable python extension from C++ source files. The built # module is considered a python source file and included as everything else. # Arguments: +# ROOT_DIR: Root directory where sources are interpreted relative to. +# Defaults to CMAKE_CURRENT_SOURCE_DIR. # MODULE_NAME: Local import name of the module (i.e. "_mlir"). # ADD_TO_PARENT: Same as for declare_mlir_python_sources. # SOURCES: C++ sources making up the module. @@ -84,27 +110,77 @@ function(declare_mlir_python_extension name) cmake_parse_arguments(ARG "" - "MODULE_NAME;ADD_TO_PARENT" + "ROOT_DIR;MODULE_NAME;ADD_TO_PARENT" "SOURCES;PRIVATE_LINK_LIBS;EMBED_CAPI_LINK_LIBS" ${ARGN}) - add_custom_target(${name}) + if(NOT ARG_ROOT_DIR) + set(ARG_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") + endif() + set(_install_destination "src/python/${name}") + + add_library(${name} INTERFACE) set_target_properties(${name} PROPERTIES - PYTHON_SOURCES_TYPE extension - PYTHON_EXTENSION_MODULE_NAME "${ARG_MODULE_NAME}" - PYTHON_CPP_SOURCES "${ARG_SOURCES}" - PYTHON_PRIVATE_LINK_LIBS "${ARG_PRIVATE_LINK_LIBS}" - PYTHON_EMBED_CAPI_LINK_LIBS "${ARG_EMBED_CAPI_LINK_LIBS}" - PYTHON_FILE_DEPENDS "" - PYTHON_DEPENDS "" + # Yes: Leading-lowercase property names are load bearing and the recommended + # way to do this: https://gitlab.kitware.com/cmake/cmake/-/issues/19261 + # Note that ROOT_DIR and FILE_DEPENDS are not exported because they are + # only relevant to in-tree uses. + EXPORT_PROPERTIES "mlir_python_SOURCES_TYPE;mlir_python_EXTENSION_MODULE_NAME;mlir_python_CPP_SOURCES;mlir_python_PRIVATE_LINK_LIBS;mlir_python_EMBED_CAPI_LINK_LIBS;mlir_python_DEPENDS" + mlir_python_SOURCES_TYPE extension + mlir_python_ROOT_DIR "${ARG_ROOT_DIR}" + mlir_python_EXTENSION_MODULE_NAME "${ARG_MODULE_NAME}" + mlir_python_CPP_SOURCES "${ARG_SOURCES}" + mlir_python_PRIVATE_LINK_LIBS "${ARG_PRIVATE_LINK_LIBS}" + mlir_python_EMBED_CAPI_LINK_LIBS "${ARG_EMBED_CAPI_LINK_LIBS}" + mlir_python_FILE_DEPENDS "" + mlir_python_DEPENDS "" + ) + # Note that an "include" directory has no meaning to such faux targets, + # but it is a CMake supported way to specify an install-prefix relative + # directory. It has some super powers which are not possible to emulate + # with custom properties (because of the prohibition on using generator + # expressions in exported custom properties and the special dispensation + # for $ and $). On imported targets, + # this is used as a single value, not as a list, so it must only have one + # item in it. + target_include_directories(${name} INTERFACE + "$" ) # Add to parent. if(ARG_ADD_TO_PARENT) - set_property(TARGET ${ARG_ADD_TO_PARENT} APPEND PROPERTY PYTHON_DEPENDS ${name}) + set_property(TARGET ${ARG_ADD_TO_PARENT} APPEND PROPERTY mlir_python_DEPENDS ${name}) + endif() + + # Install. + if(NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + _mlir_python_install_sources( + ${name} "${ARG_ROOT_DIR}" "src/python/${name}" + ${ARG_SOURCES} + ) endif() endfunction() +function(_mlir_python_install_sources name source_root_dir destination) + foreach(source_relative_path ${ARGN}) + # Transform "a/b/c.py" -> "${install_prefix}/a/b" for installation. + get_filename_component( + dest_relative_path "${source_relative_path}" DIRECTORY + BASE_DIR "${source_root_dir}" + ) + install( + FILES "${source_root_dir}/${source_relative_path}" + DESTINATION "${destination}/${dest_relative_path}" + COMPONENT "${name}" + ) + endforeach() + get_target_export_arg(${name} MLIR export_to_mlirtargets UMBRELLA mlir-libraries) + install(TARGETS ${name} + COMPONENT ${name} + ${export_to_mlirtargets} + ) +endfunction() + # Function: add_mlir_python_modules # Adds python modules to a project, building them from a list of declared # source groupings (see declare_mlir_python_sources and @@ -128,12 +204,26 @@ ${ARGN}) # Helper to process an individual target. function(_process_target modules_target sources_target) - get_target_property(_source_type ${sources_target} PYTHON_SOURCES_TYPE) + get_target_property(_source_type ${sources_target} mlir_python_SOURCES_TYPE) + + # The root directory differs based on whether it is IMPORTED (installed + # dep). + get_target_property(_is_imported ${sources_target} IMPORTED) + if(NOT _is_imported) + # In-tree. + get_target_property(_python_root_dir ${sources_target} mlir_python_ROOT_DIR) + else() + # Imported. + # Note: We only populate a single directory in + # INTERFACE_INCLUDE_DIRECTORIES, so we can get away with just using it + # as a single value. + get_target_property(_python_root_dir ${sources_target} INTERFACE_INCLUDE_DIRECTORIES) + endif() + if(_source_type STREQUAL "pure") # Pure python sources to link into the tree. - get_target_property(_python_root_dir ${sources_target} PYTHON_ROOT_DIR) - get_target_property(_python_sources ${sources_target} PYTHON_SOURCES) - get_target_property(_specified_dest_prefix ${sources_target} PYTHON_DEST_PREFIX) + get_target_property(_python_sources ${sources_target} mlir_python_SOURCES) + get_target_property(_specified_dest_prefix ${sources_target} mlir_python_DEST_PREFIX) foreach(_source_relative_path ${_python_sources}) set(_dest_relative_path "${_source_relative_path}") if(_specified_dest_prefix) @@ -162,9 +252,11 @@ endforeach() elseif(_source_type STREQUAL "extension") # Native CPP extension. - get_target_property(_module_name ${sources_target} PYTHON_EXTENSION_MODULE_NAME) - get_target_property(_cpp_sources ${sources_target} PYTHON_CPP_SOURCES) - get_target_property(_private_link_libs ${sources_target} PYTHON_PRIVATE_LINK_LIBS) + get_target_property(_module_name ${sources_target} mlir_python_EXTENSION_MODULE_NAME) + get_target_property(_cpp_sources ${sources_target} mlir_python_CPP_SOURCES) + get_target_property(_private_link_libs ${sources_target} mlir_python_PRIVATE_LINK_LIBS) + # Transform relative source to based on root dir. + list(TRANSFORM _cpp_sources PREPEND "${_python_root_dir}/") set(_extension_target "${name}.extension.${_module_name}.dso") add_mlir_python_extension(${_extension_target} "${_module_name}" INSTALL_COMPONENT ${modules_target} @@ -187,8 +279,10 @@ # Collect dependencies. set(_depends) foreach(sources_target ${_flat_targets}) - get_target_property(_local_depends ${sources_target} PYTHON_FILE_DEPENDS) - list(APPEND _depends ${_local_depends}) + get_target_property(_local_depends ${sources_target} mlir_python_FILE_DEPENDS) + if(_local_depends) + list(APPEND _depends ${_local_depends}) + endif() endforeach() # Build the modules target. @@ -334,7 +428,7 @@ set(_embed_libs ${ARG_EMBED_LIBS}) _flatten_mlir_python_targets(_all_source_targets ${ARG_DECLARED_SOURCES}) foreach(t ${_all_source_targets}) - get_target_property(_local_embed_libs ${t} PYTHON_EMBED_CAPI_LINK_LIBS) + get_target_property(_local_embed_libs ${t} mlir_python_EMBED_CAPI_LINK_LIBS) if(_local_embed_libs) list(APPEND _embed_libs ${_local_embed_libs}) endif() @@ -372,8 +466,8 @@ function(_flatten_mlir_python_targets output_var) set(_flattened) foreach(t ${ARGN}) - get_target_property(_source_type ${t} PYTHON_SOURCES_TYPE) - get_target_property(_depends ${t} PYTHON_DEPENDS) + get_target_property(_source_type ${t} mlir_python_SOURCES_TYPE) + get_target_property(_depends ${t} mlir_python_DEPENDS) if(_source_type) list(APPEND _flattened "${t}") if(_depends) @@ -402,62 +496,19 @@ message(FATAL_ERROR " Missing SOURCES argument to add_mlir_python_extension(${libname}, ...") endif() - # Build-time RPath layouts require to be a directory one up from the - # binary root. - # TODO: Don't reference the LLVM_BINARY_DIR here: the invariant is that - # the output directory must be at the same level of the lib directory - # where libMLIR.so is installed. This is presently not optimal from a - # project separation perspective and a discussion on how to better - # segment MLIR libraries needs to happen. - # TODO: Remove this when downstreams are moved off of it. - if(NOT ARG_OUTPUT_DIRECTORY) - set(ARG_OUTPUT_DIRECTORY ${LLVM_BINARY_DIR}/python) - endif() - - # Normally on unix-like platforms, extensions are built as "MODULE" libraries - # and do not explicitly link to the python shared object. This allows for - # some greater deployment flexibility since the extension will bind to - # symbols in the python interpreter on load. However, it also keeps the - # linker from erroring on undefined symbols, leaving this to (usually obtuse) - # runtime errors. Building in "SHARED" mode with an explicit link to the - # python libraries allows us to build with the expectation of no undefined - # symbols, which is better for development. Note that not all python - # configurations provide build-time libraries to link against, in which - # case, we fall back to MODULE linking. - if(Python3_LIBRARIES STREQUAL "" OR NOT MLIR_BINDINGS_PYTHON_LOCK_VERSION) - set(PYEXT_LINK_MODE MODULE) - set(PYEXT_LIBADD) - else() - set(PYEXT_LINK_MODE SHARED) - set(PYEXT_LIBADD ${Python3_LIBRARIES}) - endif() - # The actual extension library produces a shared-object or DLL and has # sources that must be compiled in accordance with pybind11 needs (RTTI and # exceptions). - add_library(${libname} - ${PYEXT_LINK_MODE} + pybind11_add_module(${libname} ${ARG_SOURCES} ) - target_include_directories(${libname} PRIVATE - "${Python3_INCLUDE_DIRS}" - "${pybind11_INCLUDE_DIR}" - ) - - target_link_directories(${libname} PRIVATE - "${Python3_LIBRARY_DIRS}" - ) - # The extension itself must be compiled with RTTI and exceptions enabled. # Also, some warning classes triggered by pybind11 are disabled. target_compile_options(${libname} PRIVATE $<$,$,$>: # Enable RTTI and exceptions. -frtti -fexceptions - # Noisy pybind warnings - -Wno-unused-value - -Wno-covered-switch-default > $<$: # Enable RTTI and exceptions. @@ -469,8 +520,6 @@ ${libname} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${ARG_OUTPUT_DIRECTORY} OUTPUT_NAME "${extname}" - PREFIX "${PYTHON_MODULE_PREFIX}" - SUFFIX "${PYTHON_MODULE_SUFFIX}${PYTHON_MODULE_EXTENSION}" NO_SONAME ON ) @@ -484,13 +533,6 @@ ) endif() - # pybind11 requires binding code to be compiled with -fvisibility=hidden - # For static linkage, better code can be generated if the entire project - # compiles that way, but that is not enforced here. Instead, include a linker - # script that explicitly hides anything but the PyInit_* symbols, allowing gc - # to take place. - set_target_properties(${libname} PROPERTIES CXX_VISIBILITY_PRESET "hidden") - # Python extensions depends *only* on the public API and LLVMSupport unless # if further dependencies are added explicitly. target_link_libraries(${libname} diff --git a/mlir/examples/standalone/CMakeLists.txt b/mlir/examples/standalone/CMakeLists.txt --- a/mlir/examples/standalone/CMakeLists.txt +++ b/mlir/examples/standalone/CMakeLists.txt @@ -20,6 +20,14 @@ include(AddLLVM) include(AddMLIR) include(HandleLLVMOptions) +include(MLIRDetectPythonEnv) + +# TODO: Provide a more common way to configure Python deps. +if(TARGET MLIRPythonSources) + find_package(Python3 COMPONENTS Interpreter Development.Module) + mlir_detect_pybind11_install() + find_package(pybind11 2.6 CONFIG REQUIRED) +endif() include_directories(${LLVM_INCLUDE_DIRS}) include_directories(${MLIR_INCLUDE_DIRS}) @@ -30,6 +38,10 @@ add_subdirectory(include) add_subdirectory(lib) +if(TARGET MLIRPythonSources) + message(STATUS "Enabling Python API") + add_subdirectory(python) +endif() add_subdirectory(test) add_subdirectory(standalone-opt) add_subdirectory(standalone-translate) diff --git a/mlir/examples/standalone/include/Standalone/StandaloneOps.td b/mlir/examples/standalone/include/Standalone/StandaloneOps.td --- a/mlir/examples/standalone/include/Standalone/StandaloneOps.td +++ b/mlir/examples/standalone/include/Standalone/StandaloneOps.td @@ -9,7 +9,7 @@ #ifndef STANDALONE_OPS #define STANDALONE_OPS -include "StandaloneDialect.td" +include "Standalone/StandaloneDialect.td" include "mlir/Interfaces/SideEffectInterfaces.td" def Standalone_FooOp : Standalone_Op<"foo", [NoSideEffect, diff --git a/mlir/examples/standalone/python/CMakeLists.txt b/mlir/examples/standalone/python/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/mlir/examples/standalone/python/CMakeLists.txt @@ -0,0 +1,58 @@ +include(AddMLIRPython) + +# Specifies that all MLIR packages are co-located under the `mlir_standalone` +# top level package (the API has been embedded in a relocatable way). +# TODO: Add an upstream cmake param for this vs having a global here. +add_compile_definitions("MLIR_PYTHON_PACKAGE_PREFIX=mlir_standalone.") + + +################################################################################ +# Sources +################################################################################ + +declare_mlir_python_sources(StandalonePythonSources) + +declare_mlir_dialect_python_bindings( + ADD_TO_PARENT StandalonePythonSources + ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/mlir_standalone" + TD_FILE dialects/StandaloneOps.td + SOURCES + dialects/standalone.py + DIALECT_NAME standalone) + +declare_mlir_python_extension(StandalonePythonSources.Extension + MODULE_NAME _standaloneDialects + ADD_TO_PARENT StandalonePythonSources + SOURCES + StandaloneExtension.cpp + EMBED_CAPI_LINK_LIBS + StandaloneCAPI +) + +################################################################################ +# Common CAPI +################################################################################ + +add_mlir_python_common_capi_library(StandalonePythonCAPI + INSTALL_COMPONENT StandalonePythonModules + INSTALL_DESTINATION python_packages/standalone/mlir_standalone/_mlir_libs + OUTPUT_DIRECTORY "${MLIR_BINARY_DIR}/python_packages/standalone/mlir_standalone/_mlir_libs" + RELATIVE_INSTALL_ROOT "../../../.." + DECLARED_SOURCES + StandalonePythonSources + MLIRPythonSources.Core +) + +################################################################################ +# Instantiation of all Python modules +################################################################################ + +add_mlir_python_modules(StandalonePythonModules + ROOT_PREFIX "${MLIR_BINARY_DIR}/python_packages/standalone/mlir_standalone" + INSTALL_PREFIX "python_packages/standalone/mlir_standalone" + DECLARED_SOURCES + StandalonePythonSources + MLIRPythonSources + COMMON_CAPI_LINK_LIBS + StandalonePythonCAPI + ) diff --git a/mlir/examples/standalone/python/StandaloneExtension.cpp b/mlir/examples/standalone/python/StandaloneExtension.cpp new file mode 100644 --- /dev/null +++ b/mlir/examples/standalone/python/StandaloneExtension.cpp @@ -0,0 +1,31 @@ +//===- StandaloneExtension.cpp - Extension module -------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "Standalone-c/Dialects.h" +#include "mlir/Bindings/Python/PybindAdaptors.h" + +namespace py = pybind11; +using namespace mlir::python::adaptors; + +PYBIND11_MODULE(_standaloneDialects, m) { + //===--------------------------------------------------------------------===// + // standalone dialect + //===--------------------------------------------------------------------===// + auto standalone_m = m.def_submodule("standalone"); + + standalone_m.def( + "register_dialect", + [](MlirContext context, bool load) { + MlirDialectHandle handle = mlirGetDialectHandle__standalone__(); + mlirDialectHandleRegisterDialect(handle, context); + if (load) { + mlirDialectHandleLoadDialect(handle, context); + } + }, + py::arg("context") = py::none(), py::arg("load") = true); +} diff --git a/mlir/examples/standalone/python/mlir_standalone/dialects/StandaloneOps.td b/mlir/examples/standalone/python/mlir_standalone/dialects/StandaloneOps.td new file mode 100644 --- /dev/null +++ b/mlir/examples/standalone/python/mlir_standalone/dialects/StandaloneOps.td @@ -0,0 +1,15 @@ +//===-- StandaloneOps.td - Python bindings for standalone --*- tablegen -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===---------------------------------------------------------------------===// + +#ifndef PYTHON_BINDINGS_STANDALONE_OPS +#define PYTHON_BINDINGS_STANDALONE_OPS + +include "mlir/Bindings/Python/Attributes.td" +include "Standalone/StandaloneOps.td" + +#endif diff --git a/mlir/examples/standalone/python/mlir_standalone/dialects/standalone.py b/mlir/examples/standalone/python/mlir_standalone/dialects/standalone.py new file mode 100644 --- /dev/null +++ b/mlir/examples/standalone/python/mlir_standalone/dialects/standalone.py @@ -0,0 +1,6 @@ +# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +from ._standalone_ops_gen import * +from .._mlir_libs._standaloneDialects.standalone import * diff --git a/mlir/examples/standalone/test/lit.cfg.py b/mlir/examples/standalone/test/lit.cfg.py --- a/mlir/examples/standalone/test/lit.cfg.py +++ b/mlir/examples/standalone/test/lit.cfg.py @@ -56,7 +56,12 @@ tools = [ 'standalone-capi-test', 'standalone-opt', - 'standalone-translate' + 'standalone-translate', + ToolSubst('%PYTHON', config.python_executable, unresolved='ignore'), ] llvm_config.add_tool_substitutions(tools, tool_dirs) + +llvm_config.with_environment('PYTHONPATH', [ + os.path.join(config.mlir_binary_dir, 'python_packages', 'standalone'), +], append_path=True) diff --git a/mlir/examples/standalone/test/lit.site.cfg.py.in b/mlir/examples/standalone/test/lit.site.cfg.py.in --- a/mlir/examples/standalone/test/lit.site.cfg.py.in +++ b/mlir/examples/standalone/test/lit.site.cfg.py.in @@ -12,7 +12,8 @@ config.llvm_shlib_ext = "@SHLIBEXT@" config.llvm_exe_ext = "@EXEEXT@" config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@" -config.python_executable = "@PYTHON_EXECUTABLE@" +config.mlir_binary_dir = "@MLIR_BINARY_DIR@" +config.python_executable = "@Python3_EXECUTABLE@" config.gold_executable = "@GOLD_EXECUTABLE@" config.ld64_executable = "@LD64_EXECUTABLE@" config.enable_shared = @ENABLE_SHARED@ diff --git a/mlir/examples/standalone/test/python/lit.local.cfg b/mlir/examples/standalone/test/python/lit.local.cfg new file mode 100644 --- /dev/null +++ b/mlir/examples/standalone/test/python/lit.local.cfg @@ -0,0 +1 @@ +config.suffixes.add('.py') diff --git a/mlir/examples/standalone/test/python/smoketest.py b/mlir/examples/standalone/test/python/smoketest.py new file mode 100644 --- /dev/null +++ b/mlir/examples/standalone/test/python/smoketest.py @@ -0,0 +1,17 @@ +# RUN: %PYTHON %s | FileCheck %s + +from mlir_standalone.ir import * +from mlir_standalone.dialects import ( + builtin as builtin_d, + standalone as standalone_d +) + +with Context(): + standalone_d.register_dialect() + module = Module.parse(""" + %0 = constant 2 : i32 + %1 = standalone.foo %0 : i32 + """) + # CHECK: %[[C:.*]] = constant 2 : i32 + # CHECK: standalone.foo %[[C]] : i32 + print(str(module)) diff --git a/mlir/python/CMakeLists.txt b/mlir/python/CMakeLists.txt --- a/mlir/python/CMakeLists.txt +++ b/mlir/python/CMakeLists.txt @@ -174,17 +174,25 @@ declare_mlir_python_extension(MLIRPythonExtension.Core MODULE_NAME _mlir ADD_TO_PARENT MLIRPythonSources.Core + ROOT_DIR "${PYTHON_SOURCE_DIR}" SOURCES - ${PYTHON_SOURCE_DIR}/DialectLinalg.cpp # TODO: Break this out. - ${PYTHON_SOURCE_DIR}/DialectSparseTensor.cpp # TODO: Break this out. - ${PYTHON_SOURCE_DIR}/MainModule.cpp - ${PYTHON_SOURCE_DIR}/IRAffine.cpp - ${PYTHON_SOURCE_DIR}/IRAttributes.cpp - ${PYTHON_SOURCE_DIR}/IRCore.cpp - ${PYTHON_SOURCE_DIR}/IRModule.cpp - ${PYTHON_SOURCE_DIR}/IRTypes.cpp - ${PYTHON_SOURCE_DIR}/PybindUtils.cpp - ${PYTHON_SOURCE_DIR}/Pass.cpp + DialectLinalg.cpp # TODO: Break this out. + DialectSparseTensor.cpp # TODO: Break this out. + MainModule.cpp + IRAffine.cpp + IRAttributes.cpp + IRCore.cpp + IRModule.cpp + IRTypes.cpp + PybindUtils.cpp + Pass.cpp + + # Headers must be included explicitly so they are installed. + Dialects.h + Globals.h + IRModule.h + Pass.h + PybindUtils.h PRIVATE_LINK_LIBS LLVMSupport EMBED_CAPI_LINK_LIBS @@ -200,8 +208,9 @@ declare_mlir_python_extension(MLIRPythonExtension.AllPassesRegistration MODULE_NAME _mlirAllPassesRegistration + ROOT_DIR "${PYTHON_SOURCE_DIR}" SOURCES - ${PYTHON_SOURCE_DIR}/AllPassesRegistration.cpp + AllPassesRegistration.cpp PRIVATE_LINK_LIBS LLVMSupport EMBED_CAPI_LINK_LIBS @@ -212,8 +221,9 @@ declare_mlir_python_extension(MLIRPythonExtension.AsyncDialectPasses MODULE_NAME _mlirAsyncPasses ADD_TO_PARENT MLIRPythonSources.Dialects.async_dialect + ROOT_DIR "${PYTHON_SOURCE_DIR}" SOURCES - ${PYTHON_SOURCE_DIR}/AsyncPasses.cpp + AsyncPasses.cpp PRIVATE_LINK_LIBS LLVMSupport EMBED_CAPI_LINK_LIBS @@ -223,8 +233,9 @@ declare_mlir_python_extension(MLIRPythonExtension.Conversions MODULE_NAME _mlirConversions ADD_TO_PARENT MLIRPythonSources.Passes + ROOT_DIR "${PYTHON_SOURCE_DIR}" SOURCES - ${PYTHON_SOURCE_DIR}/Conversions/Conversions.cpp + Conversions/Conversions.cpp PRIVATE_LINK_LIBS LLVMSupport EMBED_CAPI_LINK_LIBS @@ -234,8 +245,9 @@ declare_mlir_python_extension(MLIRPythonExtension.ExecutionEngine MODULE_NAME _mlirExecutionEngine ADD_TO_PARENT MLIRPythonSources.ExecutionEngine + ROOT_DIR "${PYTHON_SOURCE_DIR}" SOURCES - ${PYTHON_SOURCE_DIR}/ExecutionEngineModule.cpp + ExecutionEngineModule.cpp PRIVATE_LINK_LIBS LLVMSupport EMBED_CAPI_LINK_LIBS @@ -245,8 +257,9 @@ declare_mlir_python_extension(MLIRPythonExtension.GPUDialectPasses MODULE_NAME _mlirGPUPasses ADD_TO_PARENT MLIRPythonSources.Dialects.gpu + ROOT_DIR "${PYTHON_SOURCE_DIR}" SOURCES - ${PYTHON_SOURCE_DIR}/GPUPasses.cpp + GPUPasses.cpp PRIVATE_LINK_LIBS LLVMSupport EMBED_CAPI_LINK_LIBS @@ -256,8 +269,9 @@ declare_mlir_python_extension(MLIRPythonExtension.LinalgPasses MODULE_NAME _mlirLinalgPasses ADD_TO_PARENT MLIRPythonSources.Dialects.linalg + ROOT_DIR "${PYTHON_SOURCE_DIR}" SOURCES - ${PYTHON_SOURCE_DIR}/LinalgPasses.cpp + LinalgPasses.cpp PRIVATE_LINK_LIBS LLVMSupport EMBED_CAPI_LINK_LIBS @@ -267,8 +281,9 @@ declare_mlir_python_extension(MLIRPythonExtension.SparseTensorDialectPasses MODULE_NAME _mlirSparseTensorPasses ADD_TO_PARENT MLIRPythonSources.Dialects.sparse_tensor + ROOT_DIR "${PYTHON_SOURCE_DIR}" SOURCES - ${PYTHON_SOURCE_DIR}/SparseTensorPasses.cpp + SparseTensorPasses.cpp PRIVATE_LINK_LIBS LLVMSupport EMBED_CAPI_LINK_LIBS @@ -278,8 +293,9 @@ declare_mlir_python_extension(MLIRPythonExtension.Transforms MODULE_NAME _mlirTransforms ADD_TO_PARENT MLIRPythonSources.Passes + ROOT_DIR "${PYTHON_SOURCE_DIR}" SOURCES - ${PYTHON_SOURCE_DIR}/Transforms/Transforms.cpp + Transforms/Transforms.cpp PRIVATE_LINK_LIBS LLVMSupport EMBED_CAPI_LINK_LIBS