ajalt / mordant

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

Support raw mode for posix in native image #186

Closed hubvd closed 3 months ago

hubvd commented 3 months ago

The issue with Expected Object but got Word when compiling the native image comes from the fact that the kotlin compiler insert null checks if the used types are not nullable.

For example, if we declare tcgetattr as

@CFunction("tcgetattr")
external fun tcgetattr(fd: Int, termios: termios): Int

Every call to it will be compiled as

Intrinsics.checkNotNull(termios);
tcgetattr(..., termios);

It is possible to disable those checks with the following compiler parameters: -Xno-param-assertions, -Xno-call-assertions,-Xno-receiver-assertions.

But in this case, it is enough to simply mark the termios parameter as nullable.

hubvd commented 3 months ago

My bad for not mentioning this in the initial native-image PR, it also took me quite a while to figure this out. I don't have a windows computer setup right now, but if you want, I can try to check the windows part this weekend ?

ajalt commented 3 months ago

Amazing! I have no idea how you figured this out. Thank you!

The tests are failing because a struct definition is wrong on macos, but that's my fault, not yours. I'll merge now and fix it is a separate PR.