Skip to content

Inconsistent behaviour for virtual libraries using melange mode #7104

@rizo

Description

@rizo

Expected Behavior

When creating a virtual library in native or byte modes, it is possible to assign a module to be virtual and add an implementation and interface that wraps around the virtual module in the virtual library.

Specifically the following structure illustrates this:

- vlib/
  - virt.mli     # virtual module
  - vlib.mli     # interface of vlib
  - vlib.ml      # implementation of vlib (uses virt!)
- vlib_impl_1/
  - virt.ml      # implementation of the virt module for vlib

This works as expected in native and byte modes and allows providing multiple implementations for virt.mli while offering a high-level interface in vlib.mli.

This doesn't work in melange mode.

Actual Behavior

This doesn't work when (modes melange) is used. Not only it is not possible to replicate the described workflow, but having (modes melange) also prevents the non-melange implementation to be compiled.

Error when compiling a melange target:

$ dune build @melange
File "vlib/vlib.ml", line 1:        
Error: Virt not found, it means either the module does not exist or it is a namespace

Additionally, if (modes melange) is present in vlib, the native compilation fails with:

File "src/dune_rules/virtual_rules.ml", line 11, characters 30-37:
Error: No rule found for vlib/.vlib.objs/byte/virt.cmi
File "src/dune_rules/virtual_rules.ml", line 11, characters 30-37:
Error: No rule found for vlib/.vlib.objs/byte/vlib.cmi
File "src/dune_rules/virtual_rules.ml", line 11, characters 30-37:
Error: No rule found for vlib/.vlib.objs/byte/vlib.cmo
File "src/dune_rules/virtual_rules.ml", line 11, characters 30-37:
Error: No rule found for vlib/.vlib.objs/native/vlib.cmx
File "src/dune_rules/virtual_rules.ml", line 11, characters 30-37:
Error: No rule found for vlib/.vlib.objs/native/vlib.o

Reproduction

The following repository fully replicates the above scenario based on the blackbox test included in dune:

Specifications

  • Version of dune: ~3.7 05797cd3f505beca4d6d62c576506d7608a6d29d
  • Version of melange: f4ddebbc7755af5e983c4df2ac51498f286e1074
  • Version of ocaml: 4.14.0
  • Operating system (distribution and version): 22.3.0 Darwin

Metadata

Metadata

Assignees

No one assigned

    Labels

    melangeMelange rules and generator

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions