ajalt / mordant

Multiplatform text styling for Kotlin command-line applications
https://ajalt.github.io/mordant/
Apache License 2.0
957 stars 34 forks source link

Use the C API in native images #119

Closed hubvd closed 11 months ago

hubvd commented 1 year ago

Closes https://github.com/ajalt/mordant/issues/112

This fixes some issues when using mordant in a GraalVM Native Image. (More details in the commits)

I tested this on Linux x64 and Windows x64 but I don't have access to MacOS for testing. So maybe we would still need to fallback to stty if it doesn't work.

I also added a commit with the native-build-tools. With the GRAALVM_HOME variable set, we can build a binary by running ./gradlew native:nativeCompile. This commit can be removed when the PR is ready to be merged.

cmdjulian commented 11 months ago

I did try out your branch. I'm on Linux amd64. When using

val exportProgress = terminal.progressAnimation {
    percentage()
    progressBar()
    completed()
    speed("layers/s")
    timeRemaining()
}

exportProgress.start()
exportProgress.updateTotal(1)
exportProgress.advance(1)
exportProgress.stop()

I get the following error:

    0%  ????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????     0.0/---.-   ---.-layers/s  eta -:--:--

[ [ SubstrateSegfaultHandler caught a segfault in thread 0x00007f085c000b80 ] ]
siginfo: si_signo: 11, si_code: 1, si_addr: 0x000000000023f3c0

Current timestamp: 1694856861850

General purpose register values:
  RAX 0x000000000023f3c0 is an unknown value
  RBX 0x0000000000000000 
  RCX 0xffffffffffffff20 is an unknown value
  RDX 0x00007f083035abd0 is an unknown value
  RBP 0x00007f085c002650 is an unknown value
  RSI 0x00000000042f014d is an unknown value
  RDI 0x0000000000000000 
  RSP 0x00007f0883ffd448 points into the stack for thread 0x00007f085c000b80
  R8  0x000000000000021e is an unknown value
  R9  0x00000000069682ac is an unknown value
  R10 0x00007f083020bea8 is an unknown value
  R11 0x0000000000000206 is an unknown value
  R12 0x00007f085c002650 is an unknown value
  R13 0x0000000000000001 is an unknown value
  R14 0x00007f085c0011e0 is an unknown value
  R15 0x0000000000000005 is an unknown value
  EFL 0x0000000000010246 is an unknown value
  RIP 0x00007f0830237246 is an unknown value

Printing Instructions (ip=0x00007f0830237246):
  0x00007f0830237226: 0x66 0x2e 0x0f 0x1f 0x84 0x00 0x00 0x00 0x00 0x00 0xf3 0x0f 0x1e 0xfa 0x48 0x8b
  0x00007f0830237236: 0x05 0xb5 0x6c 0x20 0x00 0x48 0x8b 0x0d 0xb6 0x6a 0x20 0x00 0x64 0x48 0x8b 0x00
  0x00007f0830237246: 0x48 0x8b 0x00 0x48 0x8b 0x70 0x38 0x48 0x8d 0x96 0x00 0x01 0x00 0x00 0x64 0x48
  0x00007f0830237256: 0x89 0x11 0x48 0x8b 0x78 0x40 0x48 0x8b 0x0d 0x85 0x6d 0x20 0x00 0x48 0x8d 0x97

Top of stack (sp=0x00007f0883ffd448):
  0x00007f0883ffd448: 0x00007f083035abf0 0x0000000000000005
  0x00007f0883ffd458: 0x00000000042c1172 0x00007f085c002650
  0x00007f0883ffd468: 0x33c21478f8ec9400 0x00007f0883ffd7b0
  0x00007f0883ffd478: 0x000000000427e59f 0x0000000000000000
  0x00007f0883ffd488: 0x0000000000000000 0x0000000007f8b540
  0x00007f0883ffd498: 0x0000000000000063 0x0000000000000000
  0x00007f0883ffd4a8: 0x0000000000000040 0x0000007000000101
  0x00007f0883ffd4b8: 0x00007f0883ffd7b0 0x00007f0883ffd790
  0x00007f0883ffd4c8: 0x0000000000000000 0x00007f0883ffd610
  0x00007f0883ffd4d8: 0x000000000426e5ae 0x0000000007f842e0
  0x00007f0883ffd4e8: 0x00000000042852c8 0x00007f0883ffd610
  0x00007f0883ffd4f8: 0x00007f0883ffd690 0x000000000427deb0
  0x00007f0883ffd508: 0x00007f0883ffd7b0 0x00000000000000ff
  0x00007f0883ffd518: 0x000000000421aa16 0x00007f0883ffd610
  0x00007f0883ffd528: 0x00007f0883ffd51c 0x00007f0883ffd7b0
  0x00007f0883ffd538: 0x6e0ba27fe5d0d1f7 0xfffffffffffffff8
  0x00007f0883ffd548: 0x00007f0883ffd610 0x000000000426e5ae
  0x00007f0883ffd558: 0x0000000007f842e0 0x6e0ba27fe310d1f7
  0x00007f0883ffd568: 0x901aadd0ef92d1f7 0x0000000000000000
  0x00007f0883ffd578: 0x0000000000000000 0x0000000000000049
  0x00007f0883ffd588: 0x0000000000000000 0x0000000000000008
  0x00007f0883ffd598: 0x000000006464bda5 0x0000000015c19c1b
  0x00007f0883ffd5a8: 0x0000000063d97f49 0x0000000000000000
  0x00007f0883ffd5b8: 0x00000000640644b3 0x00000000048effdb
  0x00007f0883ffd5c8: 0x0000000000000000 0x0000000000000000
  0x00007f0883ffd5d8: 0x0000000000000000 0x0000000000000000
  0x00007f0883ffd5e8: 0x33c21478f8ec9400 0x00007f085c000eb0
  0x00007f0883ffd5f8: 0x33c21478f8ec9400 0x0000000007f84260
  0x00007f0883ffd608: 0x000000000427d859 0x00007f085c000eb0
  0x00007f0883ffd618: 0x000000005c000eb0 0x0000000000020000
  0x00007f0883ffd628: 0x0000000000001000 0x00007f085c000eb0
  0x00007f0883ffd638: 0xfffffffffffffffe 0x00007f0883ffd790

