tjammer / raylib-ocaml

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

dune utop fails in cloned git repo and merlin does not know raylib types #31

Closed nilsbecker closed 1 year ago

nilsbecker commented 1 year ago

not sure if this is a bug or user error.

to expore raylib-ocaml, i cloned the repo, then updated the raylib submodule by git submodule --update remote. i then descend into examples/shaders and open one of them in my editor (vim). merlin shows types for the imported Ctypes functions but not for the raylib types. after dune build from the examples directory or from the project root, nothing changes, also --profile=release does not change the lack of typing info.

i also tried launching utop by dune utop in the examples/shaders directory. this aborts with a bunch of c compiler warnings.

what am i missing?

macos.

nilsbecker commented 1 year ago

similarly, dune exec ./shaders_mesh_instanced.exe fails from within the examples/shaders subdir. first error from dune's output:


11 |   (names c_generated_functions c_generated_math c_generated_rlgl)
              ^^^^^^^^^^^^^^^^^^^^^
c_generated_functions.c:224:10: warning: initializing 'char *' with an expression of type 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
   char* x150 = GetMonitorName(x147);```
nilsbecker commented 1 year ago

update: the merlin issues went away for reasons unknown to me; dune utop and dune exec continue to fail.

tjammer commented 1 year ago

Which OCaml version are you on? I rarely use the repl, but I just installed utop and dune utop works for me. Both from the repo root and well as from examples/shaders. The Raylib module is loaded and tab-completion works. Executing the examples also works, both dune exec -- examples/shaders/shaders_mesh_instanced.exe (where the assets cannot be found), and from the correct location. The example works just fine.

So I'm not sure what's going on. I suspect a problem at your side. Can you successfully build the repo (just dune build) from the repo root? If you're unlucky it's a macos problem. I'm using linux, on OCaml 4.14

tjammer commented 1 year ago

similarly, dune exec ./shaders_mesh_instanced.exe fails from within the examples/shaders subdir. first error from dune's output:

11 |   (names c_generated_functions c_generated_math c_generated_rlgl)
              ^^^^^^^^^^^^^^^^^^^^^
c_generated_functions.c:224:10: warning: initializing 'char *' with an expression of type 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
   char* x150 = GetMonitorName(x147);```

What you are seeing is just a warning, not an error. There are a couple of these issues in the auto-generated C code, mostly .-Wdiscarded-qualifiers and -Wincompatible-pointer-types. I always ignore them. The build should succeed regardless.

Another thing: If you're building the whole repo, you need a couple of extra dependencies for raylib-gen. This is a small utility I use in generating the binding code, but don't distribute to opam. Try installing `containers, re and yojson

nilsbecker commented 1 year ago

hmm. the opam packages you mentioned were already installed. so i tried again doing dune clean from the project root. then, git status says this:

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)
    modified:   ../../src/c/vendor/raygui (new commits)
    modified:   ../../src/c/vendor/raylib (new commits, modified content)

after updating git submodules as described above.

i then try to dune build the whole project. this fails with errors. what i pasted before was not the relevant bit it seems. here is the first error:

File "src/c/dune", line 182, characters 0-222:
182 | (rule
183 |  (targets generate_raygui_types_step_2.exe)
184 |  (deps
185 |   (:c raygui_c_generated_types.c))
186 |  (action
187 |   (bash
188 |    "%{cc} %{c} -I '%{lib:ctypes:.}' -I %{ocaml_where} -I vendor/raylib/src -I vendor/raygui/src -o %{targets}")))
raygui_c_generated_types.c:90:51: error: use of undeclared identifier 'LIST_ITEMS_PADDING'
     enum { check_LIST_ITEMS_PADDING_const = (int)LIST_ITEMS_PADDING };
                                                  ^
raygui_c_generated_types.c:91:19: error: use of undeclared identifier 'LIST_ITEMS_PADDING'; did you mean 'LIST_ITEMS_SPACING'?

is it suspicious that this is from the raygui submodule? maybe i have updated that to a commit that is not compatible to raylib 4.2? how can i make sure i have the right version of raygui?

then follow a lot of more errors with functions containing PADDING until: fatal error: too many errors emitted, stopping now [-ferror-limit=].

further down some more errors: c_generated_functions.c:2613:4: error: implicit declaration of function 'DrawTextureQuad' is invalid in C99 [-Werror,-Wimplicit-function-declaration] DrawTextureQuad(x2582, x2585, x2588, x2591, x2594); and similar.

the dune exec calls you mentioned also fail. the first error is the 'DrawTextureQuad' is invalid in C99 one from above.

tjammer commented 1 year ago

It could be an issue with the submodules. "new commits" usually means that they are not up to date. Try git submodule update --init --recursive or manually check them out at the correct commit.

edit: As an alternative, the opam package (https://github.com/tjammer/raylib-ocaml/releases/download/0.6.0/raylib-0.6.0.tbz) already contains the two submodules, so you should be able to just dune build after extracting

nilsbecker commented 1 year ago

yes! that did it. (the submodule command above). lots of warnings but no errors. thanks!