Thanks for this wise recommendation that gives us light (and hope!)
Can you detail a little bit about how to do that?
Currently I’m using opam for installing packages “as recommended in all tutorials” (opam install <package>).
And also dune for building (so I know the syntax of a dune file).
Is the opam file you mention like the one detailed here? https://opam.ocaml.org/doc/Tricks.html#Provide-a-set-of-packages-for-a-group-of-users-to-install?
Do I need to use opam 2.0 to create “one clean switch per project” ? (I’ve just upgraded this afternoon, assuming it makes possible to create one switch per project/program - and possibly several switch with the same compiler - )
And which command is required to get the packages/libraries available (for coding and for compilation)? Or maybe dune simply does the job? (I can spend some time in the opam documentation but this point should be obvious for you)
Also, can you explain clearly and exhaustively what is a package and what is a library?
See example from @emillon:
the ounit
package exposes a oUnit
library which has a OUnit2
module
AFAIK what is an (Ocaml) module is clear for me: a Foo module can be represented by a file foo.ml ; a Bar module car be related to a Bar module declaration ( module Bar : BAR = struct … end ) inside the the foo.ml file of a Foo module, and accessed by Foo.Bar .
Thanks
EDIT:
I’ve read some opam documentation, especially http://opam.ocaml.org/doc/Manual.html#Local-configuration-files.
I upgraded to opam 2.0.0.
I did
$ mkdir ~/project ; cd project/
$ opam switch create ./ ocaml-base-compiler.4.06.1
<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ λ build ocaml-base-compiler 4.06.1
└─
┌─ The following changes have been performed (the rest was aborted)
│ ∗ install base-bigarray base
│ ∗ install base-threads base
│ ∗ install base-unix base
└─
Inspired by https://github.com/ocaml/opam-repository/issues/12050 I tried with 4.02.3 but got the same error message.
Opam 2.0.0 has just been released last week and there may be some traps.
This opam local repository setup should be obvious for you. What do you recommend?
EDIT2:
I did again:
$ opam install opam-devel
and I got a clear message from opam that I didn’t have before (but thanks for that!):
# The ‘bwrap’ command was not found. Install ‘bubblewrap’ on your system, or
# disable sandboxing in ~/.opam/config at your own risk.
So I did the following that solved my opam 2.0.0 installation issue (if it may help s.o.):
$ sudo apt-get install bubblewrap
Then I did:
~/project$ opam switch create ./ ocaml-base-compiler.4.06.1
Done.
<><> (All…) installed successfully <><><><><>
And it seems that I have now a local repository switch for project.
As opam switch documentation tells:
$ opam switch create --help
DESCRIPTION
…
When creating a directory switch, if package definitions are found locally, the user is automatically prompted to install them after the switch is created unless --no-install is specified.
Now, to follow @Leonidas recommendation, I understand that I “just” need to write a file ~/project/opam and redo
~/project$ opam switch create ./ ocaml-base-compiler.4.06.1
“to get prompted to install them after the switch is created”.
I hope these details could be helpful for other people in my situation.