Top frame info:
  Does not look like a Java Frame. Use JavaFrameAnchors to find LastJavaSP:
  Found matching Anchor:0x00007f0883ffe620
  LastJavaSP 0x00007f0883ffe600
  LastJavaIP 0x000000000227d8a0

Threads:
  0x00007f07f4000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-35" - 0x00007f087ac01160, daemon, stack(0x00007f0831ffe000,0x00007f08327fd000)
  0x00007f0808000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-32" - 0x00007f08b9453328, daemon, stack(0x00007f0833801000,0x00007f0834000000)
  0x00007f0804000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-24" - 0x00007f087b401060, daemon, stack(0x00007f08627ff000,0x00007f0862ffe000)
  0x00007f07fc000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-34" - 0x00007f087a201060, daemon, stack(0x00007f08327ff000,0x00007f0832ffe000)
  0x00007f080c000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-30" - 0x00007f0879e01130, daemon, stack(0x00007f0860ffc000,0x00007f08617fb000)
  0x00007f0828000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-31" - 0x00007f087a401030, daemon, stack(0x00007f08607fb000,0x00007f0860ffa000)
  0x00007f0824000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-27" - 0x00007f0878101060, daemon, stack(0x00007f08317fd000,0x00007f0831ffc000)
  0x00007f082c000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-26" - 0x00007f0878301060, daemon, stack(0x00007f08617fd000,0x00007f0861ffc000)
  0x00007f0814000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-23" - 0x00007f087b201060, daemon, stack(0x00007f0863000000,0x00007f08637ff000)
  0x00007f081c000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-29" - 0x00007f087b601060, daemon, stack(0x00007f08307fb000,0x00007f0830ffa000)
  0x00007f0818000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-28" - 0x00007f0880001060, daemon, stack(0x00007f0830ffc000,0x00007f08317fb000)
  0x00007f0820000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-33" - 0x00007f087a001060, daemon, stack(0x00007f0833000000,0x00007f08337ff000)
  0x00007f0838000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-25" - 0x00007f08b944f340, daemon, stack(0x00007f0861ffe000,0x00007f08627fd000)
  0x00007f0834000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-22" - 0x00007f087b001060, daemon, stack(0x00007f0863801000,0x00007f0864000000)
  0x00007f0848000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-21" - 0x00007f08b944afb0, daemon, stack(0x00007f08817fd000,0x00007f0881ffc000)
  0x00007f0840000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-20" - 0x00007f0880e01030, daemon, stack(0x00007f0880ffc000,0x00007f08817fb000)
  0x00007f0850000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "Timer-1" - 0x00007f08b94462c0, stack(0x00007f0881ffe000,0x00007f08827fd000)
  0x00007f083c000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "process reaper" - 0x00007f08c4103048, daemon, stack(0x00007f08c4a41000,0x00007f08c4a6e000)
  0x00007f0844000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "process reaper" - 0x00007f08c4103388, daemon, stack(0x00007f08c4a70000,0x00007f08c4a9d000)
  0x00007f084c000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "process reaper" - 0x00007f08c41035c8, daemon, stack(0x00007f08c4c90000,0x00007f08c4cbd000)
  0x00007f0854000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-17" - 0x00007f08c4103840, daemon, stack(0x00007f087b801000,0x00007f087c000000)
  0x00007f085c000b80 STATUS_IN_JAVA (PREVENT_VM_FROM_REACHING_SAFEPOINT) "DefaultDispatcher-worker-16" - 0x00007f08c4103a78, daemon, stack(0x00007f0883801000,0x00007f0884000000)
  0x00007f0868000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-18" - 0x00007f08c4103cb0, daemon, stack(0x00007f0883000000,0x00007f08837ff000)
  0x00007f0858000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-19" - 0x00007f08c4103ee8, daemon, stack(0x00007f08827ff000,0x00007f0882ffe000)
  0x00007f087c000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-12" - 0x00007f08c4104120, daemon, stack(0x00007f08adffe000,0x00007f08ae7fd000)
  0x00007f0888000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-4" - 0x00007f08c4104358, daemon, stack(0x00007f08b65fe000,0x00007f08b6dfd000)
  0x00007f086c000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-11" - 0x00007f08c4104590, daemon, stack(0x00007f08ae7ff000,0x00007f08aeffe000)
  0x00007f0864000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-13" - 0x00007f08c41047c8, daemon, stack(0x00007f08ad7fd000,0x00007f08adffc000)
  0x00007f0874000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-15" - 0x00007f08c4104a00, daemon, stack(0x00007f08ac7fb000,0x00007f08acffa000)
  0x00007f08a0000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-9" - 0x00007f08c4104c38, daemon, stack(0x00007f08af801000,0x00007f08b0000000)
  0x00007f0884000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-14" - 0x00007f08c4104e70, daemon, stack(0x00007f08acffc000,0x00007f08ad7fb000)
  0x00007f088c000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-3" - 0x00007f08c41050a8, daemon, stack(0x00007f08b6dff000,0x00007f08b75fe000)
  0x00007f08a4000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-5" - 0x00007f08c41052e0, daemon, stack(0x00007f08b5dfd000,0x00007f08b65fc000)
  0x00007f0894000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-6" - 0x00007f08c4105518, daemon, stack(0x00007f08b55fc000,0x00007f08b5dfb000)
  0x00007f0890000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-2" - 0x00007f08c4105750, daemon, stack(0x00007f08b7600000,0x00007f08b7dff000)
  0x00007f089c000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-7" - 0x00007f08c4102e10, daemon, stack(0x00007f08b4dfb000,0x00007f08b55fa000)
  0x00007f0898000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-10" - 0x00007f08c4105988, daemon, stack(0x00007f08af000000,0x00007f08af7ff000)
  0x00007f08a8000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-8" - 0x00007f08c4105bc0, daemon, stack(0x00007f08b45fa000,0x00007f08b4df9000)
  0x00007f08b0000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "DefaultDispatcher-worker-1" - 0x00007f08c4105df8, daemon, stack(0x00007f08b7e01000,0x00007f08b8600000)
  0x00007f08c0000b80 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "Reference Handler" - 0x00007f08c8a63248, daemon, stack(0x00007f08c5f01000,0x00007f08c6700000)
  0x0000000009e946c0 STATUS_IN_NATIVE (ALLOW_SAFEPOINT) "main" - 0x00007f08c8a63090, stack(0x00007ffc29781000,0x00007ffc29f7f000)

VM thread locals for the failing thread 0x00007f085c000b80:
  0 (8 bytes): JNIThreadLocalEnvironment.jniFunctions = (bytes) 
    0x00007f085c000b80: 0x00007f08c7d0a010
  8 (8 bytes): StackOverflowCheckImpl.stackBoundaryTL = (Word) 1 (0x0000000000000001)
  16 (4 bytes): Safepoint.safepointRequested = (int) 2147434695 (0x7fff40c7)
  20 (4 bytes): StatusSupport.statusTL = (int) 1 (0x00000001)
  24 (32 bytes): ThreadLocalAllocation.regularTLAB = (bytes) 
    0x00007f085c000b98: 0x00007f0880c00000 0x00007f0880d00000
    0x00007f085c000ba8: 0x00007f0880c15020 0x0000000000000000
  56 (8 bytes): PlatformThreads.currentThread = (Object) kotlinx.coroutines.scheduling.CoroutineScheduler$Worker (0x00007f08c4103a78)
  64 (8 bytes): JavaFrameAnchors.lastAnchor = (Word) 139674551051808 (0x00007f0883ffe620)
  72 (8 bytes): PlatformThreads.currentVThreadId = (long) 72 (0x0000000000000048)
  80 (8 bytes): AccessControlContextStack = (Object) java.util.ArrayDeque (0x00007f0880c0e710)
  88 (8 bytes): ExceptionUnwind.currentException = (Object) null
  96 (8 bytes): IdentityHashCodeSupport.hashCodeGeneratorTL = (Object) null
  104 (8 bytes): IsolatedCompileClient.currentClient = (Object) null
  112 (8 bytes): IsolatedCompileContext.currentContext = (Object) null
  120 (8 bytes): JNIObjectHandles.handles = (Object) com.oracle.svm.core.handles.ThreadLocalHandles (0x00007f0880c13a30)
  128 (8 bytes): JNIThreadLocalPendingException.pendingException = (Object) null
  136 (8 bytes): JNIThreadLocalPinnedObjects.pinnedObjectsListHead = (Object) null
  144 (8 bytes): JNIThreadOwnedMonitors.ownedMonitors = (Object) null
  152 (8 bytes): NoAllocationVerifier.openVerifiers = (Object) null
  160 (8 bytes): ThreadingSupportImpl.activeTimer = (Object) null
  168 (8 bytes): SubstrateDiagnostics.threadOnlyAttachedForCrashHandler = (bytes) 
    0x00007f085c000c28: 0x0000000000000000
  176 (8 bytes): ThreadLocalAllocation.allocatedBytes = (Word) 256 (0x0000000000000100)
  184 (8 bytes): VMThreads.IsolateTL = (Word) 139675667791872 (0x00007f08c6900000)
  192 (8 bytes): VMThreads.OSThreadHandleTL = (Word) 139674551055936 (0x00007f0883fff640)
  200 (8 bytes): VMThreads.OSThreadIdTL = (Word) 139674551055936 (0x00007f0883fff640)
  208 (8 bytes): VMThreads.StackBase = (Word) 139674551058432 (0x00007f0884000000)
  216 (8 bytes): VMThreads.StackEnd = (Word) 139674542673920 (0x00007f0883801000)
  224 (8 bytes): VMThreads.StartedByCurrentIsolate = (bytes) 
    0x00007f085c000c60: 0x0000000000000001
  232 (8 bytes): VMThreads.nextTL = (Word) 139674081299328 (0x00007f0868000b80)
  240 (8 bytes): VMThreads.unalignedIsolateThreadMemoryTL = (Word) 139673879972704 (0x00007f085c000b60)
  248 (4 bytes): ActionOnExitSafepointSupport.actionTL = (int) 0 (0x00000000)
  252 (4 bytes): ActionOnTransitionToJavaSupport.actionTL = (int) 0 (0x00000000)
  256 (4 bytes): ImplicitExceptions.implicitExceptionsAreFatal = (int) 0 (0x00000000)
  260 (4 bytes): StackOverflowCheckImpl.yellowZoneStateTL = (int) 2130640638 (0x7efefefe)
  264 (4 bytes): StatusSupport.safepointBehaviorTL = (int) 1 (0x00000001)
  268 (4 bytes): ThreadingSupportImpl.currentPauseDepth = (int) 0 (0x00000000)

