ocaml / dune

A composable build system for OCaml.
https://dune.build/
MIT License
1.63k stars 401 forks source link

Reusing the same modules for two different executable targets #1515

Closed XVilka closed 5 years ago

XVilka commented 5 years ago

For example I have some set of .ml and .mli files, which can form either a distributed node, or a standalone tool (mostly for testing). Lets say I have

I want to build two executables - one is "tool_node + some_file1 + some_file2 + some_file3", and another "tool_standalone + some_file1 + some_file2" (without "some_file3").

(executable
  (name tool_node)
  (preprocess (pps ppx_sexp_conv))
  (libraries base lwt something)
  (link_flags (-verbose -linkall))
  (modules (:standard \ tool_standalone)))

(executable
  (name tool_standalone)
  (preprocess (pps ppx_sexp_conv))
  (libraries base lwt something)
  (link_flags (-verbose -linkall))
  (modules tool_standalone))

(install
  (section bin)
  (files
    (tool_node.exe as tool_node)
    (tool_standalone.exe as tool_standalone)
  ))

But if I use let somevar = Some_file2.some_func (from "some_file2.ml" file) in the text of "tool_standalone.ml" - it complains about unbound module. Would be nice to allow dune handle this case.

nojb commented 5 years ago

The usual way to handle this is to make a library with the common parts (eg Some_file1 and Some_file2) and use the library from both executables.

rgrinberg commented 5 years ago

This is a duplicate of another issue and diml mentioned that we're not planning to change this.