tjammer / raylib-ocaml

OCaml bindings for raylib and raygui
https://tjammer.github.io/raylib-ocaml/
MIT License
175 stars 14 forks source link

raygui bindings broken #42

Closed lessismordaunt closed 6 months ago

lessismordaunt commented 6 months ago

The raygui bindings seems either unmaintained or just broken:

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
⬇ retrieved raygui.0.6.0  (https://opam.ocaml.org/cache)
[ERROR] The compilation of raygui.0.6.0 failed at "dune build -p raygui -j 11 @install".

#=== ERROR while compiling raygui.0.6.0 =======================================#
# context     2.1.5 | linux/x86_64 | ocaml.5.1.1 | https://opam.ocaml.org#ec28f29e
# path        ~/.opam/default/.opam-switch/build/raygui.0.6.0
# command     ~/.opam/opam-init/hooks/sandbox.sh build dune build -p raygui -j 11 @install
# exit-code   1
# env-file    ~/.opam/log/raygui-40827-7d9e2c.env
# output-file ~/.opam/log/raygui-40827-7d9e2c.out
### output ###
# 164 |   (names c_generated_gui)
# [...]
# (cd _build/default/src/c && /usr/bin/gcc -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -D_FILE_OFFSET_BITS=64 -O2 -fno-strict-aliasing -fwrapv -pthread -fPIC -g -I /home/<redacted>/.opam/default/lib/ocaml -I /home/<redacted>/.opam/default/lib/bigarray-compat -I /home/<redacted>/.opam/default/lib/ctypes -I /home/<redacted>/.opam/default/lib/ctypes/stubs -I /home/benja[...]
# c_generated_gui.c: In function ‘raygui_stub_37_GuiListViewEx’:
# c_generated_gui.c:378:35: error: passing argument 2 of ‘GuiListViewEx’ from incompatible pointer type [-Wincompatible-pointer-types]
#   378 |    int x405 = GuiListViewEx(x395, x396, x397, x400, x401, x402);
#       |                                   ^~~~
#       |                                   |
#       |                                   char **
# In file included from c_generated_gui.c:3:
# vendor/raygui/src/raygui.h:2724:50: note: expected ‘const char **’ but argument is of type ‘char **’
#  2724 | int GuiListViewEx(Rectangle bounds, const char **text, int count, int *focus, int *scrollIndex, int active)
#       |                                     ~~~~~~~~~~~~~^~~~

<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ λ build raygui 0.6.0
└─ 
╶─ No changes have been performed
tjammer commented 6 months ago

They're neither unmaintained nor just broken. The issue is that as of now, ocaml-ctypes does not support cv-qualifiers. Thus, strings in binding code are always char* instead of const char*, which leads to a warning (-Wincompatible-pointer-types). There is a issue in the ctypes repo, which goes back to 2014 (https://github.com/yallop/ocaml-ctypes/issues/134).

Recently, gcc14 turned this warning into an error (see https://gcc.gnu.org/gcc-14/porting_to.html#warnings-as-errors). Am I correct in assuming that's the version you are on?

Unfortunately, I don't know how to work around this without explicit support for const in ctypes. In another issue, the author called the warning "unavoidable" (for now, https://github.com/fdopen/ppx_cstubs/pull/6#issuecomment-898294186). Maybe we could patch raygui to change the declaration.. I'll see if this is feasible.

Until then, you could try to compile with an older version of gcc.

tjammer commented 6 months ago

Patching raygui seems to work. The last commit should build for you. I'll leave the issue open until I have published the fix on opam.