libMLIRPublicAPI.so came into existence early when the Python and C-API were being co-developed because the Python extensions need a single DSO which exports the C-API to link against. It really should never have been exported as a mondo library in the first place, which has caused no end of problems in different linking modes, etc (i.e. the CAPI tests depended on it). This patch does a mechanical move that: * Makes the C-API tests link directly to their respective libraries. * Creates a libMLIRPythonCAPI as part of the Python bindings which assemble to exact DSO that they need. This has the effect that the C-API is no longer monolithic and can be subset and used piecemeal in a modular fashion, which is necessary for downstreams to only pay for what they use. There are additional, more fundamental changes planned for how the Python API is assembled which should make it more out of tree friendly, but this minimal first step is necessary to break the fragile dependency between the C-API and Python API. Downstream actions required: * If using the C-API and linking against MLIRPublicAPI, you must instead link against its constituent components. As a reference, the Python API dependencies are in lib/Bindings/Python/CMakeLists.txt and approximate the full set of dependencies available. * If you have a Python API project that was previously linking against MLIRPublicAPI (i.e. to add its own C-API DSO), you will want to `s/MLIRPublicAPI/MLIRPythonCAPI/` and all should be as it was. There are larger changes coming in this area but this part is incremental. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D106369
138 lines
3.6 KiB
CMake
138 lines
3.6 KiB
CMake
include(AddMLIRPython)
|
|
add_custom_target(MLIRBindingsPythonExtension)
|
|
|
|
################################################################################
|
|
# All python extensions must link through one DSO which exports the CAPI, and
|
|
# this must have a globally unique name amongst all embeddors of the python
|
|
# library since it will effectively have global scope.
|
|
#
|
|
# The presence of this aggregate library is part of the long term plan, but its
|
|
# use needs to be made more flexible.
|
|
################################################################################
|
|
|
|
set(public_api_libs
|
|
MLIRCAPIConversion
|
|
MLIRCAPIDebug
|
|
MLIRCEXECUTIONENGINE
|
|
MLIRCAPIIR
|
|
MLIRCAPIRegistration
|
|
MLIRCAPITransforms
|
|
|
|
# Dialects
|
|
MLIRCAPIAsync
|
|
MLIRCAPIGPU
|
|
MLIRCAPILinalg
|
|
MLIRCAPILLVM
|
|
MLIRCAPIShape
|
|
MLIRCAPISparseTensor
|
|
MLIRCAPIStandard
|
|
MLIRCAPISCF
|
|
MLIRCAPITensor
|
|
)
|
|
|
|
foreach(lib ${public_api_libs})
|
|
if(XCODE)
|
|
# Xcode doesn't support object libraries, so we have to trick it into
|
|
# linking the static libraries instead.
|
|
list(APPEND _DEPS "-force_load" ${lib})
|
|
else()
|
|
list(APPEND _OBJECTS $<TARGET_OBJECTS:obj.${lib}>)
|
|
endif()
|
|
# Accumulate transitive deps of each exported lib into _DEPS.
|
|
list(APPEND _DEPS $<TARGET_PROPERTY:${lib},LINK_LIBRARIES>)
|
|
endforeach()
|
|
|
|
add_mlir_library(MLIRPythonCAPI
|
|
PARTIAL_SOURCES_INTENDED
|
|
SHARED
|
|
${_OBJECTS}
|
|
EXCLUDE_FROM_LIBMLIR
|
|
LINK_LIBS
|
|
${_DEPS}
|
|
)
|
|
if(MSVC)
|
|
set_property(TARGET MLIRPythonCAPI PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON)
|
|
endif()
|
|
|
|
################################################################################
|
|
# Build core python extension
|
|
################################################################################
|
|
add_mlir_python_extension(MLIRCoreBindingsPythonExtension _mlir
|
|
INSTALL_DIR
|
|
python
|
|
SOURCES
|
|
DialectLinalg.cpp
|
|
DialectSparseTensor.cpp
|
|
MainModule.cpp
|
|
IRAffine.cpp
|
|
IRAttributes.cpp
|
|
IRCore.cpp
|
|
IRModule.cpp
|
|
IRTypes.cpp
|
|
PybindUtils.cpp
|
|
Pass.cpp
|
|
ExecutionEngine.cpp
|
|
LINK_LIBS PRIVATE
|
|
LLVMSupport
|
|
MLIRPythonCAPI
|
|
)
|
|
add_dependencies(MLIRBindingsPythonExtension MLIRCoreBindingsPythonExtension)
|
|
|
|
add_subdirectory(Transforms)
|
|
add_subdirectory(Conversions)
|
|
|
|
add_mlir_python_extension(MLIRAllPassesRegistrationBindingsPythonExtension _mlirAllPassesRegistration
|
|
INSTALL_DIR
|
|
python
|
|
SOURCES
|
|
AllPassesRegistration.cpp
|
|
LINK_LIBS PRIVATE
|
|
LLVMSupport
|
|
MLIRPythonCAPI
|
|
)
|
|
add_dependencies(MLIRBindingsPythonExtension MLIRAllPassesRegistrationBindingsPythonExtension)
|
|
|
|
add_mlir_python_extension(MLIRAsyncPassesBindingsPythonExtension _mlirAsyncPasses
|
|
INSTALL_DIR
|
|
python
|
|
SOURCES
|
|
AsyncPasses.cpp
|
|
LINK_LIBS PRIVATE
|
|
LLVMSupport
|
|
MLIRPythonCAPI
|
|
)
|
|
add_dependencies(MLIRBindingsPythonExtension MLIRAsyncPassesBindingsPythonExtension)
|
|
|
|
add_mlir_python_extension(MLIRSparseTensorPassesBindingsPythonExtension _mlirSparseTensorPasses
|
|
INSTALL_DIR
|
|
python
|
|
SOURCES
|
|
SparseTensorPasses.cpp
|
|
LINK_LIBS PRIVATE
|
|
LLVMSupport
|
|
MLIRPythonCAPI
|
|
)
|
|
add_dependencies(MLIRBindingsPythonExtension MLIRSparseTensorPassesBindingsPythonExtension)
|
|
|
|
add_mlir_python_extension(MLIRGPUPassesBindingsPythonExtension _mlirGPUPasses
|
|
INSTALL_DIR
|
|
python
|
|
SOURCES
|
|
GPUPasses.cpp
|
|
LINK_LIBS PRIVATE
|
|
LLVMSupport
|
|
MLIRPythonCAPI
|
|
)
|
|
add_dependencies(MLIRBindingsPythonExtension MLIRGPUPassesBindingsPythonExtension)
|
|
|
|
add_mlir_python_extension(MLIRLinalgPassesBindingsPythonExtension _mlirLinalgPasses
|
|
INSTALL_DIR
|
|
python
|
|
SOURCES
|
|
LinalgPasses.cpp
|
|
LINK_LIBS PRIVATE
|
|
LLVMSupport
|
|
MLIRPythonCAPI
|
|
)
|
|
add_dependencies(MLIRBindingsPythonExtension MLIRLinalgPassesBindingsPythonExtension)
|