Dune: [feature request] configure-less build

Created on 3 Oct 2018  路  7Comments  路  Source: ocaml/dune

This is a feature request, for people just tinkering around with ocaml for fun, it is possible to provide minimal config to get up and running.

Nowadays, I used dune maybe once a couple of months, I have to consult the manual each time since I used it only occasionally, but I think other people may have similar experience.

A bit story unfolded about my experience when using dune this morning:

I tried to use it for a tiny project, I used it for a couple of times but forgot its config, so I go to https://dune.readthedocs.io/en/latest/quick-start.html, but it does not work, it tells me:

test>dune build
Info: creating file dune-project with this contents: (lang dune 1.2)

I try to add (lang dune 1.2),
It tells me

test>dune build
File "dune", line 2, characters 1-5:
2 | (lang dune 1.2)
     ^^^^
Error: Unknown constructor lang

I understand it may be a trivial problem for frequent dune users, but it is not too good for occasional users, my time budget is one hour for coding today, but already spent half an hour in trying out dune

Two proposals to address issue:

  1. provide an easy mode
    -- minimal user input to build an executable, I did not use Emacs anymore these days, it is very hard to edit S-exp in an editor without any config (it is great to enhance user experience for those who just tinker around)

  2. provide something like omake install or bsb init
    it installs a minimal template so I just need edit some files.

Ideally, I wish I only need one command for an occasional user:

dune exec ./main.exe

and it always works out of box

Most helpful comment

What about inlining the dune file in the source? That would make it easier to have "scripts" that one can invoke as well. For example:

(*$ dune
(preprocess ..)
(libraries ..)
 *)
printe_endline "hello world"

All 7 comments

Improving the default behavior is fine, however it's not clear how it should interact with explicit configuration when the user writes a dune file manually.

When no configuration file is found, I suppose Dune could try infer the dune file and write it to disk. The user could then use this generated dune file as a starting point to do more complicated things, such as adding ppx rewriters, etc...

BTW, the first message about (lang dune 1.2) was just informative, it wasn't an error. Dune couldn't find a dune-project file so it created one for you. The idea is that Dune is fully backward compatible and in order to provide this feature it needs to know against what version of Dune the configuration files where written. As a result it is important that projects have a dune-project file with this version number. However, to avoid forcing users to write this file systematically when they start a project, Dune creates it automatically.

provide something like omake install or bsb init
it installs a minimal template so I just need edit some files.

This is a separate issue that's on our roadmap: https://github.com/ocaml/dune/issues/159

provide an easy mode -- minimal user input to build an executable, I did not use Emacs anymore these days, it is very hard to edit S-exp in an editor without any config (it is great to enhance user experience for those who just tinker around)

I think @aantron discussed this feature being desirable as well. Basically a $ dune run command that would accept executable fields as command line arguments. The idea, isn't original, I've found https://github.com/mjambon/ocamlscript to be quite useful over the years. It would be nice to recreate the same experience with dune.

It would also be nice to have a way to save these options in the script itself. For example, have dune parse out the libraries field out of a comment that begins the script file.

I wanted this in part for examples. I'd like to be able to put a one-liner under each example for compiling and running it. This was possible with ocamlfind, but not currently possible with Dune, because Dune requires boilerplate files.

Once Dune_lang.Decoder.t is a pure applicative, it will be easy to automatically get a cmdliner parser out of Dune_file.Library.decode. I.e. generate a command line spec that follows the executable stanza without hassle:

$ dun run --libraries foo bar --preprocess '(pps ppx_foo ppx_bar)'  -- foo.ml <args>...

It would also be nice to have a way to save these options in the script itself. For example, have dune parse out the libraries field out of a comment that begins the script file.

This would be nice as well.

What about inlining the dune file in the source? That would make it easier to have "scripts" that one can invoke as well. For example:

(*$ dune
(preprocess ..)
(libraries ..)
 *)
printe_endline "hello world"

Related to #1884

I would still strongly welcome the ability to give stanzas on the command line. The syntax can be the same as in dune files or in source files, if we implement that.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

c-cube picture c-cube  路  7Comments

jvillard picture jvillard  路  8Comments

mjambon picture mjambon  路  3Comments

mmottl picture mmottl  路  4Comments

jeremiedimino picture jeremiedimino  路  5Comments