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.
Desired Behavior
My use case is the following.
I have a library
lib1which is already implemented.I would like to have a library
lib2which contains the same modules aslib1but some hooks are added. However, becauselib1is evolving, I don't want to copy/paste the code oflib1intolib2instead, I would like toinclude lib1inlib2and change the linking process so that the modules included refers to the implementation oflib2and notlib1.I thought that
virtual_librariescould 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 withvirtual_librariesor the feature I want is different.Example
Assume the following structure:
where :
lib1/A.mlis implemented aslet foo = "foo"lib1/B.mlis implemented aslet bar = A.foolib2/A.mlis implemented aslet foo = "foo2"lib2/B.mlis implemented asinclude Lib1.Bbin/main.mlis implemented asFormat.printf "%s@." Lib2.B.barThe result when
mainis compiled as usual is"foo"but I would like to seefoo2instead.This is possible using
ocamlcby givinglib2/A.mlat the linking step, but I did not manage to do it withdune. One may found the current example in the following archive (using virtual libraries):link.tar.gz.