-
Notifications
You must be signed in to change notification settings - Fork 379
Document how opam chooses the default compiler during opam init and opam switch create #6778
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
base: master
Are you sure you want to change the base?
Conversation
…pam switch create
dra27
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps the FAQ isn't the correct place to be noting opam switch create 5.4 ocaml.5.4.0, but it would go well with the part about opam init --compiler (i.e. that you can just specify the precise version package and not rely on any of these heuristics)
| Since opam 2.4, `opam init` will choose `ocaml-base-compiler` as default | ||
| compiler for the `default` switch, and let the solver choose the latest | ||
| version. Of course this default can always be changed using `--compiler` | ||
| or by skipping the creation of the `default` switch all-together with | ||
| `--bare`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Since opam 2.4, `opam init` will choose `ocaml-base-compiler` as default | |
| compiler for the `default` switch, and let the solver choose the latest | |
| version. Of course this default can always be changed using `--compiler` | |
| or by skipping the creation of the `default` switch all-together with | |
| `--bare`. | |
| Since opam 2.4, `opam init` will select `ocaml-base-compiler` as the default | |
| compiler package for the `default` switch, and let the solver choose the latest | |
| version. This can always be changed using `--compiler` or by skipping the | |
| creation of the `default` switch altogether with `--bare`. |
| `--bare`. | ||
|
|
||
| For example if you would rather use the OCaml compiler that you have | ||
| installed by other means, you can use the `ocaml-system` package as follows: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| installed by other means, you can use the `ocaml-system` package as follows: | |
| installed outside opam, you can use the `ocaml-system` package as follows: |
?
| For example if you would rather use the OCaml compiler that you have | ||
| installed by other means, you can use the `ocaml-system` package as follows: | ||
| `opam init --compiler=ocaml-system`. Be careful though, system-wide compilers | ||
| can be setup in a way that the default opam-repository doesn't expect, | ||
| so failures may occur. Thus this option should only be used if you know | ||
| what you're doing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| For example if you would rather use the OCaml compiler that you have | |
| installed by other means, you can use the `ocaml-system` package as follows: | |
| `opam init --compiler=ocaml-system`. Be careful though, system-wide compilers | |
| can be setup in a way that the default opam-repository doesn't expect, | |
| so failures may occur. Thus this option should only be used if you know | |
| what you're doing. | |
| For example, if you would rather use the OCaml compiler that you have | |
| installed by other means, you can use the `ocaml-system` package as follows: | |
| `opam init --compiler=ocaml-system`. Be careful, though; system-wide compilers | |
| can be set-up in a way that the default opam-repository doesn't expect, | |
| so failures may occur. Thus this option should only be used if you know | |
| what you're doing. |
| installed by other means, you can use the `ocaml-system` package as follows: | ||
| `opam init --compiler=ocaml-system`. Be careful though, system-wide compilers | ||
| can be setup in a way that the default opam-repository doesn't expect, | ||
| so failures may occur. Thus this option should only be used if you know |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| so failures may occur. Thus this option should only be used if you know | |
| so failures may occur. We recommend this option should only be used if you know |
?
| `opam switch create <version>` on the other hand, works slightly differently. | ||
| Since the only unknown is: which package is going to be used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| `opam switch create <version>` on the other hand, works slightly differently. | |
| Since the only unknown is: which package is going to be used. | |
| `opam switch create <version>` on the other hand, works slightly differently, | |
| since the only unknown is exactly which package is going to be used. |
| Opam decides this by looking at all the packages that have been tagged as | ||
| `compiler`, filter which ones have the right version, and then let the solver | ||
| decide. For example calling `opam switch create 5.4 5.4.0` will create a | ||
| switch named `5.4` and look for compiler packages with versions `5.4.0` which | ||
| by default, with [opam-repository](https://github.com/ocaml/opam-repository/), | ||
| will get back with `ocaml-base-compiler.5.4.0` and `ocaml-system.5.4.0`. | ||
| Since 2025, `ocaml-system` is tagged as `avoid-version` so the solver will | ||
| choose `ocaml-base-compiler.5.4.0`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Opam decides this by looking at all the packages that have been tagged as | |
| `compiler`, filter which ones have the right version, and then let the solver | |
| decide. For example calling `opam switch create 5.4 5.4.0` will create a | |
| switch named `5.4` and look for compiler packages with versions `5.4.0` which | |
| by default, with [opam-repository](https://github.com/ocaml/opam-repository/), | |
| will get back with `ocaml-base-compiler.5.4.0` and `ocaml-system.5.4.0`. | |
| Since 2025, `ocaml-system` is tagged as `avoid-version` so the solver will | |
| choose `ocaml-base-compiler.5.4.0`. | |
| Opam decides this by finding all packages which have the given and which | |
| that have been flagged as `compiler` and then presents just these packages | |
| to the solver. For example calling `opam switch create 5.4 5.4.0` will create a | |
| switch named `5.4` and look for compiler packages with versions `5.4.0` which | |
| by default, with [opam-repository](https://github.com/ocaml/opam-repository/), | |
| will be with `ocaml-base-compiler.5.4.0`, `ocaml-system.5.4.0` and | |
| `ocaml-variants.5.4.0+options`. `ocaml-system.5.4.0` is flagged as `avoid-version`, | |
| so the solver will choose `ocaml-base-compiler.5.4.0`. |
(although I can't remember for certain why ocaml-base-compiler.5.4.0 is guaranteed to be selected, given that it actually has more dependencies than ocaml-variants.5.4.0+options)
Fixes #6407