No VMOperation in progress

The 15 most recent VM operation status changes (oldest first):
  1694856860119 - Started Garbage collection (safepoint: true, queueingThread: 0x0000000009e946c0, executingThread: 0x0000000009e946c0, safepointId: 1)
  1694856860155 - Finished Garbage collection (safepoint: true, queueingThread: 0x0000000009e946c0, executingThread: 0x0000000009e946c0, safepointId: 1)
  1694856860202 - Started Garbage collection (safepoint: true, queueingThread: 0x0000000009e946c0, executingThread: 0x0000000009e946c0, safepointId: 2)
  1694856860218 - Finished Garbage collection (safepoint: true, queueingThread: 0x0000000009e946c0, executingThread: 0x0000000009e946c0, safepointId: 2)
  1694856860302 - Started Garbage collection (safepoint: true, queueingThread: 0x0000000009e946c0, executingThread: 0x0000000009e946c0, safepointId: 3)
  1694856860310 - Finished Garbage collection (safepoint: true, queueingThread: 0x0000000009e946c0, executingThread: 0x0000000009e946c0, safepointId: 3)
  1694856860473 - Started Garbage collection (safepoint: true, queueingThread: 0x00007f08a4000b80, executingThread: 0x00007f08a4000b80, safepointId: 4)
  1694856860536 - Finished Garbage collection (safepoint: true, queueingThread: 0x00007f08a4000b80, executingThread: 0x00007f08a4000b80, safepointId: 4)
  1694856861377 - Started Garbage collection (safepoint: true, queueingThread: 0x00007f08b0000b80, executingThread: 0x00007f08b0000b80, safepointId: 5)
  1694856861406 - Finished Garbage collection (safepoint: true, queueingThread: 0x00007f08b0000b80, executingThread: 0x00007f08b0000b80, safepointId: 5)
  1694856861663 - Started Garbage collection (safepoint: true, queueingThread: 0x00007f089c000b80, executingThread: 0x00007f089c000b80, safepointId: 6)
  1694856861706 - Finished Garbage collection (safepoint: true, queueingThread: 0x00007f089c000b80, executingThread: 0x00007f089c000b80, safepointId: 6)
  1694856861779 - Started Garbage collection (safepoint: true, queueingThread: 0x00007f089c000b80, executingThread: 0x00007f089c000b80, safepointId: 7)
  1694856861802 - Finished Garbage collection (safepoint: true, queueingThread: 0x00007f089c000b80, executingThread: 0x00007f089c000b80, safepointId: 7)

