This is an archive of the discontinued LLVM Phabricator instance.

Re-apply "[mlir] Allow out-of-tree python building from installed MLIR."
ClosedPublic

Authored by stellaraccident on Nov 11 2021, 9:50 PM.

Details

Summary

Re-applies D111513:

  • Adds a full-fledged Python example dialect and tests to the Standalone example (need to do a bit of tweaking in the top level CMake and lit tests to adapt better to if not building with Python enabled).
  • Rips out remnants of custom extension building in favor of pybind11_add_module which does the right thing.
  • Makes python and extension sources installable (outputs to src/python/${name} in the install tree): Both Python and C++ extension sources get installed as downstreams need all of this in order to build a derived version of the API.
  • Exports sources targets (with our properties that make everything work) by converting them to INTERFACE libraries (which have export support), as recommended for the forseeable future by CMake devs. Renames custom properties to start with lower-case letter, as also recommended/required (groan).
  • Adds a ROOT_DIR argument to declare_mlir_python_extension since now all C++ sources for an extension must be under the same directory (to line up at install time).
  • Downstreams will need to adapt by:
    • Remove absolute paths from any SOURCES for declare_mlir_python_extension (I believe all downstreams are just using ${CMAKE_CURRENT_SOURCE_DIR} here, which can just be ommitted). May need to set ROOT_DIR if not relative to the current source directory.
    • To allow further downstreams to install/build, will need to make sure that all C++ extension headers are also listed under SOURCES for declare_mlir_python_extension.

This reverts commit 1a6c26d1f52999edbfbf6a978ae3f0e6759ea755.

Diff Detail

Event Timeline

stellaraccident requested review of this revision.Nov 11 2021, 9:50 PM

Incorporate stephen's additional fixes to the standalone example, plus:

  • Fix makefiles generator by creating the tablegen directory.
  • Add test depend on the standalone python modules (this fixes the makefiles generator).
  • Propagate the CMake generator to the standalone example (i.e. if building the main with ninja, build standalone with ninja -- otherwise, when building python bindings, adds ~minutes to the build to do it serially with make).
This revision is now accepted and ready to land.Nov 12 2021, 1:55 PM