oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.34k stars 1.63k forks source link

[GR-28582] Enable to generate C bindings from header files #3106

Open rmannibucau opened 3 years ago

rmannibucau commented 3 years ago

Feature request

Is your feature request related to a problem? Please describe. Testing the native-image library generation, I realized that writing the C binding (@CStruct, @CFunction etc) is quite bothering, long and error prone.

Describe the solution you'd like. It would be neat to have a generate in svm or graal (more than fine to install it with gu), something along:

<new-tool> generate-java-binding /usr/include/apache2/http_config.h

Indeed it can require to go through some macro (this is why I used httpd as an example) and potentially visit some other imported file but the gain is huge.

Describe who do you think will benefit the most. Anyone wanting to plug in in a system written in C/C++ using java.

Describe alternatives you've considered.

  1. Doing it manually,
  2. Using some custom glue C library

(but both options creates additional cost and are harder to validate, in particular when there are some #ifdef/#ifndef blocks)

munishchouhan commented 3 years ago

@rmannibucau thanks for the feature request we will look into it and update the issue

christianwimmer commented 3 years ago

There is work in progress for the OpenJDK project Panama to extract Java declarations from C header files. At this time, we do not think we will have time to implement something for the Native Image C API, but instead wait for project Panama to be done and then support Panama also in Native Image.