Skip to content

Conversation

@kit-ty-kate
Copy link
Member

Fixes #6407

@kit-ty-kate kit-ty-kate added this to the 2.6.0~alpha1 milestone Nov 4, 2025
@kit-ty-kate kit-ty-kate requested a review from rjbou November 4, 2025 21:57
@rjbou rjbou requested a review from dra27 November 10, 2025 13:30
Copy link
Member

@dra27 dra27 left a 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)

Comment on lines +445 to +449
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`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:

?

Comment on lines +451 to +456
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

?

Comment on lines +458 to +459
`opam switch create <version>` on the other hand, works slightly differently.
Since the only unknown is: which package is going to be used.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`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.

Comment on lines +460 to +467
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`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add documentation about default compiler change at init

3 participants