ocamlocaml-dune

Copy the produced executable in my root dir with dune


Let's say I have a simple project with the following structure:

.
├── dune-project
└── src
└── bin
    ├── dune
    └── main.ml

dune-project

(lang dune 2.7)
(name myproject)

(package
 (name myproject)
 (synopsis "myproject")
 (description "Basic project")
)

dune

(executable
 (name main)
 (public_name myproject)
)

When compiling with dune build I have a new directory _build with the following structure:

_build
├── default
│   ├── dune-project
│   ├── META.myproject
│   ├── myproject.dune-package
│   ├── myproject.install
│   └── src
│       └── bin
│           ├── dune
│           ├── main.exe
│           └── main.ml
├── install
│   └── default
│       ├── bin
│       │   └── myproject -> ../../../default/src/bin/main.exe
│       └── lib
│           └── myproject
│               ├── dune-package -> ../../../../default/myproject.dune-package
│               └── META -> ../../../../default/META.myproject
└── log

So dune is able to create a symlink from main.exe to myproject but I actually want myproject to be in . and not in _build/install/default/bin

I tried three things:

And honestly I don't know what else I can do. I read the manual and can't find a solution. I wouldn't mind if I could just type dune run but since dune allows to build multiple executables, I understand it's not an option. I'd like to be able to write dune run myproject since I'm using the public name of my executables but dune can't find it. So I just want to have myproject in my root directory so I can just type ./myproject and be happy.


Solution

  • Do you know about dune exec? It is what you call dune run I believe.

    From the root of your project, you can do dune exec ./bin/main.exe.