jabref icon indicating copy to clipboard operation
jabref copied to clipboard

Native compile [GraalVM]

Open calixtus opened this issue 1 year ago • 12 comments

Howto

  • Run gradle task nativeCompile.

Mandatory checks

  • [ ] Change in CHANGELOG.md described in a way that is understandable for the average user (if applicable)
  • [ ] Tests created for changes (if applicable)
  • [ ] Manually tested changed features in running JabRef (always required)
  • [ ] Screenshots added in PR description (for UI changes)
  • [ ] Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • [ ] Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

calixtus avatar May 17 '24 14:05 calixtus

image image

calixtus avatar May 17 '24 14:05 calixtus

Caused by: java.lang.module.InvalidModuleDescriptorException: Unsupported major.minor version 66.0

Siedlerchr avatar May 17 '24 15:05 Siedlerchr

Caused by: java.lang.module.InvalidModuleDescriptorException: Unsupported major.minor version 66.0

Uhoh. I went back to Java 21 in d39fb35 (#11298), because I didn't know why Java 22 should be important at this point in time.

koppor avatar May 18 '24 11:05 koppor

With Java 21, the image compiles fine, but cannot be started:

koppor@DESKTOP-KAK953S MINGW64 /c/git-repositories/jabref/build/native/nativeCompile (nativecompile)
$ ./JAbRef.exe
Messages are not initialized before accessing key: Display help on command line options
LOGGER ERROR: Service implementation 'org.tinylog.writers.ConsoleWriter' has no matching constructor
Exception in thread "main" java.lang.NullPointerException
        at org.jabref.logic.l10n.Localization.lookup(Localization.java:146)
        at org.jabref.logic.l10n.Localization.lang(Localization.java:58)
        at org.jabref.cli.JabRefCLI.getOptions(JabRefCLI.java:184)
        at org.jabref.cli.JabRefCLI.<init>(JabRefCLI.java:33)
        at org.jabref.Launcher.main(Launcher.java:59)
        at [email protected]/java.lang.invoke.LambdaForm$DMH/sa346b79c.invokeStaticInit(LambdaForm$DMH)

koppor avatar May 18 '24 11:05 koppor

Current hint:

// Source: https://github.com/tinylog-org/tinylog/issues/145#issuecomment-603430594
task generateConfiguration(type: Exec) {
    group = "graal"
    description = "Run application to generate the configuration for native image"
    dependsOn build
    commandLine project.gradle.gradleUserHomeDir.toPath().resolve("caches/com.palantir.graal/$graalVmVersion/graalvm-ce-$graalVmVersion/bin/java"), "-agentlib:native-image-agent=config-output-dir=" + project.buildDir.toPath().resolve("resources/main/META-INF/native-image"), "-cp", sourceSets.main.runtimeClasspath.getAsPath(), javaMainClass

    doFirst {
        mkdir project.buildDir.toPath().resolve("resources/main/META-INF/native-image")
    }
}

koppor avatar May 18 '24 11:05 koppor

Current hint

Requires palantir graal plugin for gradle

calixtus avatar May 18 '24 13:05 calixtus

Current hint

Requires palantir graal plugin for gradle

I don't think so. The path starts with plantir, but the content seems to be the real GraalVM. Thus, the paths "just" need to ne adapted to recent GraalVM.

koppor avatar May 18 '24 13:05 koppor

MWE project to try out a fix: https://github.com/shoneslab/graal-logging (referenced from https://github.com/tinylog-org/tinylog/issues/145#issuecomment-602885335)

koppor avatar May 19 '24 18:05 koppor

This needs to be adressed: https://github.com/oracle/graal/issues/7682

koppor avatar May 20 '24 20:05 koppor

https://thenewstack.io/how-to-build-with-graalvm-inside-github-actions/

calixtus avatar May 23 '24 05:05 calixtus

https://thenewstack.io/how-to-build-with-graalvm-inside-github-actions/

Doesn't use Toolchain. Think, we already managed to compile using GraalVM, but have issues with our file access

koppor avatar May 23 '24 10:05 koppor

Tinylog "official" "guide": https://github.com/tinylog-org/tinylog-graal-example

koppor avatar Jul 11 '24 12:07 koppor

The build of this PR is available at https://builds.jabref.org/pull/11298/merge.

github-actions[bot] avatar Jul 11 '24 12:07 github-actions[bot]

Current error:

Error: Error loading a referenced type: com.oracle.svm.hosted.substitute.DeletedElementException: Unsupported method jdk.internal.loader.NativeLibrary.findEntry0(long, String) is reachable
To diagnose the issue, you can add the option --report-unsupported-elements-at-runtime. The unsupported element is then reported at run time when it is accessed the first time.
Error encountered while parsing org.apache.lucene.store.PosixNativeAccess.lookupMadvise(PosixNativeAccess.java:87) 
Parsing context:
      141 types,   103 fields, and   138 methods registered for JNI access
        5 native libraries: crypt32, ncrypt, psapi, version, winhttp

------------------------------------------------------------------------------------------------------------------------
   at org.apache.lucene.store.PosixNativeAccess.<clinit>(PosixNativeAccess.java:67)
   at static root method.(Unknown Source)

koppor avatar Jul 11 '24 13:07 koppor

Might be related https://github.com/oracle/graal/issues/673

Siedlerchr avatar Jul 11 '24 16:07 Siedlerchr

https://www.graalvm.org/22.0/reference-manual/native-image/JNI/

https://github.com/amahfouz1/jna-graalvm

calixtus avatar Jul 11 '24 20:07 calixtus

At https://github.com/JabRef/jabref/pull/11510, we even introduced more reflection.

Closing and re-opening at koppor, because it will take more time.

koppor avatar Aug 04 '24 20:08 koppor