Dune: Two executables stanza

Created on 14 Mar 2017  路  7Comments  路  Source: ocaml/dune

I tried to duplicate the hello_world example twice with the following jbuild file:

(executables
 ((names (hello_world))
))

(executables
 ((names (hello_world2))
))

But I obtained an error because of multiple rules generated:

{$HOME/.opam/4.02.3/bin/ocamlopt.opt, _build/default/.merlin-exists, _build/default/hello_world2.cmi, _build/default/hello_world2.depends.sexp, _build/default/hello_world2.ml, _build/default/hello_world2.requires.sexp} -> {_build/default/hello_world2.cmx, _build/default/hello_world2.o}
{$HOME/.opam/4.02.3/bin/ocamlopt.opt, _build/default/.merlin-exists, _build/default/hello_world.depends.sexp, _build/default/hello_world.requires.sexp, _build/default/hello_world2.cmi, _build/default/hello_world2.ml} -> {_build/default/hello_world2.cmx, _build/default/hello_world2.o}
Multiple rules generated for _build/default/hello_world2.o

Is it supported to have multiple executables rules?

Most helpful comment

I think this should be better explained in the quickstart. It is rather common to have several executables and the error thrown by jbuilder is rather cryptic when one starts with it.

All 7 comments

Yes, but you need to tell Jbuilder the list of modules each stanza refer to using (modules (...)) fields. I think this is described in the manual

Oh yes it is indeed said, sorry. I didn't get that the default modules list is all the files in the filesystem and not empty.

Perhaps it can be mentioned in the quick-start guide, as a second example or a side note that if hello_world.ml depends on another module it is not needed (as in ocamlbuild) to specify it in the module list (what I did).

Thanks!

Just for reference:

(executables (
 (names (hello_world))
 (modules (hello_world))
))

(executables (
  (names (hello_world2))
  (modules (hello_world2))
))

Perhaps it can be mentioned in the quick-start guide, as a second example or a side note that if hello_world.ml depends on another module it is not needed (as in ocamlbuild) to specify it in the module list (what I did)

Actually if you use an explicit (modules (...)) field, you do need to specify such modules inside the (modules (...)) field so that jbuilder knows how to setup compilation for this module. Different stanzas might use different flags, have different dependencies, etc...

In general, it is recommended to have one library or executables stanza per directory. For the current example, you can simply write:

(executables (
 (names (hello_world hello_world2))
))

I think this should be better explained in the quickstart. It is rather common to have several executables and the error thrown by jbuilder is rather cryptic when one starts with it.

Anyone can create a PR for the docs, I think :D

Santa added a PR for this issue: https://github.com/janestreet/jbuilder/pull/386

Was this page helpful?
0 / 5 - 0 ratings