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:
Add the rule (promote (into ../../))
in my dune
file. It actually copies main.exe
and not myproject
in the source directory and dune clean
doesn't delete main.exe
in the root dir
Add the following rule in my dune
file:
(rule
(target myproject)
(deps ../../myproject)
(action (copy %{target} %{deps}))
)
which gives me the following error:
❯ dune build
File "src/bin/dune", line 6, characters 0-88:
6 | (rule
7 | (target myproject)
8 | (deps ../../myproject)
9 | (action (copy %{target} %{deps}))
10 | )
Error: No rule found for myproject
Error: Dependency cycle between the following files:
_build/default/src/bin/myproject
Done: 0/0 (jobs: 0)%
Add the following rule in my dune
file:
(rule
(target main.exe)
(deps ../../myproject)
(action (copy %{target} %{deps}))
)
which gives me the following error:
❯ dune build
Error: Multiple rules generated for _build/default/src/bin/main.exe:
- src/bin/dune:6
- src/bin/dune:2
Done: 0/0 (jobs: 0)%
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.
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
.