Searching for a manual about packaging compiler for opam 2.0

I want to try multicore ocaml with opam 2.0. I can’t use the default multicore opam repo because the update from 1.2.x goes wrong (ussue on github) and I can’t see the switch in the available list. So I tried to create a 2.0 repo myself but without much success: a new switch still not available.

Where is the manual about adding a new compiler to opam 2.0?

➜  multicore-opam cat ./packages/ocaml-variants/ocaml-variants.4.02.2+multicore/opam
opam-version: "2.0"
synopsis: "Switch for 4.02.2 multicore"
maintainer: ""
depends: ["base-unix" "base-bigarray" "base-threads"]
conflict-class: "ocaml-core-compiler"
flags: compiler
setenv: CAML_LD_LIBRARY_PATH = "%{lib}%/stublibs"
build: [
  ["./configure" "-prefix" prefix "-with-debug-runtime"]
  [make "world"]
  [make "world.opt"]
]
install: [make "install"]
url {
  src: "https://github.com/ocamllabs/ocaml-multicore/archive/master.tar.gz"
}

P.S. Maybe I should cast somebody here. @AltGr ?

That looks correct to me! That has been reverted since, but at some point it was required to issue opam switch list-available --all to include available variants: are you using the last beta ?
You could check that the package is available (not considering its compiler status) using opam list, too. If it appears there, you can force its use as compiler with opam switch create my-multicore-switch --packages=ocaml-variants.4.02.2+multicore

EDIT: fixed typo (opam switch list-available)

Something is wrong with latest opam… I don’t yet know exactly what… @AltGr ?

➜  opam git:(master) ✗ opam remote remove multicore  --all                                         
➜  opam git:(master) ✗ opam remote add multicore  http://github.com/ocamllabs/multicore-opam -k git     
[multicore] Initialised
[NOTE] Repository at git+http://github.com/ocamllabs/multicore-opam doesn't define its version, assuming it's 1.2.

=-=- Upgrading repositories from older opam format =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Upgrading repository "multicore"...
Repository multicore has been added to the selections of switch 4.04.0+fp+flambda.
➜  opam git:(master) ✗ evalopam 
/home/kakadu/.opam/4.04.0+fp+flambda/lib/ocaml
2.0.0~beta3
➜  opam git:(master) ✗ opam list-available --all                                                        
opam: unknown command `list-available'.
Usage: opam COMMAND ...
Try `opam --help' for more information.
➜  opam git:(master) ✗ opam list --all|grep multicore                                                   
1236:parmap                             --                Minimalistic library allowing to exploit multicore architecture
➜  opam git:(master) ✗ opam switch create my-multicore-switch --packages=ocaml-variants.4.02.2+multicore
[ERROR] ocaml-variants = 4.02.2+multicore no matching version

Hmm, it seems there is still some polishing to do for the CLI.

opam repo add is now specific to the current switch by default:

  • you could add it to the default using opam repo add --set-default
  • or, after having added it as you did (or with --dont-select), add --repositories=multicore,default to the switch creation command
  • or all-in-one command, on recent dev versions:
    opam switch create 4.02.2+multicore --repositories multicore=git+https://github.com/ocamllabs/multicore-opam,default`
    

Thanks, I managed to install compiler. But new opam interface is … weird.
Are you trying to say that while creating new switches opam by default looks only into default repo?

With repositories configurable per-switch, we keep a selection of repos for each switch, plus one for the defaults when creating new switches. All can be set independently, but the default for opam repo add is to add only to the current switch (in the first version I had it add to current and default, but it wasn’t better).

I am not sure how to make it more intuitive. Maybe the default should be to update all switches + default on opam repo add, and have a different command for fine-tuning (opam switch repo add … ?)
OTOH, in this example, you probably didn’t want to add the repo globally, so the last command really was what you were after.

Another, more verbose but more self-explanatory way could be to add no selections on opam repo add, requiring them to be explicit:

$ opam repo add foo https://...
Repository `foo` was added.
NOTE: no switch is yet configured to use this repository. Use
     `opam repo add foo --this-switch|--switch SW|--all|--set-default`
   to select it, or create a new switch using it with
     `opam switch create --repositories=foo,{current default}`

My idea was to make it as simple as possible in the simpler case (just one switch), but at least the above would have saved you the confusion.

Why is it bad to add new repo to all switches by default? And only to some switches when an option specified

I think that adding to all switches by default is not a good idea and will lead to surprises with local switches (which I guess opam may not know about when you add).

However I do think that opam repo as it exists is quite confusing. I tried to make a few suggestions here.

It may be simpler to use ; but I am fairly sure this isn’t actually what you want in general, so in the best case you are adding repositories with packages that you won’t use and are harmless — like in your case. In the worst case you want to try out something in a test switch, and add weird package alternatives to your main dev switches, which might lead to confusing behaviour.

The idea is that, with local switches and all, we are trying to have more isolation between switches: having a default that could affect them all when you might have just wanted to test something in your test switch seems dangerous.

Do you think that it is a good idea to add a mesage in the end of opam switch list-available saying The listed switches are from the repo blah. You can specify other repos using switch --bla-bla ?

Yes, that may be helpful. More something like

[NOTE] Showing compilers from the repositories [default or specified repository
       selection]. Use `--repositories REPO[,REPO...]` to show more.

… and only if you have repositories containing compilers that aren’t in your default selection.