FROM ubuntu:20.04
ENV DEBIAN_FRONTEND=noninteractive

RUN apt update -y

# Apparently wget is not installed by default
RUN apt-get install -y wget

# Add llvm pub key
RUN wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc

# Install add-apt-repository
RUN apt-get install -y software-properties-common

# Add llvm 18 repository with sources
RUN add-apt-repository -s -y "deb http://apt.llvm.org/focal/ llvm-toolchain-focal-18 main"

RUN echo apt-get update && apt-get install -y llvm-18 clang-18 libclang-18-dev libclang-cpp18-dev python3-pip

# Easiest way to get sufficiently new cmake appears to be using pip - Ubuntu 20.10 version is too old
RUN pip3 install --upgrade cmake

# Copy the source into the Docker container
RUN mkdir -p /c2ffi
COPY / /c2ffi
WORKDIR /c2ffi

# Build c2ffi
RUN cd /c2ffi && \
        rm -rf build && mkdir -p build && cd build && \
        cmake -DBUILD_CONFIG=Release .. && make

# As a sanity check, make sure the binary we built can be executed
RUN /c2ffi/build/bin/c2ffi --help