Hi everyone! Is there a way to make gradle project...
# compiler
l
Hi everyone! Is there a way to make gradle project work with custom-built compiler/annotation processor binaries? In example, I want to build an existing WASM example project (which has
kotlin { wasmWasi { ... }}
configuration), and I don't want to run
kotlin-js
directly from the bash. Sorry if it was asked here before, I couldn't find it in READMEs or by Slack search.
t
Yes, it is possible. You can create a gradle plugin which in turn adds a Kotlin compiler plugin. In the Kotlin compiler plugin you can do quite a lot of things. For example:
Copy code
plugins {
    kotlin("multiplatform") version "1.9.10"
    id("hu.simplexion.z2") version "2024.02.27"
}
It is not particularly hard to set up the plugins but you have to do some investigation to do it. Resources: https://github.com/demiurg906/kotlin-compiler-plugin-template https://github.com/ahinchman1/Kotlin-Compiler-Crash-Course/blob/master/README.md https://github.com/JetBrains/kotlin/blob/master/docs/fir https://github.com/JetBrains/kotlin/blob/master/plugins/fir-plugin-prototype https://github.com/JetBrains/kotlin/blob/master/compiler/test-infrastructure/ReadMe.md (a bit outdated but good intro): https://bnorm.medium.com/writing-your-second-kotlin-compiler-plugin-part-1-project-setup-7b05c7d93f6c
What do you want to achieve btw? Just curious.
l
Oh, thank you so much! There are a lot of stuff to learn 😄
What do you want to achieve btw? Just curious.
I’m curious about how Kotlin/Wasm works and what it takes to implement some of the missing Wasm opcodes, but I need to be able to build test project first. (I actually did it using raw
kotlinc-js
calls, but feels unhandy tbh)
t
In that case (WASM opcodes) you probably want to focus on the backend part. Actually, the backend compiler plugins are called before any platform specific stuff is done. So maybe your interest is not even in the plugins, but the WASM compiler backend itself. That said, understanding the backend IR and how it is structured is really necessary to navigate easily in the compiler backend. I would check this part of the compiler repo: https://github.com/JetBrains/kotlin/tree/407448d8e37c311007bf343cbf77c8911e4c45e4/wasm/wasm.ir/src/org/jetbrains/kotlin/wasm/ir
l
Yeap, that's what I was working on. Just wanted to build a test project as I always do with IDEA, but using tweaked compiler (to see the differences my code makes)
So I was not looking to create a compiler plugin, but rather to 1. tweak compiler 2. build the official wasm example using it 3. check if my tweaks doesn't brake the bytecode inside of wasm binaries