ocaml / setup-ocaml

GitHub Action for the OCaml programming language
https://ocaml.org/
MIT License
195 stars 38 forks source link

How does setup-ocaml chooses opam versions? (ci failure with 4.08.1 on macos) #861

Closed mbarbin closed 6 days ago

mbarbin commented 1 week ago

Hello!

I am not sure where to best report this issue, I'll start with setup-ocaml and please you can help me determine whether this is rather something for the opam devs.

I am encountering build issues in pp's PR 21 CI, specifically the build for macos-latest, 4.08.x

In the log, I can see that the opam selected is this:

Install opam
  Acquired 2.2.1 from https://github.com/ocaml/opam/releases/download/2.2.1/opam-2.2.1-arm64-macos

And then later:

   Switch invariant: ["ocaml-base-compiler" {= "4.08.1"}]
  [ERROR] Could not determine which packages to install for this switch:
    * Missing dependency:
      - ocaml-base-compiler = 4.08.1
      unmet availability conditions: '!(os = "macos" & arch = "arm64")'

I think this error makes sense, given that in the opam configuration for this package, there is this line:

available: !(os = "macos" & arch = "arm64")

I am wondering if there are other arch available that would make this build succeed, and if so, how to force setup-ocaml to select it. I might very well be confused about the fact that arch = arm64 has anything to do with the fact that opam-2.2.1-arm64-macos is selected (I am out of my depth here).

Thanks for your help!

smorimoto commented 1 week ago

@mbarbin See this PR #862. There are some pitfalls except for Ubuntu. It's a matter of compiler support, so we can't fix it here.

Here is what I usually do.

  1. Add the lower and upper compiler versions that the package supports, just for Ubuntu.
  2. Add the latest compiler version for macOS and Windows.

So, in YAML, it should look like this:

strategy:
  fail-fast: false
  matrix:
    os:
      - ubuntu-latest
    ocaml-compiler:
      - "4.08"
      - "5"
    include:
      - os: macos-latest
        ocaml-compiler: "5"
      - os: windows-latest
        ocaml-compiler: "5"
mbarbin commented 1 week ago

@smorimoto Thank you very much for the new documentation PR, that is very helpful!

I have two follow up questions:

tmcgilchrist commented 1 week ago

@mbarbin The default macOS architecture has changed from x86_64 to ARM64 in the past. If you need macOS x86_64 I would suggest using an explicit version over using -latest see https://docs.github.com/en/actions/using-github-hosted-runners/using-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories It will leave you with an older macOS version but that's all GitHub provides.

eg

      matrix:
        include:
          - name: macos-x86_64
            os: macos-13
          - name: macos-arm64
            os: macos-14
mbarbin commented 6 days ago

@tmcgilchrist thanks for jumping in, and very nice to hear from you. This clarifies it for me, thank you both!

I have also found another repo where they made the switch to macos-13 for this reason. Linking in to illustrate : https://github.com/ocaml-sf/learn-ocaml/pull/603

I think this thread covered all of my questions, I'll be closing the issue. Thanks again.