GithubHelp home page GithubHelp logo

Comments (4)

chippmann avatar chippmann commented on July 21, 2024 1

We had the same problem on our project. We basically "solved" it by making a fake target through gradle at build time which has the same configuration like the actual target we want to build. During the compilation of the fake target, the generated code is created and added to the source set and thus available when the actual target is built.
An ugly hack but with the current way compiler plugins are made, it seems not to be possible to achieve this like with the kapt annotation processors for the jvm. The only other solution would be to directly generate IR for the kotlin compiler like the kotlinx Serialization plugin does. But then you end up with code that is not debuggable.
So a trade of either way.

Edit: from here on we create the dummy target: https://github.com/utopia-rise/godot-kotlin/blob/521476cececfa13cbc86cb3b9e7d9eb3a3bd15be/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/GodotPlugin.kt#L73 if you want to have a look on how to setup this

from mpapt.

Archinamon avatar Archinamon commented on July 21, 2024

Looks cool! But doesn't work on my side :(

The reason is: you made a virtual target with custom source set name (godot[Main|Test]).
But I have a jvm default source set.

Well, it still could be achieved with your's way. But I need to change whole project's structure :(

I'm digging deeper to kotlinx.serialization... What do you mean saying "directly generate IR"?

from mpapt.

chippmann avatar chippmann commented on July 21, 2024

Yes depending on the size of the project that's not feasible at all.
You can directly generate the Intermediate Representation (IR) of the code you want to generate. This is the format the kotlin compiler uses to generate the ByteCode for the various platforms.
But as of now this is very poorly documented and not a stable API yet. With Kotlin 1.4 it seems they want to improve that situation.
That said I'm by no means an expert on how to generate IR. On our project we'll start into looking to directly generate IR with kotlin 1.4 soon so not much experiance on my side. Your best bet seems to be the kotlinx.Serialization plugin.

Also a good starting point might be this set of slides: https://resources.jetbrains.com/storage/products/kotlinconf2018/slides/5_Writing%20Your%20First%20Kotlin%20Compiler%20Plugin.pdf
from this talk: https://www.youtube.com/watch?v=w-GMlaziIyo
Although he directly generates JVM bytecode from it, it might get you more familiar with what to look for.

But maybe @Foso has a better idea on how to tackle this problem which is quite similar with what i eluded here: #11
There i also linked another possible but really hacky "solution" by generating the code in advance of the compilation process by parsing kotlin code yourself with the help of the kotlin compiler frontend.
Shortcut if you don't want to read the issue: https://github.com/vektory79/kotlin-script-parser-test/blob/master/src/main/java/hello/CompileTest.kt

from mpapt.

Foso avatar Foso commented on July 21, 2024

Hi, sorry for the late answer, unfortunately i don't have a better solution yet, but i will take a look if Kotlin 1.4.0 offers some new opportunities

from mpapt.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.