Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] configure-less build #1385

Open
bobzhang opened this issue Oct 3, 2018 · 7 comments
Open

[feature request] configure-less build #1385

bobzhang opened this issue Oct 3, 2018 · 7 comments

Comments

@bobzhang
Copy link
Member

bobzhang commented Oct 3, 2018

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

@ghost
Copy link

ghost commented Oct 3, 2018

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.

@rgrinberg
Copy link
Member

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: #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.

@aantron
Copy link
Collaborator

aantron commented Oct 3, 2018

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.

@ghost
Copy link

ghost commented Oct 4, 2018

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.

@rgrinberg
Copy link
Member

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"

@ghost
Copy link

ghost commented Mar 25, 2020

Related to #1884

@aantron
Copy link
Collaborator

aantron commented Mar 25, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants