Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] Use GraalVM nativeimage #26

Open
electronstudio opened this issue Sep 29, 2021 · 1 comment
Open

[Proposal] Use GraalVM nativeimage #26

electronstudio opened this issue Sep 29, 2021 · 1 comment
Labels

Comments

@electronstudio
Copy link
Owner

There are two ways to do this:

  1. With the Jaylib bindings.

Problem: All the JNI method calls need to be listed in a file META-INF/native-image/jni-config.json. This file can be generated by the 'native-image-agent' but it's very incomplete. So someone would have to manually add every JNI call which seems a pretty big job.

  1. Make new bindings that don't use JNI.

There's a nice example of this here: https://github.com/praj-foss/opengl-graal-examples

Seems like it should be very fast. But it will only ever work with GraalVM in nativeimage mode which might limit how many people would want to use it. Is there a tool to autogenerate these or are we back to having to do it manually?

@electronstudio
Copy link
Owner Author

I got (1) working. To generate the jni-config use:

$GRAALVM_HOME/bin/java -agentlib:native-image-agent=config-output-dir=META-INF/native-image,no-builtin-caller-filter -jar jaylib-example-project-1.0-SNAPSHOT-all.jar

Then edit reflect-config.json and add these extra fields to every entry:

{
  "name":"com.raylib.Raylib$Texture",
  "allDeclaredFields":true,
  "allPublicConstructors" : true,
  "allPublicFields": true,
  "allDeclaredMethods": true,
  "allPublicMethods": true
},

The native-image.properties should contain:

Args = --no-fallback --allow-incomplete-classpath

However in the end the performance is pretty poor, so no point in this approach for performance. (Might be if you have some other reason like wanting to run on iOS where you cant run JIT.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant