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

Split JVM syscall implemetations into separate modules, add FFM #200

Merged
merged 16 commits into from
Aug 18, 2024

Conversation

ajalt
Copy link
Owner

@ajalt ajalt commented Aug 11, 2024

No description provided.

@ajalt ajalt force-pushed the ffm-syscalls branch 2 times, most recently from 84eb06b to 44fa835 Compare August 11, 2024 16:54
@ajalt
Copy link
Owner Author

ajalt commented Aug 12, 2024

Hm, looks like the graal test isn't running on nativeimage, it's just the regular JVM. The only GHA change was to go from JDK 21 -> 22, so not sure why that would have broken...

@hubvd
Copy link
Contributor

hubvd commented Aug 14, 2024

It doesn't say much in the logs, but maybe it is because we're missing some --initialize-at-build-time flags
Those are also needed with Graal 21 if we enable the new behavior --strict-image-heap

I use those ones
https://github.com/hubvd/odoo-tools/blob/master/buildSrc/src/main/kotlin/NativeImageConvention.kt#L29-L33
(I guess those names are not up to date, for example com.github.ajalt.mordant.internal.syscalls.nativeimage.SyscallHandlerNativeImageLinux becomes com.github.ajalt.mordant.terminal.terminalinterface.TerminalInterfaceNativeImageLinux)

I haven't made a PR, as I'm not sure if we can pass every flag for every platform. If it's the case, we could add them to the native-image.properties.

If not, I guess we could implement org.graalvm.nativeimage.hosted.Feature

@hubvd
Copy link
Contributor

hubvd commented Aug 14, 2024

Ok, so It had nothing to do with that (even if the flags are still required)

The output when running locally is

GraalSmokeTest > terminal detection test() FAILED
    org.opentest4j.AssertionFailedError: Incorrect terminal interface: TerminalInterfaceJnaLinux
        at app//org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:38)
        at app//org.junit.jupiter.api.Assertions.fail(Assertions.java:138)
        at app//kotlin.test.junit5.JUnit5Asserter.fail(JUnitSupport.kt:56)
        at app//kotlin.test.AssertionsKt__AssertionsKt.fail(Assertions.kt:520)
        at app//kotlin.test.AssertionsKt.fail(Unknown Source)
        at app//com.github.ajalt.mordant.graalvm.GraalSmokeTest.terminal detection test(GraalSmokeTest.kt:28)

Since the test runs two times, we can do something like this #186 (comment)

But then I have another weird error


The build process encountered an unexpected error... :

> java.lang.IncompatibleClassChangeError: com.github.ajalt.mordant.terminal.terminalinterface.WinKernel32Lib and com.github.ajalt.mordant.terminal.terminalinterface.WinKernel32Lib$EventUnion disagree on InnerClasses attribute

I might do a PR tomorrow

@ajalt
Copy link
Owner Author

ajalt commented Aug 15, 2024

Thanks for looking into it! I implemented your suggestions, and ended up with the same error. The only lead I have right now is that the uChar and Event declarations are unions nested inside structs in C. Removing the CStruct annotations from those two interfaces is enough to get linux working, but that obviously breaks windows. I'll need to investigate some more.

@hubvd
Copy link
Contributor

hubvd commented Aug 15, 2024

I made a PR that should hopefully solve those issues #201

@ajalt ajalt marked this pull request as ready for review August 16, 2024 02:25
@ajalt ajalt force-pushed the ffm-syscalls branch 2 times, most recently from 8a79b21 to 0d1968e Compare August 18, 2024 01:13
@ajalt ajalt enabled auto-merge (rebase) August 18, 2024 01:16
ajalt and others added 13 commits August 17, 2024 18:32
Before the new native image default `--strict-image-heap`,
we used `--initialize-at-build-time=com.github.ajalt.mordant.internal.MppImplKt`
so that the os was resolved at build time and classes of other OS were
not used.

With the new default, we need to specify every class that needs to be
initialized from the initialized class.

It's also easy to move or introduce a new class and not keep the
configuration synced.

We now use @substitute + @platforms to get the expected behaviour

Substituting TerminalInterfaceProviderJna isn't really needed, but it
prevents the jna classes from being included in the final binary.

As for the Ffm provider, we need to disable it as it requires a build
flag `-H:+ForeignAPISupport` + some configuration and isn't supported
with GraalVM 21.
When compiling a native image, we get the following error:
> java.lang.IncompatibleClassChangeError: com.github.ajalt.mordant.terminal.terminalinterface.WinKernel32Lib and com.github.ajalt.mordant.terminal.terminalinterface.WinKernel32Lib$EventUnion disagree on InnerClasses attribute

There were multiple classes with the same package + name
We get the following warning when compile the native image:
-H:ResourceConfigurationResources': Use a resource-config.json in your META-INF/native-image/<groupID>/<artifactID> directory instead.
Since they are already in the right place, we can simply remove the
native-image.properties
@ajalt ajalt merged commit 7ca3db6 into master Aug 18, 2024
4 checks passed
@ajalt ajalt deleted the ffm-syscalls branch August 18, 2024 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants