# Update CACHEKEY in the .gitlab-ci.yml when modifying this file.

FROM ubuntu:23.04
LABEL maintainer="e@x80.org"

ENV DEBIAN_FRONTEND="noninteractive"

# We need libgmp-dev:i386 for zarith; maybe we could also install GTK
RUN dpkg --add-architecture i386

RUN apt-get update -qq && apt-get install --no-install-recommends -y -qq \
        # Dependencies of the image, the test-suite and external projects
        m4 automake autoconf time wget rsync git gcc-multilib build-essential unzip jq \
        # Dependencies of ZArith
        perl libgmp-dev libgmp-dev:i386 \
        # Dependencies of lablgtk (for CoqIDE)
        libgtksourceview-3.0-dev adwaita-icon-theme-full \
        # Dependencies of Gappa
        libboost1.81-all-dev libmpfr-dev autoconf-archive bison flex \
        # Dependencies of source-doc and coq-makefile
        texlive-latex-extra texlive-science tipa \
        # Dependencies of HB (test suite)
        wdiff \
        # Required to get the wget step to succeed
        ca-certificates \
        # Required for fiat-crypto and Coqtail
        python-is-python3

# We need to install OPAM 2.0 manually for now.
RUN wget https://github.com/ocaml/opam/releases/download/2.1.5/opam-2.1.5-x86_64-linux -O /usr/bin/opam && chmod 755 /usr/bin/opam

# Basic OPAM setup
ENV NJOBS="2" \
    OPAMJOBS="2" \
    OPAMROOT=/root/.opamcache \
    OPAMROOTISOK="true" \
    OPAMYES="true"

# Edge opam is the set of edge packages required by Coq
ENV COMPILER="4.14.1" \
    BASE_OPAM="zarith.1.11 ounit2.2.2.6" \
    CI_OPAM="ocamlgraph.2.0.0 cppo.1.6.9" \
    BASE_OPAM_EDGE="dune.3.6.1 dune-build-info.3.6.1 dune-release.1.6.2 ocamlfind.1.9.5 odoc.2.1.1" \
    CI_OPAM_EDGE="elpi.1.17.0 ppx_import.1.10.0 cmdliner.1.1.1 sexplib.v0.15.1 ppx_sexp_conv.v0.15.1 ppx_hash.v0.15.0 ppx_compare.v0.15.0 ppx_deriving_yojson.3.7.0 yojson.2.1.0 uri.4.2.0 ppx_yojson_conv.v0.15.1 ppx_inline_test.v0.15.1 ppx_assert.v0.15.0 lsp.1.16.2" \
    COQIDE_OPAM_EDGE="lablgtk3-sourceview3.3.1.3"

# EDGE+flambda switch, we install CI_OPAM as to be able to use
# `ci-template-flambda` with everything.
RUN opam init -a --disable-sandboxing --bare && eval $(opam env) && opam update && \
    opam switch create "${COMPILER}+flambda" \
      --repositories default,ocaml-beta=git+https://github.com/ocaml/ocaml-beta-repository.git \
      --packages="ocaml-variants.${COMPILER}+options,ocaml-option-flambda" && eval $(opam env) && \
    opam install $BASE_OPAM $BASE_OPAM_EDGE $COQIDE_OPAM_EDGE $CI_OPAM $CI_OPAM_EDGE


RUN opam clean -a -c

# set the locale for the benefit of Python
ENV LANG C.UTF-8
