ajalt / mordant

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

[GraalVM] Static image with `musl libc` fails with `error: ‘struct termios’ has no member named ‘c_ispeed’` #189

Closed sureshg closed 2 months ago

sureshg commented 2 months ago

I do have a sample GraalVM native image project to create a static image with musl libc. Recently the build started failing (not sure if it's because of any change in GH Action env or updating to the latest dependency 2.7.1) with the following error message (com.github.ajalt.mordant.internal.syscalls.nativeimage.LinuxLibC$termios.getC_ispeed())

[1/8] Initializing...                                                                                    (0.0s @ 0.11GB)
Error: Error compiling query code (in /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c). Compiler command '/opt/hostedtoolcache/x86_64-linux-musl-native/10.2.1/x64/bin/x86_64-linux-musl-gcc -Wall -Werror --static -o /tmp/SVM-13769868978469610973/LinuxLibC_Directives /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c' output included error: /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:44:173: error: ‘struct termios’ has no member named ‘c_ispeed’; did you mean ‘__c_ispeed’?
    C file contents around line 44:
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:43:     }
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:44:     printf("NativeCodeInfo:LinuxLibC_Directives:StructInfo:struct_termios:StructFieldInfo:c_ispeed:PropertyInfo:size=%lu\n", ((unsigned long)sizeof(((struct termios *) 0)->c_ispeed)));
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:45:     printf("NativeCodeInfo:LinuxLibC_Directives:StructInfo:struct_termios:StructFieldInfo:c_ispeed:PropertyInfo:offset=%lu\n", ((unsigned long)offsetof(struct termios, c_ispeed)));
Error: Error compiling query code (in /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c). Compiler command '/opt/hostedtoolcache/x86_64-linux-musl-native/10.2.1/x64/bin/x86_64-linux-musl-gcc -Wall -Werror --static -o /tmp/SVM-13769868978469610973/LinuxLibC_Directives /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c' output included error: /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:45:169: error: ‘struct termios’ has no member named ‘c_ispeed’; did you mean ‘__c_ispeed’?
    method com.github.ajalt.mordant.internal.syscalls.nativeimage.LinuxLibC$termios.getC_ispeed()
    C file contents around line 45:
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:44:     printf("NativeCodeInfo:LinuxLibC_Directives:StructInfo:struct_termios:StructFieldInfo:c_ispeed:PropertyInfo:size=%lu\n", ((unsigned long)sizeof(((struct termios *) 0)->c_ispeed)));
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:45:     printf("NativeCodeInfo:LinuxLibC_Directives:StructInfo:struct_termios:StructFieldInfo:c_ispeed:PropertyInfo:offset=%lu\n", ((unsigned long)offsetof(struct termios, c_ispeed)));
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:46:     {
Error: Error compiling query code (in /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c). Compiler command '/opt/hostedtoolcache/x86_64-linux-musl-native/10.2.1/x64/bin/x86_64-linux-musl-gcc -Wall -Werror --static -o /tmp/SVM-13769868978469610973/LinuxLibC_Directives /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c' output included error: /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:51:21: error: ‘struct termios’ has no member named ‘c_ispeed’; did you mean ‘__c_ispeed’?
    C file contents around line 51:
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:50:         memset(&fieldHolder, 0x0, sizeof(fieldHolder));
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:51:         fieldHolder.c_ispeed = all_bits_set;
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:52:         is_unsigned = fieldHolder.c_ispeed > 0;
Error: Error compiling query code (in /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c). Compiler command '/opt/hostedtoolcache/x86_64-linux-musl-native/10.2.1/x64/bin/x86_64-linux-musl-gcc -Wall -Werror --static -o /tmp/SVM-13769868978469610973/LinuxLibC_Directives /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c' output included error: /tmp/SVM-[137](https://github.com/sureshg/native-image-playground/actions/runs/10119212190/job/27987310517#step:4:138)69868978469610973/LinuxLibC_Directives.c:52:35: error: ‘struct termios’ has no member named ‘c_ispeed’; did you mean ‘__c_ispeed’?
    C file contents around line 52:
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:51:         fieldHolder.c_ispeed = all_bits_set;
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:52:         is_unsigned = fieldHolder.c_ispeed > 0;
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:53:         printf("NativeCodeInfo:LinuxLibC_Directives:StructInfo:struct_termios:StructFieldInfo:c_ispeed:PropertyInfo:signedness=$%s$\n", (is_unsigned) ? "UNSIGNED" : "SIGNED");
Error: Error compiling query code (in /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c). Compiler command '/opt/hostedtoolcache/x86_64-linux-musl-native/10.2.1/x64/bin/x86_64-linux-musl-gcc -Wall -Werror --static -o /tmp/SVM-13769868978469610973/LinuxLibC_Directives /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c' output included error: /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:88:173: error: ‘struct termios’ has no member named ‘c_ospeed’; did you mean ‘__c_ospeed’?
    C file contents around line 88:
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:87:     }
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:88:     printf("NativeCodeInfo:LinuxLibC_Directives:StructInfo:struct_termios:StructFieldInfo:c_ospeed:PropertyInfo:size=%lu\n", ((unsigned long)sizeof(((struct termios *) 0)->c_ospeed)));
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:89:     printf("NativeCodeInfo:LinuxLibC_Directives:StructInfo:struct_termios:StructFieldInfo:c_ospeed:PropertyInfo:offset=%lu\n", ((unsigned long)offsetof(struct termios, c_ospeed)));
Error: Error compiling query code (in /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c). Compiler command '/opt/hostedtoolcache/x86_64-linux-musl-native/10.2.1/x64/bin/x86_64-linux-musl-gcc -Wall -Werror --static -o /tmp/SVM-13769868978469610973/LinuxLibC_Directives /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c' output included error: /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:89:169: error: ‘struct termios’ has no member named ‘c_ospeed’; did you mean ‘__c_ospeed’?
    method com.github.ajalt.mordant.internal.syscalls.nativeimage.LinuxLibC$termios.getC_ospeed()
    C file contents around line 89:
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:88:     printf("NativeCodeInfo:LinuxLibC_Directives:StructInfo:struct_termios:StructFieldInfo:c_ospeed:PropertyInfo:size=%lu\n", ((unsigned long)sizeof(((struct termios *) 0)->c_ospeed)));
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:89:     printf("NativeCodeInfo:LinuxLibC_Directives:StructInfo:struct_termios:StructFieldInfo:c_ospeed:PropertyInfo:offset=%lu\n", ((unsigned long)offsetof(struct termios, c_ospeed)));
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:90:     {
Error: Error compiling query code (in /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c). Compiler command '/opt/hostedtoolcache/x86_64-linux-musl-native/10.2.1/x64/bin/x86_64-linux-musl-gcc -Wall -Werror --static -o /tmp/SVM-13769868978469610973/LinuxLibC_Directives /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c' output included error: /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:95:21: error: ‘struct termios’ has no member named ‘c_ospeed’; did you mean ‘__c_ospeed’?
    C file contents around line 95:
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:94:         memset(&fieldHolder, 0x0, sizeof(fieldHolder));
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:95:         fieldHolder.c_ospeed = all_bits_set;
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:96:         is_unsigned = fieldHolder.c_ospeed > 0;
Error: Error compiling query code (in /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c). Compiler command '/opt/hostedtoolcache/x86_64-linux-musl-native/10.2.1/x64/bin/x86_64-linux-musl-gcc -Wall -Werror --static -o /tmp/SVM-13769868978469610973/LinuxLibC_Directives /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c' output included error: /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:96:35: error: ‘struct termios’ has no member named ‘c_ospeed’; did you mean ‘__c_ospeed’?
    C file contents around line 96:
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:95:         fieldHolder.c_ospeed = all_bits_set;
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:96:         is_unsigned = fieldHolder.c_ospeed > 0;
    /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:97:         printf("NativeCodeInfo:LinuxLibC_Directives:StructInfo:struct_termios:StructFieldInfo:c_ospeed:PropertyInfo:signedness=$%s$\n", (is_unsigned) ? "UNSIGNED" : "SIGNED");
Internal exception: com.oracle.svm.core.util.UserError$UserException: Error compiling query code (in /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c). Compiler command '/opt/hostedtoolcache/x86_64-linux-musl-native/10.2.1/x64/bin/x86_64-linux-musl-gcc -Wall -Werror --static -o /tmp/SVM-13769868978469610973/LinuxLibC_Directives /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c' output included error: /tmp/SVM-13769868978469610973/LinuxLibC_Directives.c:44:173: error: ‘struct termios’ has no member named ‘c_ispeed’; did you mean ‘__c_ispeed’?
    C file contents around line 44:

Native image builds with mordant are working fine on all other platforms (Windows/Linux/Mac)

ajalt commented 2 months ago

Hm, is there a way to change the struct definition based on the linked libc? c_ispeed and c_ospeed are required on the standard gnu libc, so I don't think there's a single struct definition that works on both.

sureshg commented 2 months ago

is there a way to change the struct definition based on the linked libc?

Sorry, I don't know how to do that. A quick search showed a similar issue on OpenJDK - https://bugs.openjdk.org/browse/JDK-8308544 As per this issue both c_ispeed and c_ospeed are not Posix standard and not available on musl - https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/termios.h.html

sureshg commented 2 months ago

@hubvd @ajalt You folks are awesome, and thanks for fixing the issue. Build is green on all platforms now 👍🏼