Counters:

Java frame anchors for the failing thread 0x00007f085c000b80:
  Anchor 0x00007f0883ffe620 LastJavaSP 0x00007f0883ffe600 LastJavaIP 0x000000000227d8a0

Stacktrace for the failing thread 0x00007f085c000b80:
  SP 0x00007f0883ffd448 IP 0x00007f0830237246  IP is not within Java code. Trying frame anchor of last Java frame instead.
  SP 0x00007f0883ffe600 IP 0x000000000227d8a0  [image code] java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
  SP 0x00007f0883ffe650 IP 0x000000000228203b  [image code] java.net.InetAddress$PlatformNameService.lookupAllHostAddr(InetAddress.java:934)
  SP 0x00007f0883ffe670 IP 0x000000000228305b  [image code] java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1543)
  SP 0x00007f0883ffe6a0 IP 0x00000000022817e5  [image code] java.net.InetAddress$NameServiceAddresses.get(InetAddress.java:852)
  SP 0x00007f0883ffe710 IP 0x00000000022846f3  [image code] java.net.InetAddress.getAllByName0(InetAddress.java:1533)
  SP 0x00007f0883ffe760 IP 0x00000000022838f5  [image code] java.net.InetAddress.getAllByName(InetAddress.java:1385)
  SP 0x00007f0883ffe7b0 IP 0x0000000002289e6a  [image code] java.net.InetAddress.getAllByName(InetAddress.java:1306)
  SP 0x00007f0883ffe7b0 IP 0x0000000002289e6a  [image code] java.net.InetAddress.getByName(InetAddress.java:1256)
  SP 0x00007f0883ffe7b0 IP 0x0000000002289e6a  [image code] java.net.InetSocketAddress.<init>(InetSocketAddress.java:229)
  SP 0x00007f0883ffe7f0 IP 0x0000000003b974e0  [image code] sun.net.NetworkClient.doConnect(NetworkClient.java:178)
  SP 0x00007f0883ffe830 IP 0x0000000003bbd1eb  [image code] sun.net.www.http.HttpClient.openServer(HttpClient.java:533)
  SP 0x00007f0883ffe860 IP 0x0000000003bbce7c  [image code] sun.net.www.http.HttpClient.openServer(HttpClient.java:638)
  SP 0x00007f0883ffe8b0 IP 0x0000000003bef467  [image code] sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:266)
  SP 0x00007f0883ffe900 IP 0x0000000003bef9e6  [image code] sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:380)
  SP 0x00007f0883ffe970 IP 0x0000000003bee971  [image code] sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:193)
  SP 0x00007f0883ffe990 IP 0x0000000003be4eed  [image code] sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1242)
  SP 0x00007f0883ffea00 IP 0x0000000003be4719  [image code] sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1128)
  SP 0x00007f0883ffea20 IP 0x0000000003bee365  [image code] sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:179)
  SP 0x00007f0883ffea40 IP 0x0000000003bf30d5  [image code] sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:142)
  SP 0x00007f0883ffea50 IP 0x0000000000b578e9  [image code] com.github.kittinunf.fuel.toolbox.HttpClient.sendRequest(HttpClient.kt:145)
  SP 0x00007f0883ffeac0 IP 0x0000000000b550ad  [image code] com.github.kittinunf.fuel.toolbox.HttpClient.doRequest(HttpClient.kt:79)
  SP 0x00007f0883ffeaf0 IP 0x0000000000b5496f  [image code] com.github.kittinunf.fuel.toolbox.HttpClient.awaitRequest(HttpClient.kt:67)
  SP 0x00007f0883ffeb50 IP 0x0000000000b5285d  [image code] com.github.kittinunf.fuel.core.requests.SuspendableRequest.executeRequest(SuspendableRequest.kt:21)
  SP 0x00007f0883ffebb0 IP 0x0000000000b51955  [image code] com.github.kittinunf.fuel.core.requests.SuspendableRequest.awaitResult(SuspendableRequest.kt:40)
  SP 0x00007f0883ffec00 IP 0x0000000000b30f0c  [image code] com.github.kittinunf.fuel.core.DeserializableKt.awaitResponseResult(Deserializable.kt:276)
  SP 0x00007f0883ffec50 IP 0x00000000013b7c0b  [image code] de.cmdjulian.kirc.impl.ContainerRegistryApiImpl.manifests(ContainerRegistryApiImpl.kt:100)
  SP 0x00007f0883ffecd0 IP 0x00000000013be227  [image code] de.cmdjulian.kirc.impl.SuspendingContainerImageRegistryClientImpl.manifest(SuspendingContainerImageRegistryClientImpl.kt:60)
  SP 0x00007f0883ffed10 IP 0x00000000005666e3  [image code] com.etalytics.etadeploy.export.ContainerImagePullClientFactory.resolveManifest(ContainerImagePullClientFactory.kt:55)
  SP 0x00007f0883ffedd0 IP 0x0000000000565690  [image code] com.etalytics.etadeploy.export.ContainerImagePullClientFactory.create(ContainerImagePullClientFactory.kt:42)
  SP 0x00007f0883ffee30 IP 0x0000000000575b10  [image code] com.etalytics.etadeploy.export.ImageExporter$write$clients$1$1$1$1.invokeSuspend(ImageExporter.kt:96)
  SP 0x00007f0883ffee60 IP 0x000000000057581d  [image code] com.etalytics.etadeploy.export.ImageExporter$write$clients$1$1$1$1.invoke(ImageExporter.kt)
  SP 0x00007f0883ffee80 IP 0x00000000005756d9  [image code] com.etalytics.etadeploy.export.ImageExporter$write$clients$1$1$1$1.invoke(ImageExporter.kt)
  SP 0x00007f0883ffee90 IP 0x00000000005555b3  [image code] com.etalytics.etadeploy.core.utils.RetryKt.retry(Retry.kt:12)
  SP 0x00007f0883ffef00 IP 0x0000000000555e80  [image code] com.etalytics.etadeploy.core.utils.RetryKt.retry$default(Retry.kt:5)
  SP 0x00007f0883ffef30 IP 0x000000000057650c  [image code] com.etalytics.etadeploy.export.ImageExporter$write$clients$1$1$1.invokeSuspend(ImageExporter.kt:95)
  SP 0x00007f0883ffef60 IP 0x000000000284d83f  [image code] kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
  SP 0x00007f0883ffefc0 IP 0x0000000002cea4a4  [image code] kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
  SP 0x00007f0883fff050 IP 0x0000000002d27bd8  [image code] kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
  SP 0x00007f0883fff080 IP 0x0000000002d435cf  [image code] kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
  SP 0x00007f0883fff0a0 IP 0x0000000002d3fbc5  [image code] kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
  SP 0x00007f0883fff0b0 IP 0x0000000002d39b97  [image code] kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
  SP 0x00007f0883fff0e0 IP 0x0000000002d3a605  [image code] kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
  SP 0x00007f0883fff120 IP 0x0000000002d3a3f3  [image code] kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
  SP 0x00007f0883fff130 IP 0x0000000000ea46d3  [image code] com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:807)
  SP 0x00007f0883fff160 IP 0x0000000000e176a7  [image code] com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:210)
  SP 0x00007f0883fff180 IP 0x0000000000d87800  [image code] com.oracle.svm.core.code.IsolateEnterStub.PosixPlatformThreads_pthreadStartRoutine_cf47bd191b082a3631657d369b9255c828b9a95c(IsolateEnterStub.java:0)

VM mutexes:
  mutex "mainVMOperationControlWorkQueue" is unlocked.
  mutex "thread" is unlocked.
  mutex "referencePendingList" is unlocked.

AOT compiled code is mapped at 0x0000000000403000 - 0x00000000041d8e9f

Heap settings and statistics:
  Supports isolates: true
  Heap base: 0x00007f08c6900000
  Object reference size: 8
  Aligned chunk size: 1048576
  Incremental collections: 7
  Complete collections: 4

Native image heap boundaries:
  ReadOnly Primitives: 0x00007f08c6a01030 - 0x00007f08c7653da8
  ReadOnly References: 0x00007f08c7653da8 - 0x00007f08c7d09548
  ReadOnly Relocatables: 0x00007f08c7d0a000 - 0x00007f08c82d87c0
  Writable Primitives: 0x00007f08c82d9000 - 0x00007f08c88c9900
  Writable References: 0x00007f08c88c9900 - 0x00007f08c92a4d70
  Writable Huge: 0x00007f08c9300038 - 0x00007f08c9676ad8
  ReadOnly Huge: 0x00007f08c9677038 - 0x00007f08ca65cf00

Heap:
  Young generation: 
    Eden: 
      edenSpace:
        aligned: 0/0 unaligned: 0/0
    Survivors: 
      Survivor-1 From:
        aligned: 14680064/14 unaligned: 131088/1
        aligned chunks:
          0x00007f0871a00000 (0x00007f0871a01030-0x00007f0871afffe8)
          0x00007f0871800000 (0x00007f0871801030-0x00007f08718ffff8)
          0x00007f0871600000 (0x00007f0871601030-0x00007f08716fffe8)
          0x00007f0871400000 (0x00007f0871401030-0x00007f08714ff2a0)
          0x00007f0871200000 (0x00007f0871201030-0x00007f08712fffc8)
          0x00007f0871000000 (0x00007f0871001030-0x00007f08710fff20)
          0x00007f0870e00000 (0x00007f0870e01030-0x00007f0870f00000)
          0x00007f0870c00000 (0x00007f0870c01030-0x00007f0870cfffb8)
          0x00007f0870a00000 (0x00007f0870a01030-0x00007f0870affff8)
          0x00007f0870800000 (0x00007f0870801030-0x00007f08708fffd0)
          0x00007f0870600000 (0x00007f0870601030-0x00007f08706ffee0)
          0x00007f0870400000 (0x00007f0870401030-0x00007f0870500000)
          0x00007f0870200000 (0x00007f0870201030-0x00007f08702ffdf8)
          0x00007f0870000000 (0x00007f0870001030-0x00007f08700a5328)
        unaligned chunks:
          0x00007f08ca68c000 (0x00007f08ca68c038-0x00007f08ca6ac048)
      Survivor-1 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-2 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-2 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-3 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-3 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-4 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-4 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-5 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-5 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-6 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-6 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-7 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-7 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-8 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-8 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-9 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-9 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-10 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-10 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-11 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-11 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-12 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-12 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-13 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-13 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-14 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-14 To:
        aligned: 0/0 unaligned: 0/0
      Survivor-15 From:
        aligned: 0/0 unaligned: 0/0
      Survivor-15 To:
        aligned: 0/0 unaligned: 0/0
  Old generation: 
    oldFromSpace:
      aligned: 40894464/39 unaligned: 3627504/8
      aligned chunks:
        0x00007f08c4100000 (0x00007f08c4101030-0x00007f08c41ffff8)
        0x00007f08bb200000 (0x00007f08bb201030-0x00007f08bb2ffff0)
        0x00007f08bb000000 (0x00007f08bb001030-0x00007f08bb0fffe0)
        0x00007f08bae00000 (0x00007f08bae01030-0x00007f08baefffd0)
        0x00007f08bac00000 (0x00007f08bac01030-0x00007f08bad00000)
        0x00007f08baa00000 (0x00007f08baa01030-0x00007f08baafffd0)
        0x00007f08ba800000 (0x00007f08ba801030-0x00007f08ba8fffd0)
        0x00007f08ba600000 (0x00007f08ba601030-0x00007f08ba6ffff8)
        0x00007f08bc000000 (0x00007f08bc001030-0x00007f08bc0fffd8)
        0x00007f08bbe00000 (0x00007f08bbe01030-0x00007f08bbeffff8)
        0x00007f08bbc00000 (0x00007f08bbc01030-0x00007f08bbd00000)
        0x00007f08bba00000 (0x00007f08bba01030-0x00007f08bbb00000)
        0x00007f08bb800000 (0x00007f08bb801030-0x00007f08bb8fffd0)
        0x00007f08bb600000 (0x00007f08bb601030-0x00007f08bb6fffe8)
        0x00007f08bb400000 (0x00007f08bb401030-0x00007f08bb4fff98)
        0x00007f08c5d00000 (0x00007f08c5d01030-0x00007f08c5dfffb8)
        0x00007f08ba400000 (0x00007f08ba401030-0x00007f08ba4fff88)
        0x00007f08ba200000 (0x00007f08ba201030-0x00007f08ba2ffff8)
        0x00007f08ba000000 (0x00007f08ba001030-0x00007f08ba0ffff0)
        0x00007f08c5100000 (0x00007f08c5101030-0x00007f08c51fff88)
        0x00007f08c5300000 (0x00007f08c5301030-0x00007f08c53fffe8)
        0x00007f08bd600000 (0x00007f08bd601030-0x00007f08bd6fffe0)
        0x00007f08c5500000 (0x00007f08c5501030-0x00007f08c55ffff0)
        0x00007f08c5700000 (0x00007f08c5701030-0x00007f08c57fffa0)
        0x00007f08c5900000 (0x00007f08c5901030-0x00007f08c59ffff0)
        0x00007f08c5b00000 (0x00007f08c5b01030-0x00007f08c5bfffe0)
        0x00007f08b9a00000 (0x00007f08b9a01030-0x00007f08b9afffc8)
        0x00007f08b9800000 (0x00007f08b9801030-0x00007f08b98fffa8)
        0x00007f08b9600000 (0x00007f08b9601030-0x00007f08b96fffe0)
        0x00007f08b4400000 (0x00007f08b4401030-0x00007f08b44fffe0)
        0x00007f08b4200000 (0x00007f08b4201030-0x00007f08b42fff30)
        0x00007f08b4000000 (0x00007f08b4001030-0x00007f08b40ffee0)
        0x00007f08ac600000 (0x00007f08ac601030-0x00007f08ac6fffb8)
        0x00007f08ac400000 (0x00007f08ac401030-0x00007f08ac4fffc8)
        0x00007f08ac200000 (0x00007f08ac201030-0x00007f08ac2fffe8)
        0x00007f08ac000000 (0x00007f08ac001030-0x00007f08ac0fffe8)
        0x00007f08c6700000 (0x00007f08c6701030-0x00007f08c67fffd0)
        0x00007f08bfa00000 (0x00007f08bfa01030-0x00007f08bfaffeb0)
        0x00007f08bf800000 (0x00007f08bf801030-0x00007f08bf85c0d0)
      unaligned chunks:
        0x00007f087845d000 (0x00007f087845d038-0x00007f087863d340)
        0x00007f08c526a000 (0x00007f08c526a038-0x00007f08c529b948)
        0x00007f08c6880000 (0x00007f08c6880038-0x00007f08c68bed00)
        0x00007f08c5a1f000 (0x00007f08c5a1f038-0x00007f08c5a5dd00)
        0x00007f08c4edf000 (0x00007f08c4edf038-0x00007f08c4eff048)
        0x00007f08c4e17000 (0x00007f08c4e17038-0x00007f08c4e591a0)
        0x00007f08c5e16000 (0x00007f08c5e16038-0x00007f08c5e581a0)
        0x00007f08c4cbd000 (0x00007f08c4cbd038-0x00007f08c4cff1a0)
    oldToSpace:
      aligned: 0/0 unaligned: 0/0

  Unused:
    aligned: 0/0

Segfault detected, aborting process. Use '-XX:-InstallSegfaultHandler' to disable the segfault handler at run time and create a core dump instead. Rebuild with '-R:-InstallSegfaultHandler' to disable the handler permanently at build time.

Also mind the question marks for the progress bar chars. How could I assist here? Not much of a C / JNA guy myself.

hubvd commented 11 months ago

@cmdjulian I could not reproduce the issue. The stacktrace doesn't seem related to this PR. Do you have a sample project that you can share ? What version of GraalVM are you using ?

cmdjulian commented 11 months ago

@cmdjulian I could not reproduce the issue. The stacktrace doesn't seem related to this PR. Do you have a sample project that you can share ? What version of GraalVM are you using ?

Maybe it was related to the way I did replace the package in my build.gradle.kts file. I'm on GraalVM community version 17 the latest.

hubvd commented 11 months ago

Mmh, maybe. To use this PR in another gradle project, I did the following:

In the mordant repo:

./gradlew :mordant:publishKotlinMultiplatformPublicationToMavenLocal -PRELEASE_SIGNING_ENABLED=false ./gradlew :mordant:publishJvmPublicationToMavenLocal -PRELEASE_SIGNING_ENABLED=false

And in the project using mordant,

repositories {
    mavenCentral {
        mavenContent {
            excludeGroup("com.github.ajalt.mordant")
        }
    }
    mavenLocal {
        mavenContent {
            includeGroup("com.github.ajalt.mordant")
        }
    }
}
cmdjulian commented 11 months ago

