name: ci
on: [push, pull_request]

jobs:
  opam:
    strategy:
      matrix:
        os:
          - ubuntu-latest
        ocaml:
          - 5.1.x
          - 4.14.x
          - 4.03.x
        include:
          - os: macos-latest
            ocaml: 4.14.x
          - os: windows-latest
            ocaml: 4.14.x
      fail-fast: false
    runs-on: ${{ matrix.os }}

    steps:
      - uses: actions/checkout@v4
        with:
          submodules: recursive

      - uses: ocaml/setup-ocaml@v2
        if: runner.os != 'Windows'
        with:
          ocaml-compiler: ${{ matrix.ocaml }}

      - uses: ocaml/setup-ocaml@v2
        if: runner.os == 'Windows'
        with:
          ocaml-compiler: ${{ matrix.ocaml }}
          opam-repositories: |
            opam-repository-mingw: https://github.com/ocaml-opam/opam-repository-mingw.git#sunset
            default: https://github.com/ocaml/opam-repository.git

      - run: opam install -y --deps-only .
      - run: opam exec -- dune build -p luv

  old-libuv:
    strategy:
      fail-fast: false
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
        with:
          submodules: recursive
      - uses: ocaml/setup-ocaml@v2
        with:
          ocaml-compiler: 4.14.x
      - run: opam install -y --deps-only .
      - run: git clone https://github.com/libuv/libuv.git
        working-directory: ..
      - run: |
          git checkout v1.3.0
          ./autogen.sh
          sh configure
          make
          sh libtool --mode install cp libuv.la $(pwd)
        working-directory: ../libuv
      - run: opam exec -- dune build -p luv
        env:
          LUV_USE_SYSTEM_LIBUV: yes
          C_INCLUDE_PATH: ${{ github.workspace }}/../libuv/include
          LIBRARY_PATH: ${{ github.workspace }}/../libuv

  # esy builds are broken due to an upstream bug that is not worth working
  # around in luv, but should be fixed in esy:
  #
  #   https://github.com/esy/esy/issues/1440
  #
  # esy:
  #   strategy:
  #     matrix:
  #       os:
  #         - ubuntu-latest
  #         - macos-latest
  #         - windows-latest
  #     fail-fast: false
  #   runs-on: ${{ matrix.os }}
  #
  #   steps:
  #     - uses: actions/checkout@v4
  #       with:
  #         submodules: recursive
  #     - run: npm install esy
  #     - run: npx esy install
  #     - run: npx esy build
