I'm looking for resources on writing compiler plug...
# compiler
p
I'm looking for resources on writing compiler plugins. So far I found: •

https://youtu.be/w-GMlaziIyo

https://bnorm.medium.com/writing-your-second-kotlin-compiler-plugin-part-1-project-setup-7b05c7d93f6c but I'm aware that the API moves fast. Is there some fresh tutorial or example plugin? I've been looking around source code of existing plugins, but first I want to check if there are some guides.
b
No guides, just pretty much following bnorm blog and using .dump() a lot to inspect the general structure.
That's how I got going. People here also help with word-of-mouth knowledge sharing on case-by-case basis
p
Thanks! For context: my goal is to move generation of GitHub action wrappers in github-workflows-kt to a compiler plugin. Right now they are bundled with the library so their updates are bound to the library's release cycle. There's a long way to rely solely on the plugin, but I want to start. Primarily, I need to check if it's possible to use third-party compiler plugins in Kotlin Script.
b
Hmm, you certainly can add compiler plugins to scripts, but it's not pretty. I'm not sure it's the way to go for your usecase. Why don't you publish each action wrapper as its own artefact instead?
p
Why don’t you publish each action wrapper as its own artefact instead?
my goal is to make the DSL library scalable in terms of the number of supported actions, and ultimately unaware of the actions that it can support. I want to achieve it by asking the action authors to use https://github.com/krzema12/github-actions-typing/. As a maintainer of the DSL library, I don’t want to be responsible for publishing separate artefacts - it does sound complicated because publication failures happen and automation to release these would have to be created, and I simply want to avoid being the middleman. That’s of course the ideal world, my current northern star
cool question, BTW - happy to discuss it further in #github-workflows-kt if you want!
b
So what's your idea for the compiler plugin? Fetch action typings injected via some annotation on an empty interface and generate actions methods on the fly?
p
yep, that’s my initial idea
still thinking about a cleaner API, but it would be bearable I think
b
You won't get any IDE support for that unless you also write FIR plugin (which is even less stable/documented)
While your idea is sound, I think it's much too early for that
p
Got it - yeah, I don't want to introduce this change just yet, just wanted to play around with compiler API and build a little PoC
b
You could build a backend IR plugin for this fairly easy, but at the moment end user experience would be terrible. Not only will they have to add the plugin via kotlinc cli, but they will also need to write their scripts blindly without any intellisense
p
Yes, true - I realize that
b
I'd suggest just having a scheduled github ci job that would somehow scan known repos that use action types and would generate/publish wrapper artefacts for new versions
Complex one-time setup that can run unattended afterwards and have much better end user experience
In the current state of kotlin ecosystem at least
You can also have some readme page on the repo that ci would record latest published wrapper artefacts for discoverability
p
That's exactly my plan B, or a mid-term one until Kotlin allows for more
b
Just some alternative ideas for you short-term
p
Great, thanks a lot for digging deeper with me and helping me realize what's missing in Kotlin :)
b
Happy to help with CI stuff if you get stuck. Just ping me.
p
Ah, I fancy the CI stuff myself 😉
b
I think you could copy a lot of infra from kamp scan job to give you a head start
Ah, I fancy the CI stuff myself 😉
We're the minority on that 😀
Anyways, do report back on #github-workflows-kt when you make some progress. Curious to see where it ends up.
p
BTW, I'd like to better understand what FIR plugins are. I understand they're related to IDE support and that FIR stands for Frontend IR (right?). But why aren't just backend IR plugins enough for the IDE? Do compiler plugins always come in pairs (backend and frontend), like socks? And finally, is FIR plugin needed if I plan to work only with backend IR? What would the plugin do in such case?
b
I'd love a good explanation on that too. So far it's very confusing 😀 Maybe ask in a separate thread on this channel?
j
@Piotr Krzemiński What do you mean with "IDE support"? I am also just getting into the world of compiler plugins. In a plugin I implemented a method from an interface. In IntelliJ there were errors because IntelliJ didn't know about it. I wrote an Intellij plugin that references the "SyntheticResolveExtension" of the plugin. With this it works. But you have to provide an IntelliJ plugin...