This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Make Python bindings installable.
ClosedPublic

Authored by stellaraccident on Oct 9 2020, 3:53 PM.

Details

Summary
  • Links against libMLIR.so if the project is built for DYLIBs.
  • Puts things in the right place in build and install time python/ trees so that RPaths line up.
  • Adds install actions to install both the extension and sources.
  • Copies py source files to the build directory to match (consistent layout between build/install time and one place to point a PYTHONPATH for tests and interactive use).
  • Finally, "import mlir" from an installed LLVM just works.

Diff Detail

Event Timeline

stellaraccident created this revision.Oct 9 2020, 3:53 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 9 2020, 3:53 PM
stellaraccident requested review of this revision.Oct 9 2020, 3:53 PM
silvas added a comment.EditedOct 9 2020, 3:56 PM

Just a drive-by nit.

Please defer to others that have been tracking this work more closely for more substantial review.

edit: you seem to have caught the nit.

Harbormaster completed remote builds in B74662: Diff 297351.
zhanghb97 added a comment.EditedOct 9 2020, 11:09 PM

LGTM, I use the following commands in the build directory:

cmake --build . --target check-mlir
cmake --build . --target install

I have a question that if I only want to install MLIRBindingsPythonExtension and MLIRBindingsPythonSources (without installing llvm, llvm-c, mlir, mlir-c, etc.), what should I do?

LGTM, I use the following commands in the build directory:

cmake --build . --target check-mlir
cmake --build . --target install

I have a question that if I only want to install MLIRBindingsPythonExtension and MLIRBindingsPythonSources (without installing llvm, llvm-c, mlir, mlir-c, etc.), what should I do?

This should work:
cmake --build . --target install-MLIRBindingsPythonSources install-MLIRBindingsPythonExtension

Also, for interactive use, you don't need to install. Just build those two targets and set your PYTHONPATH to the python dir in your build directory.

This should work:
cmake --build . --target install-MLIRBindingsPythonSources install-MLIRBindingsPythonExtension

It works. Thanks!

ftynse accepted this revision.Oct 12 2020, 1:57 AM
ftynse added inline comments.
mlir/lib/Bindings/Python/CMakeLists.txt
15

Did you mean ${PY_SRC_FILE} (singular) here?

This revision is now accepted and ready to land.Oct 12 2020, 1:57 AM
mlir/test/lit.cfg.py
102–108

I don't think this should get littered in the llvm install. There should be a separate mlir-npcomp_obj_root, I think.

Address comments/rebase.

stellaraccident marked an inline comment as done.Oct 12 2020, 3:19 PM
stellaraccident added inline comments.
mlir/lib/Bindings/Python/CMakeLists.txt
15

Yes. (and this was only working because there is presently one source file, I expect)

mlir/test/lit.cfg.py
102–108

As discussed on discord, added a todo and will start a thread in a couple of days to work out overall issues that implicate needing to do this.

This revision was landed with ongoing or failed builds.Oct 12 2020, 3:20 PM
This revision was automatically updated to reflect the committed changes.
stellaraccident marked an inline comment as done.
mlir/lib/Bindings/Python/CMakeLists.txt