Dune developer preview: ocamllsp cannot read stdlib.cmi (corrupted compiled interface)
Expected Behavior
ocamllsp works
Actual Behavior
ocamllsp fails.
Reproduction
- PR with a reproducing test:
- Follow steps at https://preview.dune.build/ to install dune and a build a hello world project. This builds an OCaml 5.2.1.
- Run 'ocamllsp'. This downloads an ocamlformat and ocamllsp for 5.2.1, but it is a binary download for the musl toolchain (the one built by dune previously was using a GCC toolchain).
- Run an editor (e.g. Helix, or probably any other editor), and observe the error message.
Specifications
- Version of
dune(output ofdune --version):
- "Dune Developer Preview: build 2024-12-18T09:09:58Z, git revision
3fc17eec135ab67a514c1cbb02182f7bccf6d042"
-
Version of
ocaml(output ofocamlc --version) 4.14.0 (not relevant, because dune builds its own) -
Operating system (distribution and version):
Additional information
I think this is because ocamllsp is a binary download built using the musl toolchain, and the hello world project uses a locally built OCaml compiler. Obviously interface hashes won't agree between the two, since it is a different compiler.
I assume ocamllsp would have to be built instead of downloaded as binary, since the musl version doesn't appear to be truly portable yet if it can only parse a musl based compiler.
ocamllsp
Locking dev-tools.locks/ocamlformat: Updating package repos "binary-packages", " Locking dev-tools.locks/ocamlformat: Updating package repos "binary-packages", " Locking dev-tools.locks/ocamlformat: Updating package repos "binary-packages", " Locking dev-tools.locks/ocamlformat: Updating package repos "binary-packages", " Locking dev-tools.locks/ocamlformat: Updating package repos "binary-packages", " Locking dev-tools.locks/ocamlformat: Updating package repos "binary-packages", " Locking dev-tools.locks/ocamlformat: Updating package repos "binary-packages", " Locking dev-tools.locks/ocamlformat: Updating package repos "binary-packages", " Locking dev-tools.locks/ocamlformat: Updating package repos "binary-packages", " Solution for dev-tools.locks/ocamlformat:
- ocamlformat.0.27.0+binary-ocaml-5.2.1-built-2024-12-04.0-x86_64-unknown-linux-musl
Downloading ocamlformat.0.27.0+binary-ocaml-5.2.1-built-2024-12-04.0-x86_64-unknown-linux-musl
Building ocamlformat.0.27.0+binary-ocaml-5.2.1-built-2024-12-04.0-x86_64-unknown-linux-musl
Running 'ocamlformat --help'
Locking dev-tools.locks/ocaml-lsp-server: Updating package repos "binary-package Locking dev-tools.locks/ocaml-lsp-server: Updating package repos "binary-package Locking dev-tools.locks/ocaml-lsp-server: Updating package repos "binary-package Locking dev-tools.locks/ocaml-lsp-server: Updating package repos "binary-package Locking dev-tools.locks/ocaml-lsp-server: Updating package repos "binary-package Locking dev-tools.locks/ocaml-lsp-server: Updating package repos "binary-package Solution for dev-tools.locks/ocaml-lsp-server:
- ocaml.5.2.1
- ocaml-base-compiler.5.2.1
- ocaml-config.3
- ocaml-lsp-server.1.20.1+binary-ocaml-5.2.1-built-2024-12-12.0-x86_64-unknown-linux-musl
Downloading ocaml-lsp-server.1.20.1+binary-ocaml-5.2.1-built-2024-12-12.0-x86_64-unknown-linux-musl
Building ocaml-lsp-server.1.20.1+binary-ocaml-5.2.1-built-2024-12-12.0-x86_64-unknown-linux-musl
Running 'ocamllsp'
dune pkg lock
Solution for dune.lock:
- ocaml.5.2.1
- ocaml-base-compiler.5.2.1
- ocaml-config.3
⌛10s edwin ~/h/hello_world [default] ❯ dune exec "$PROJECT"
Downloading ocaml-base-compiler.5.2.1
Building ocaml-base-compiler.5.2.1
Hello, World!
- Link to gist with verbose output (run
dunewith the--verboseflag):
Not sure how to best capture the error from the LSP in a text form, so here is a screenshot of the error.
Thanks for the report! I was hoping that using a different linker between ocamllsp and the code being analyzed wouldn't be an issue but I might be wrong. Can you share what linux distro/version you're using so I can try setting up a similar environment in docker to reproduce/investigate.
I think this error is a symptom of the fact that dune will install a binary version of the ocaml-lsp-server package by default. Even though dune makes sure that the instance of ocamllsp that it installs was compiled with the same version of the ocaml compiler as your project, it seems that for reasons I don't understand there is still an incompatibility between the ocamllsp binary and the compiled ocaml code that it's analyzing.
A workaround is to get dune to build ocamllsp from source rather than using the binary release. Place the following in a file named dune-workspace at the root of your project:
(lang dune 3.16)
(lock_dir
(path "dev-tools.locks/ocaml-lsp-server")
(repositories upstream overlay))