Hello! I'm trying to do the following: 1. Create...
# multiplatform
r
Hello! I'm trying to do the following: 1. Create a kotlin lib 2. Generate the
.d.ts
files (I don't use the generated javascript code!) 3. Create a typescript script which uses the
.d.ts
4. Compile to javascript 5. Run in the GraalVM The end result I'm looking for like a binding for my kotlin classes to be called from typescript. I'm using latest kotlin version 1.4-M3. Disclaimer I'm not expert in typescript (nor kotlin), but I could do everything, however: 1. The generated typescript definition file doesn't
export
module, so I cannot import in my typescript script 2. I added the export keyword to fix it 3. Now I can import the definition and use it, however in order to execute in GraaVM what I need is to import java types from javascript by using the
Java.type
call instead of
require
Now I would like to know if there's a way to modify the kotlin generator so that I could achieve transpilation from such imported types to javascript and be callable by GraalVM out of the box. Some guidance on this topic would nice and I believe at least the
export
of the module should be part of the core kotlin generator.
@bashor tagging you here as you are involved in developing this feature 🙂
r
FYI The export issue is tracked at https://youtrack.jetbrains.com/issue/KT-37883
👍 1
b
Important note: this feature wasn’t designed for described usecase (ala d.ts for Kotlin/JVM API). It may work accidentally sometimes, sometimes not, but we don’t test it such possibility and don’t have any plan to support it.
👍 1
r
@bashor I totally understand it. Apart from the the module issue, I believe the rest of the things don't really belong to the core code generation. I'm curious though if you could at least tell me how I could achieve such a thing through a compiler plugin or something...? I don't know where I could start.
b
to discover implementation details you can start from here
I believe it’s possible to be done using compiler plugin, but note we don’t have public nor stable plugin API yet.
also d.ts generation now is part of the new JS compiler backend
r
I see... So that I could followup on this, if you wanted to support such a feature, how would you approach it then? extend (i.e. depend on) the
backend.js
to create something like
backend.graalvmjs
would be the right path?
and by
public
you mean that the only way to use the compiler API would be forking kotlin itself?
I really don't mind if it's not stable API though, I can live with it
b
There is some plugin API mostly for internal use 🙂 It’s not documented, but you can find some resources in the internet including some talks 😉.
👍 1
Do I I understood correctly that you wanted to have d.ts for the classes generated by Kotlin/JVM? If so I think it should be plugin for Kotlin/JVM, maybe you will be able to reuse something from current d.ts generator along with the new JVM IR based compiler.
r
@bashor in the end, yes, I want to call the JVM classes, not the javascript ones. I'm not sure if there could be differences between the
.d.ts
generated for this purpose and the one generated to call javascript. To summarize: 1. compile kotlin 2. generate
.d.ts
for those classes 3. use it from typescript 4. transpile to javascript 5. run in the graalvm (then it will be able to call the kotlin classes from javascript)
to me it would be enough if I could extend the current generated
d.ts
to generate in addition the graalvm's required
Java.type
calls
b
I’m not sure if there could be differences between the 
.d.ts
 generated for this purpose and the one generated to call javascript.
Unfortunately, ABI of generated code is platform dependent.
r
👍