What are the limits and prerequisites of using dependencies with melange?

I am trying to explore melange. But I am quite confused about its prerequisites, and neither the issues, documentation, or repo have been able to clarify for me so far.

When I try to define a simple skeleton application using melange, any dependency I add in the libraries field of my dune stanza seems to be missing when I try to build. As a simple example,

Given

let ex = CCList.map (fun x -> x) [1;2;3]

With the stanza

(library
 (name melange_ex)
 (libraries containers)
 (modes melange best))

And the file

let () =
  let _ = Melange_ex.ex in
  print_endline "Hello, World!"

With the stanza

(melange.emit
 (target output)
 (libraries melange_ex))

dune build tells me things like

File "./_opam/lib/either/dune-package", line 27, characters 0-697:
27 | (library
28 |  (name either)
29 |  (kind normal)
....
51 |       (visibility public)
52 |       (source (path Either_intf) (impl (path either_intf.ml))))))
53 |    (wrapped true))))
Error: File unavailable:
./_opam/lib/either/melange/either__Either_intf.cmj
-> required by _build/default/bin/output/node_modules/either/either_intf.js
-> required by alias bin/all
-> required by alias default
File "lib/melange_ex.ml", line 1, characters 9-19:
1 | let ex = CCList.map (fun x -> x) [1;2;3]
             ^^^^^^^^^^
Error: Unbound module CCList

Is the implication that melange cannot be used with most ocaml libraries?
Is there some additional configuration needed?
How does one know what can or cannot be used with melange?

Thanks in advance for any tips!

bumping this thread because I would also like to know.

Hi,

Dune libraries that support Melange currently need to be explicitly annotated with (modes melange), or (modes :standard melange) if they’re also compatible with OCaml.

The reason why this is needed is because when installing the library, Dune needs to know if it has to generate rules to build Melange artifacts, which differ slightly from OCaml ones.

Besides this, any library that depends on C libraries or other platform specific code (like unix) won’t work in Melange (this is the same limitation as Js_of_ocaml).

The approach we are following to make existing libraries compatible with Melange is to fork the repository where the library is defined to add or update the library modes field, you can see an example of such modification in this patch to ppx_deriving runtime lib.

Another thing to note, as can be seen in that diff, is that supporting Melange involves raising the lower boundary of the OCaml compiler to at least 4.14, which some maintainers (understandably) don’t want to do.

We are still trying to improve this workflow and make things easier for both authors and users of Melange packages, a related thread can be found in melange -- option to enable melange mode only if melange is installed · Issue #7939 · ocaml/dune · GitHub.

Hope this helps!