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

R8/Proguard rules don't match `2.2.0`'s code #130

Closed mateuszkwiecinski closed 11 months ago

mateuszkwiecinski commented 11 months ago

I'm using mordant via clikt and its latest release 4.2.1 pulls the most recent mordant version which according to what I saw started providing their own Proguard/R8 rules (πŸš€). Unfortunately the rules were not updated to match latest code changes, and the build now fails with

Error: Missing class com.oracle.svm.core.annotate.Delete (referenced from: com.github.ajalt.mordant.internal.jna.JnaLinuxMppImpls and 5 other contexts)
Missing class org.graalvm.nativeimage.Platform$LINUX (referenced from: com.github.ajalt.mordant.internal.nativeimage.NativeImagePosixMppImpls and 1 other context)
Missing class org.graalvm.nativeimage.Platform$MACOS (referenced from: com.github.ajalt.mordant.internal.nativeimage.NativeImagePosixMppImpls and 1 other context)
Missing class org.graalvm.nativeimage.Platform$WINDOWS (referenced from: com.github.ajalt.mordant.internal.nativeimage.NativeImageWin32MppImpls and 1 other context)
Missing class org.graalvm.nativeimage.Platforms (referenced from: com.github.ajalt.mordant.internal.nativeimage.NativeImagePosixMppImpls and 3 other contexts)
Missing class org.graalvm.nativeimage.StackValue (referenced from: kotlin.Pair com.github.ajalt.mordant.internal.nativeimage.NativeImagePosixMppImpls.getTerminalSize() and 3 other contexts)
Missing class org.graalvm.nativeimage.c.CContext$Directives (referenced from: com.github.ajalt.mordant.internal.nativeimage.PosixLibC$Directives and 1 other context)
Missing class org.graalvm.nativeimage.c.CContext (referenced from: com.github.ajalt.mordant.internal.nativeimage.PosixLibC and 1 other context)
Missing class org.graalvm.nativeimage.c.constant.CConstant (referenced from: int com.github.ajalt.mordant.internal.nativeimage.PosixLibC.STDIN_FILENO() and 4 other contexts)
Missing class org.graalvm.nativeimage.c.function.CFunction (referenced from: int com.github.ajalt.mordant.internal.nativeimage.PosixLibC.ioctl(int, int, com.github.ajalt.mordant.internal.nativeimage.PosixLibC$winsize) and 4 other contexts)
Missing class org.graalvm.nativeimage.c.struct.CField (referenced from: short com.github.ajalt.mordant.internal.nativeimage.PosixLibC$winsize.getWs_col() and 5 other contexts)
Missing class org.graalvm.nativeimage.c.struct.CStruct (referenced from: com.github.ajalt.mordant.internal.nativeimage.PosixLibC$winsize and 1 other context)
Missing class org.graalvm.nativeimage.c.type.CIntPointer (referenced from: boolean com.github.ajalt.mordant.internal.nativeimage.NativeImageWin32MppImpls.stdinInteractive() and 2 other contexts)
Missing class org.graalvm.word.PointerBase (referenced from: kotlin.Pair com.github.ajalt.mordant.internal.nativeimage.NativeImagePosixMppImpls.getTerminalSize() and 8 other contexts)
Compilation failed

So I guess grallvm-related references should be kept somehow too? I'm not sure how they are used, so maybe ignoring them is the proper choice (-dontwarn org.graalvm.**)?

If needed, failing build can be found here: https://github.com/usefulness/diffuse/actions/runs/6421384714/job/17435616654?pr=238 build scan: https://scans.gradle.com/s/fkzlsu76u35ce/console-log?anchor=162&page=1

ajalt commented 11 months ago

Those classes are compileOnly, so I'm not sure why proguard is complaining. Can you try adding the dontwarn rule to your build to see if it passes?

mateuszkwiecinski commented 11 months ago

I'm far from understanding R8 internals, but I believe the compileOnly dependency is exactly the reason why R8 cannot access and read the class, so it is unable to check how mordant classes interact with them to establish if they can be removed from final jar πŸ‘€

I added -dontwarns and it passed the build :)