jmonkeyengine icon indicating copy to clipboard operation
jmonkeyengine copied to clipboard

Prepare a Graal-based iOS AOT Compilation

Open MeFisto94 opened this issue 3 years ago • 7 comments

Due to the sunset of bintray, the SDK cannot easily access the avian build anymore, that I manually did painfully on a Mac OS X machine and stored it on bintray.

Now while I could try to get this running on Github Actions, it's still discontinued and based on java 7. Instead Graal provides an industry grade support for general AOT compilation and should be supported for a much longer time.

The scope of this issue is to determine the steps required to get a working iOS Build and potentially yield further issues to implement engine-side improvements for that.

I guess @Ali-RS already had Graal Native image running?

Edit: Potentially even running some example in Github Actions to verify all the issues from https://hub.jmonkeyengine.org/t/native-compilation-graalvm-native-image/43820/ don't arise

MeFisto94 avatar Sep 30 '21 08:09 MeFisto94

Atm, I do not have GraalVM installed. My experience with Graal was with a non-JME hello world sample on Linux but it was from long ago.

One of the restrictions of GraalVM native-image on mobile is that at the moment it only supports 64bit phones.

There are two Gradle plugins for using GraalVM native-image.

https://github.com/graalvm/native-build-tools (Java)

or

https://github.com/gluonhq/gluonfx-gradle-plugin (Java/JavaFX)

I guess the most complicated part is with writing the configuration files. For auto-generating configuration files for JNI, Reflection,... they have developed a tracing agent. (have not used). It runs the app in a regular JVM and detects the JNI, Reflection,... configuration at runtime. This might be feasible for a desktop app with LWJGL backend but I am not sure how we can run tracing agent with GLES backend on Mac to create the correct JNI configuration file for iOS!

Ali-RS avatar Sep 30 '21 11:09 Ali-RS

About 6 months ago, I invested quite a bit a time in trying to get jme graalvm images to build. I never was actually successful. Some of the LWJGL magic was causing is to explode. Iirc I may have a slightly older forum post about it. If someone can get it working even for a desktop build of jme I would love to know.

tlf30 avatar Nov 13 '21 19:11 tlf30

There is a Graal VM example using LibGdx + LWJGL which might worth looking. https://github.com/ByerN/libgdx-graalvm-example

Also, note that for iOS we do not require LWJGL.

Ali-RS avatar Nov 14 '21 05:11 Ali-RS

By the way, there is also RoboVM https://github.com/MobiVM/robovm But I do not know if they support newer java language features.

Edit: https://github.com/MobiVM/robovm/discussions/582

Ali-RS avatar Mar 23 '23 11:03 Ali-RS

Hi guys!

I got some spare time and managed to get a simple jme3.6.1 app to compile and run successfully with graalvm's native image. I've uploaded the sample to github so you can have a look: https://github.com/joliver82/jme3-graalvm-sample-project

Although this is a good first step forward, iOS compatibility will require a lot more work to be done, at least:

  • Recover and update (if required) jme-ios and the native code previously hosted at both jme3 and jme3-sdk repos
  • Create both the java lib and natives from them
  • Add to graalvm's native-image configurations most (if not all) jni calls for iOS in jni-config.json and also the dylibs in resource-config.json
  • Modify gradle to create ios binary instead of current desktop os and arch and use the new libraries

Once these tasks are accomplished I think we should be able to have a graalvm ios build and run it on a device.

I'm not sure what will happen regarding touch input, device rotation and maybe other stuff. Previously it was managed in https://github.com/jMonkeyEngine/sdk/blob/v3.2/jme3-ios/ios-data/templates/project/jme-ios/jmeAppDelegate.m getting the events from native and sending them to the jme harness

joliver82 avatar Sep 20 '23 14:09 joliver82

That's encouraging.

stephengold avatar Sep 20 '23 17:09 stephengold