Yep it works now, must have been my mistake. Thanks :)

Regarding Mac, static compile is currently not supported on it with Apple Silicon. However, for non static compile it does work. I had to let one of my coworkers check it out. Is there something else I can do in helping you in making this MR ready and getting merged? We're really looking forward into this getting merged and usable for one of our cli applications.

hubvd commented 11 months ago

Good news then :)

What do you think @ajalt, should I remove the sample commit and set this PR as ready ? Or is there any change I need to do ?

ajalt commented 11 months ago

If it's been tested on all three platforms, then that's great.

Do you know if it's feasible to set up graal on CI and use it to compile and run the test suite? That would certainly give me more confidence in it being correct.

hubvd commented 11 months ago

I tried a bit, and it is sadly not possible to apply the org.graalvm.buildtools.native plugin in the same subproject as a kotlin multiplatform one. It also requires java 11 and JUnit platform. What should possible though is to use the graalvm/setup-graalvm action to set the GRAALVM_HOME variable and run some tests in a subproject. I'm not sure what should be tested though, I guess instantiating a terminal and checking that it doesn't throw an error ?

ajalt commented 11 months ago

If a test submodule is our only option, then let's go with that and make a simple smoke test. I think the bulk of the code could be exercised by testing a progress animation and markdown rendering. Something like this:

class GraalSmokeTest {
    @Test
    fun `progress animation test`() {
        // Just make sure it doesn't crash, exact output is verified in the normal test suite
        val t = Terminal(interactive = true, ansiLevel = AnsiLevel.TRUECOLOR)
        val animation = t.progressAnimation { progressBar() }
        animation.start()
        Thread.sleep(100)
        animation.clear()
    }

    @Test
    fun `markdown test`() {
        val vt = TerminalRecorder()
        val t = Terminal(terminalInterface = vt)
        t.print(Markdown("- Some **bold** text"))
        assertEquals(" • Some ${bold("bold")} text", vt.output())
    }
}
ajalt commented 11 months ago

Thank you for all the work!

cmdjulian commented 11 months ago

Is there a date when you do create a new release of clikt including this new version here? @ajalt