dune icon indicating copy to clipboard operation
dune copied to clipboard

Module name conflict with vendored library

Open mbarbin opened this issue 11 months ago • 1 comments

Hello,

I'm encountering a module name conflict when trying to vendor a library into another repository. This issue arises when I attempt to compile a monorepo containing multiple projects.

Here's a brief description of my setup:

I've added the library my-vendored-lib into the vendor/ directory of my-repo.

File: repo/my-repo/vendor/my-vendored-lib/src/dune

(name my_vendored_lib)
(public_name my-repo-private-libs.my-vendored-lib)

The dune file in my-repo/vendor includes (vendored_dirs *).

The library my-vendored-lib is also present in the monorepo with its own dune configuration:

File: repo/my-vendored-lib/src/dune

(name my_vendored_lib)
(public_name my-vendored-lib)

In another project, repo/other-project, I have dependencies on both my-vendored-lib and my-repo.

When I attempt to compile other-project, I encounter the following OCaml compilation error:

File "_none_", line 1:
Error: Files repo/my-repo/vendor/my-vendored-lib/src/my_vendored_lib.cmxa
       and repo/my-vendored-lib/src/my_vendored_lib.cmxa
       both define a module named My_vendored_lib

If I remove the vendored library's public_name within my-repo

File: repo/my-repo/vendor/my-vendored-lib/src/dune

  (name my_vendored_lib)
- (public_name my-repo-private-libs.my-vendored-lib)

the error is this:

File "repo/my-repo/lib/my_repo/src/dune", line 16, characters 43-53:
16 |  (libraries my_vendored_lib)
                ^^^^^^^^^^^^^^^
Error: Library "my_vendored_lib" is private, it cannot be a dependency of a public
library. You need to give "my_vendored_lib" a public name.

By the way, how do you make it work in the code source of dune itself? It seems to me you do have some libraries inside vendor/ that do not have a public_name.

I am not sure whether the linking would work regardless of this private/public question. Perhaps it is not directly related.

I am using dune 3.14.0 and ocaml 5.1.1.

Is this a common issue when vendoring libraries with dune? If so, is there a recommended setup or workaround to avoid module name conflicts? Any guidance would be greatly appreciated.

Thank you for your time.

mbarbin avatar Mar 14 '24 11:03 mbarbin

I wanted to link a live example of the issue for reference: https://github.com/mbarbin/vcs/pull/2

In this PR, I've worked around the module name conflict by renaming the vendored libraries and prefixing them with the name of the enclosing project (example). For managing the actual vendoring, I was inspired by dune's update-*.sh pattern - Thanks!

I'm interested in hearing your thoughts on this approach and whether there's a more recommended way to handle such conflicts (such as a built-in solution or setting in dune that could help resolve this). Thank you!

mbarbin avatar Mar 21 '24 15:03 mbarbin