[all-commits] [llvm/llvm-project] c26517: [mlir] Add MLIR-C dylib.

Stella Laurenzo via All-commits all-commits at lists.llvm.org
Thu Nov 11 22:58:40 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: c265170110b2e3b82ab8fca6658bfbbce79381c5
      https://github.com/llvm/llvm-project/commit/c265170110b2e3b82ab8fca6658bfbbce79381c5
  Author: Stella Laurenzo <stellaraccident at gmail.com>
  Date:   2021-11-11 (Thu, 11 Nov 2021)

  Changed paths:
    M mlir/CMakeLists.txt
    M mlir/include/mlir/ExecutionEngine/CRunnerUtils.h
    M mlir/include/mlir/ExecutionEngine/RunnerUtils.h
    M mlir/lib/CAPI/CMakeLists.txt
    M mlir/lib/CAPI/Conversion/CMakeLists.txt
    M mlir/lib/CAPI/Debug/CMakeLists.txt
    M mlir/lib/CAPI/Dialect/CMakeLists.txt
    M mlir/lib/CAPI/ExecutionEngine/CMakeLists.txt
    M mlir/lib/CAPI/IR/CMakeLists.txt
    M mlir/lib/CAPI/Interfaces/CMakeLists.txt
    M mlir/lib/CAPI/Registration/CMakeLists.txt
    M mlir/lib/CAPI/Transforms/CMakeLists.txt
    M mlir/test/CAPI/CMakeLists.txt

  Log Message:
  -----------
  [mlir] Add MLIR-C dylib.

Per discussion on discord and various feature requests across bindings (Haskell and Rust bindings authors have asked me directly), we should be building a link-ready MLIR-C dylib which exports the C API and can be used without linking to anything else.

This patch:

* Adds a new MLIR-C aggregate shared library (libMLIR-C.so), which is similar in name and function to libLLVM-C.so.
* It is guarded by the new CMake option MLIR_BUILD_MLIR_C_DYLIB, which has a similar purpose/name to the LLVM_BUILD_LLVM_C_DYLIB option.
* On all platforms, this will work with both static, BUILD_SHARED_LIBS, and libMLIR builds, if supported:
  * In static builds: libMLIR-C.so will export the CAPI symbols and statically link all dependencies into itself.
  * In BUILD_SHARED_LIBS: libMLIR-C.so will export the CAPI symbols and have dynamic dependencies on implementation shared libraries.
  * In libMLIR.so mode: same as static. libMLIR.so was not finished for actual linking use within the project. An eventual relayering so that libMLIR-C.so depends on libMLIR.so is possible but requires first re-engineering the latter to use the aggregate facility.
* On Linux, exported symbols are filtered to only the CAPI. On others (MacOS, Windows), all symbols are exported. A CMake status is printed unless if global visibility is hidden indicating that this has not yet been implemented. The library should still work, but it will be larger and more likely to conflict until fixed. Someone should look at lifting the corresponding support from libLLVM-C.so and adapting. Or, for special uses, just build with `-DCMAKE_CXX_VISIBILITY_PRESET=hidden -DCMAKE_C_VISIBILITY_PRESET=hidden`.
* Includes fixes to execution engine symbol export macros to enable default visibility. Without this, the advice to use hidden visibility would have resulted in test failures and unusable execution engine support libraries.

Differential Revision: https://reviews.llvm.org/D113731




More information about the All-commits mailing list