ocaml / dune

A composable build system for OCaml.
https://dune.build/
MIT License
1.64k stars 409 forks source link

Vendored libraries are not linked statically to public libraries that use them #5301

Open vch9 opened 2 years ago

vch9 commented 2 years ago

Hello, I'm having an issue about the git submodules installation with opam. This is more certainly an issue on my side but I come here to ask for your help, feel free to close if you do not have the time and/or do not want to look at this :).

I am writing a library and executable with dune:

(library
 (public_name ometrics.core)
 ...

; and
(executable
 (public_name ometrics)
 ...

I am now trying to install this in another project by doing:

opam pin add ometrics git+https://gitlab.com/nomadic-labs/ometrics.git#battle-test

The executable ometrics works fine but if I try to use the library ometrics.core as a dependency I get:

10 |  (requires unix str merlin.kernel merlin.analysis)
                                       ^^^^^^^^^^^^^^^
Error: Library "merlin.analysis" not found.
-> required by library "ometrics.core" in
   /home/valentin/Documents/ometrics/merbocop/_opam/lib/ometrics/core
Hint: try:
  dune external-lib-deps --missing @@default

which is the library introduced by my submodule. Can the git submodules work as well for libraries ?

The project for reference: https://gitlab.com/nomadic-labs/ometrics/-/tree/snapshot-issue and my opam version:

$ opam --version
2.0.5
kit-ty-kate commented 2 years ago

It looks like the problem is not with opam (which pulls git submodules just fine) but with dune. Libraries marked as public, linked with a vendored libraries will be installed but not linked statically to the vendored library. So apparently dune creates an external dependency for those, which seems like a bug to me.

Moving to the dune bugtracker and renaming the title.

jumpnbrownweasel commented 1 year ago

I think the problem I have with vendoring may be related. When vendoring a library I have to remove the dune-project file from the vendored library directory. Otherwise I also get the "Error: Library "..." not found." when building. Is this the same problem?

The only example of vendoring I could find is in Dune itself. And I noticed that the vendored libraries do not have dune-project files. If this is a requirement, please document it. I couldn't find anything in the docs about it.