dart-lang / native

Dart packages related to FFI and native assets bundling.
BSD 3-Clause "New" or "Revised" License
105 stars 36 forks source link

[Discussion] Roadmap #798

Closed mahesh-hegde closed 1 year ago

mahesh-hegde commented 1 year ago

This issue is a discussion on development roadmap.

The code generator is the most important part of this project, which comprises of two major parts - the API summarizer and the binding generator.

Current Progress (28 July 2022)

I have got the summarizer working to a satisfactory level, (except the bugs / insufficiencies we discover as write the binding generator). The default implementation is based on OpenJDK Doclet API, but there's place for including an ASM based summarizer as well.

The summarizer has to be vendored later, and a script should be provided to build jar using mvn.

For now, summarizer must output json or some other serialization format, since macos and windows JNI bindings are not quite ready. Also, hand-writing JNI bindings will be error prone. In later stages we might be able to inspect the possibility of using jni_gen itself to generate bindings to the summarizer. (It's currently outputting JSON).

For the binding generator part, I have a skeleton at codegen_temp branch of my fork. Still have to write the code that generates bindings.

Binding generator architecture (planned)

Divided into a summary provider, config, and output writer.

output writer calls C and Dart binding generators, passing parts of the config as required.

User can add a script depending on package:jni_gen, creating a JniGenTask(summarySource, config, writer) or something like that.

In future we can also add a YAML config for basic options. But I think some options are better served by ability to write arbitrary callbacks.

package:jni refactoring

package:jni works right now, but relies on some unreliable assumptions. It requires a refactor: (#12)

It can be done by patching some parts of ffigen to also emit some extra C code.

Dependencies

Roadmap

Here's the roadmap

Future goals:

liamappelbe commented 1 year ago

Is the API summarizer going to be part of package:jni_gen, or a separate package? I think outputting a JSON API summary is unnecessary, especially if it's within the same package.

You're basically doing this: [3rd party Java parser] -> [Dart representation of AST] --(serialize)-> [JSON] --(deserialize)-> [Dart representation of AST] -> [binding generator]

You could skip the JSON step, right? If you've already written it that way, that's fine, but if you find yourself spending a lot of time on the serialization and deserialization logic, just skip it.

Next step: Focus on the output writer/code generator. Ignore those bits of package:jni cleanup for now.

mahesh-hegde commented 1 year ago

Parsing java APIs is in java using doclet API, writing bindings (main tool) is in dart. We need a way to access at least until codegen is ready.

Daco suggested writing some manual Jni bindings (like ffigen did), but desktop support on windows is fragile, it doesn't exist for macOS right now, and writing accessors manually using JNI is quite some repetitive work.

    Mahesh

On Fri, 29 Jul, 2022, 12:02 am Liam Appelbe, @.***> wrote:

Is the API summarizer going to be part of package:jni_gen, or a separate package? I think outputting a JSON API summary is unnecessary, especially if it's within the same package.

You're basically doing this: [3rd party Java parser] -> [Dart representation of AST] --(serialize)-> [JSON] --(deserialize)-> [Dart representation of AST] -> [binding generator]

You could skip the JSON step, right? If you've already written it that way, that's fine, but if you find yourself spending a lot of time on the serialization and deserialization logic, just skip it.

Next step: Focus on the output writer/code generator. Ignore those bits of package:jni cleanup for now.

— Reply to this email directly, view it on GitHub https://github.com/dart-lang/jni_gen/issues/18#issuecomment-1198499054, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALAKLFVEMKOXRDNF2F2MZHDVWLG4HANCNFSM546DMTKA . You are receiving this because you authored the thread.Message ID: @.***>

mahesh-hegde commented 1 year ago

I forgot to add few things.

[3rd party Java parser] -> [Dart representation of AST] --(serialize)-> [JSON] --(deserialize)-> [Dart representation of AST]

No it's building a tree at once using the visitors provided by parser. I could not find a way to access a prebuilt tree representation. For example, the type mirrors are usages of the class, and we have to visit the members to get some required information about the class.

As for JSON, it's trivial on Java side because there's reflection, I am just passing the built objects to jackson API. On dart side also I am using code generation (json_serializable). Only extra thing is double definition of classes on both dart and java. So far it seems to be OK.

dcharkes commented 1 year ago

You're basically doing this: [3rd party Java parser] -> [Dart representation of AST] --(serialize)-> [JSON] --(deserialize)-> [Dart representation of AST] -> [binding generator]

No, the current approach is: [3rd party Java parser] -> [Java representation of AST] --(serialize)-> [JSON] --(deserialize)-> [Dart representation of AST] -> [binding generator]

When we can use jni_gen to bind the 3rd party Java parser, then we can get immediately go to a Dart representation of the AST.

The summarizer has to be vendored later, and a script should be provided to build jar using mvn.

We should maybe make that a sub-folder on this repository. Including a CI step that builds the JAR and some Java unit tests.

Next step: Focus on the output writer/code generator. Ignore those bits of package:jni cleanup for now.

Agreed. Let's try to focus on getting a code generator for the simple use case working as first prio.