ocaml / dune

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

(allow_empty) rules and messages are confusing #8352

Open askvortsov1 opened 1 year ago

askvortsov1 commented 1 year ago

I was trying to build https://github.com/TyOverby/sdui, and got the following error message:

Error: The package sdui does not have any user defined stanzas attached to
it. If this is intentional, add (allow_empty) to the package definition in
the dune-project file
-> required by _build/default/sdui.install
-> required by alias all
-> required by alias default

For context, the project consists of an executable compiled with (modes js)

There's a few issues here:

  1. (allow_empty) is not documented at all #5567, and is not highlighted/suggested by VSCode's dune syntax highlighting and autofill.
  2. The wording "user defined stanzas" is confusing. At first I thought that maybe the dune file was empty (or undefined), but that wasn't the case. I'm assuming it's trying to say that nothing is made importable via public_name, but I only pieced that together by looking at other support questions with the same issue.
  3. The suggested fix in support forums is to add a (public_name<s>) stanza to (executable<s>). But that's not allowed for (modes js).
  4. Should projects that consist entirely of executables not have (package) stanzas or opam files? From my limited experience with OCaml, my impression was that dune-project and opam files are mandatory for building, dependency-locking, locally installing, and setting metadata for any OCaml project, not just ones where code can be used by other projects.

Reproduction

dune-project:

(lang dune 3.10)

(name test)

(package
 (name test))

dune:

(executable
 (name main))

main.ml:

let () = print_string "test"

Specifications

Alizter commented 1 year ago

cc @hhugo

wildfield commented 1 year ago

I've stumbled upon this too. When I did dune init project myproject and then added (modes js) to the executable, I was stuck. modes js requires removing public_name and removing public_name causes the error message above.

Of course adding allow_empty fixes it, but that's non-trivial to figure out