Create new file using compiler plugin

Not having much luck trying to figure out how to add a new file via a compiler plugin (the reason is I need to add a top level function with a specific package name, so I can’t just add a function to an existing file).

I’ve tried creating a IrFileImpl and adding it to the module fragment, but then the compiler complains that source files != ir files.

I’ve tried using buildFile {} inside IrGenerationExtension but that returns an FirFile whereas the module framegment is existing an IrFile.

Just looking if anyone can point me in the right direction - some docs or a project that’s doing the same thing that I can draw inspiration from.

Try KSP, that is easier.

1 Like