Skip to content

Make dune exec look up target on its own and execute them #14511

@Leonidas-from-XIV

Description

@Leonidas-from-XIV

Desired Behavior

dune exec is an useful command for running binaries and making sure that the binaries that are run are up-to-date (thus preferable to dune build followed by _build/default/install/bin/...). However in my experience it is unnecessarily strict on what inputs it accepts when it could (in my opinion) fairly reasonably infer what the user wants to do in a number of common cases.

dune exec currently requires a target to execute. However, the notion of targets is somewhat confusing for users because unlike make Dune does not put targets in the source tree. At the moment to execute a binary dune exec can take a public name (which is fairly ergonomic and straightforward) but it can also be used to launch executables by means of dune exec bin/main.exe.

Unfortunately, bin/main.exe does not exist in the source tree thus naive command line completion does not suggest it. Furthermore, the user needs to be aware of the fact that even on Unix the target has an .exe suffix. Thus lowering the chances of the user succeeding in figuring this out and remembering this for the future to a low percentage. Back in the day it was easier for me to call dune build && _build/.../binary.exe since it was more understandable what is happening and this might be similar to other users.

@Alizter mentioned that it is also possible to pass pforms to dune exec, however I think the ergonomics of an user typing dune exec %{bin:foo} is potentially even worse than typing in the target manually.

Example

(executable
  (name foo))
$ dune exec bin/foo.ml

builds and executes foo automatically.

Unlike dune build bin/foo.ml this does not conflict with copying code from the source tree into the build folder as the user has expressed that they want to execute a process.

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalRFC's that are awaiting discussion to be accepted or rejected
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions