Skip to content

Include a module and change the implementation of its dependencies #3534

@francoisthire

Description

@francoisthire

Desired Behavior

My use case is the following.

I have a library lib1 which is already implemented.
I would like to have a library lib2 which contains the same modules as lib1 but some hooks are added. However, because lib1 is evolving, I don't want to copy/paste the code of lib1 into lib2 instead, I would like to include lib1 in lib2 and change the linking process so that the modules included refers to the implementation of lib2 and not lib1.

I thought that virtual_libraries could help me but I did a test and the behavior is not the one I expected. I don't really know whether I did something wrong with virtual_libraries or the feature I want is different.

Example

Assume the following structure:

|-- bin
|   |-- dune
|   `-- main.ml
|-- lib1
|   |-- A.ml
|   |-- B.ml
|   `-- dune
|-- lib2
|   |-- A.ml
|   |-- B.ml
|   `-- dune

where :

  • lib1/A.ml is implemented as let foo = "foo"
  • lib1/B.ml is implemented as let bar = A.foo
  • lib2/A.ml is implemented as let foo = "foo2"
  • lib2/B.ml is implemented as include Lib1.B
  • bin/main.ml is implemented as Format.printf "%s@." Lib2.B.bar

The result when main is compiled as usual is "foo" but I would like to see foo2 instead.
This is possible using ocamlc by giving lib2/A.ml at the linking step, but I did not manage to do it with dune. One may found the current example in the following archive (using virtual libraries):
link.tar.gz.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions