fusesource / jansi

Jansi is a small java library that allows you to use ANSI escape sequences to format your console output which works even on windows.
http://fusesource.github.io/jansi/
Apache License 2.0
1.1k stars 139 forks source link

Add support for statically linking Jansi JNI library #246

Open rsenden opened 1 year ago

rsenden commented 1 year ago

We have a picocli-based application for which we build native images for Windows, Linux & MacOS using GraalVM. For various reasons, we build a statically linked executable for Linux, and dynamically linked executables for Windows/MacOS.

We would like to add Jansi (and JLine) to our application. Jansi 2.4.0 works just fine for our dynamically linked executables, however it fails to load the native jansi library in the statically linked executable because musl apparently doesn't support dynamic library loading (see https://github.com/oracle/graal/issues/4028#issue-1055983935):

open("/tmp", O_RDONLY|O_LARGEFILE|O_CLOEXEC|O_DIRECTORY) = 4
open("/tmp/jansi-2.4.0-83026643492bd4eb-libjansi.so.lck", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 4
open("/tmp/jansi-2.4.0-83026643492bd4eb-libjansi.so", O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE, 0666) = 4
open("/tmp/jansi-2.4.0-83026643492bd4eb-libjansi.so", O_RDONLY|O_LARGEFILE) = 4
Failed to load native library:jansi-2.4.0-83026643492bd4eb-libjansi.so. osinfo: Linux/x86_64
java.lang.UnsatisfiedLinkError: Can't load library: /tmp/jansi-2.4.0-83026643492bd4eb-libjansi.so

Apart from this issue, it's also just more logical to statically link the Jansi library when building native images, to avoid dynamic extraction of the library to a temporary directory and then loading it.

Based on what I've read so far, I think the following would be needed:

For reference, some links related to statically linking JNI libraries:

xtaixe commented 1 year ago

+1. We are also facing this issue.

gnodet commented 1 year ago

A PR would be welcomed @rsenden

Glavo commented 9 months ago

Let me give it a try, I'm doing some work on this.

rsenden commented 9 months ago

Thanks for looking into this!

On Thu, Sep 28, 2023, 19:58 Glavo @.***> wrote:

Let me give it a try, I'm doing some work on this.

— Reply to this email directly, view it on GitHub https://github.com/fusesource/jansi/issues/246#issuecomment-1739777950, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACB4GAQBMK4QAN5UWKDWZXTX4W3EHANCNFSM6AAAAAATDB4VSU . You are receiving this because you were mentioned.Message ID: @.***>

gnodet commented 9 months ago

@Glavo you're still planning to work on this feature ? If that's the case, I can wait a bit before starting a 2.5.0 release.

Glavo commented 9 months ago

@Glavo you're still planning to work on this feature ? If that's the case, I can wait a bit before starting a 2.5.0 release.

I don't think it can be done in a short time. If I don't find a workaround, I need to wait for GraalVM to solve #7507, or give up on what I'm trying and explore something else.

Glavo commented 9 months ago

hmm, I found another easier way. I'll give it a quick try and if it works I'll report the results here.

Glavo commented 9 months ago

@gnodet I think #269 is more promising, please wait for me.