Skip to content

Update building plugin guide #1515

Open
@erick-xanadu

Description

@erick-xanadu

Users reported the following:

With these changes, you should now be able to use make all and build the standalone plugin.

I find that all of the above changes get overwritten with the initial state. Is there some configuration that might cause a reset of the standalone implementation?

Additionally, the build process can be somewhat simplified. I originally had issues building the standalone plugin and including Catalyst's sources without making it part of the Catalyst build system. I asked a question on discord:

Hello,

I have a MLIR based project. I am trying to make the experience of writing a standalone-plugin for my project fairly easy. I have not modified the standalone-plugin build system in any major way yet. (I would say I haven't modified the build system besides patching the CMake to have a path to my mlir-opt-like tool and patching the lit tests so that my mlir-opt-like tool is used instead of mlir-opt). This works well so far.

However, I am trying now to modify the Standalone Pass available upstream to be able to correctly have the INCLUDE_DIRS for my project. I was able to do that myself, but I am having troubles after adding this line:

let dependentDialects = [
"foo::MyDialect"
];

When I build the standalone-plugin everything appears to work until the linking phase. I then get the following message:

/usr/bin/ld: lib/libMLIRStandalone.a(StandalonePasses.cpp.o): in function `mlir::detail::TypeIDResolver<foo::MyDialect, void>::resolveTypeID()':
StandalonePasses.cpp:

// ... snip ...

undefined reference to `foo::MyDialect::MyDialect(mlir::MLIRContext*)'
collect2: error: ld returned 1 exit status

I understand that this is missing in the linking stage. I believe what I need to do is to have the StandalonePlugin cmake file modified to add my library, something like

add_llvm_library(StandalonePlugin

   DEPENDS
   MLIRMyDialect
   MLIRStandalone
   PLUGIN_TOOL
   mlir-opt

   LINK_LIBS
   MLIRMyDialect
   MLIRStandalone
   )

But I am having some troubles getting this to work. I have the following questions:

Does anyone know of a project that has already implemented this type of support? I would like to see how they set up their build system to make it easy for MLIR plugin developers to reuse their dialects.
Does anyone have an idea on where to get started? Should I use FetchContent or AddExternalDependency? Maybe a link to read some documentation.

Thanks in advance!

Finally got a reply (thanks Maks!)

this means you're missing an include MyDialect.cpp.inc somewhere
that's where those TypeIDResolver resolvers live

which could simplify the build process

Metadata

Metadata

Assignees

Labels

choredocumentationImprovements or additions to documentation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions