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

projects created with dune init proj are not supported #604

Closed
ivg opened this issue May 5, 2021 · 2 comments
Closed

projects created with dune init proj are not supported #604

ivg opened this issue May 5, 2021 · 2 comments

Comments

@ivg
Copy link

ivg commented May 5, 2021

TL;DR; modern dune (4.8.5) doesn't create dune-workspace or dune-project at the top level of the project, only the <package>.opam. Therefore, running a build task in a bin folder will end in a message that is extremely confusing for beginners (that the opam file is missing).

The long read. I would like to have a nice and easy way for the OCaml beginners to use dune init with vscode. Ideally, there should be a command in dune "Create a new Dune project" for that, but so far the following workflow doesn't work.

dune init project start

it creates the following folder,

$ tree start
start
├── bin
│   ├── dune
│   └── main.ml
├── lib
│   └── dune
├── start.opam
└── test
    ├── dune
    └── start.ml

3 directories, 6 files

Now I want to just open that folder, e.g.,

code start

open the bin/main.ml file and run the build action. It fails, however, with


> Executing task: /usr/local/bin/opam exec --switch=4.09.0 --root /home/ivg/.opam -- dune build <

Info: Creating file dune-project with this contents:
| (lang dune 2.8)
File "dune", line 1, characters 0-65:
1 | (executable
2 |  (public_name start)
3 |  (name main)
4 |  (libraries start))
Error: The current project defines some public elements, but no opam packages
are defined.
Please add a <package>.opam file at the project root so that these elements
are installed into it.
The terminal process "/bin/bash '-c', '/usr/local/bin/opam exec --switch=4.09.0 --root /home/ivg/.opam -- dune build'" terminated with exit code: 1.

and now the project is broken as we have a new dune-project file,

$ tree start
start
├── bin
│   ├── _build
│   │   └── log
│   ├── dune
│   ├── dune-project #  <--- argh!
│   └── main.ml
├── lib
│   └── dune
├── start.opam
└── test
    ├── dune
    └── start.ml

4 directories, 8 files

At this point there is no way for an OCaml beginner to recover from this situation, as they don't know what this dune-project file means and what are the rules for the project workspace root.

Current workaround is to a set the project root by adding either dune-project or dune-workspace, the latter is easier as it doesn't require any contents (but is error-prone as an empty file can't be committed to git),

touch start/dune-workspace

P.S. It is hard to me to classify is that a dune bug or vscode-ocaml-platform one. The root of the problem is that you're running dune build and dune utop, etc just in the current folder, though it would make more sense (to me) to run it in the root of the project. On the other hand, you might say that it is the responsibility of dune to properly identify the root and workspace. In any case, the user experience is quite unsatisfying right now. See also ocaml/dune#4459

@tmattio
Copy link
Collaborator

tmattio commented May 5, 2021

I think Dune maintainers are planning to re-introduce the creation of dune-project with dune init (see ocaml/dune#4367), so I would say let's fix this workflow by waiting for the next Dune release.

In any case, we're planning on having a project creation workflow in VSCode directly (most likely using spin. We'll make sure that the workflow is beginner-friendly when we start working on this 🙂

@tmattio
Copy link
Collaborator

tmattio commented Oct 5, 2021

The issue you linked to has been addressed in ocaml/dune@046614e, so I think we can close this issue.

@tmattio tmattio closed this as completed Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants