ARG BASE=nvidia/cuda:11.6.0-devel-ubuntu20.04
FROM $BASE

ARG DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y --no-install-recommends \
    bc \
    wget \
    ccache \
    ninja-build \
    python3 \
    git \
    cmake \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

RUN SYCL_VERSION=20220328 \
    && SYCL_URL=https://github.com/intel/llvm/archive/sycl-nightly \
    && SYCL_ARCHIVE=${SYCL_VERSION}.tar.gz \
    && SCRATCH_DIR=./scratch \
    && mkdir -p ${SCRATCH_DIR} \
    && cd ${SCRATCH_DIR} \
    && wget --quiet ${SYCL_URL}/${SYCL_ARCHIVE} \
    && mkdir llvm \
    && tar -xf ${SYCL_ARCHIVE} -C llvm --strip-components=1

ENV SYCL_DIR=/opt/sycl
ENV CUDA_LIB_PATH=/usr/local/cuda-11.6/targets/x86_64-linux/lib/stubs/

RUN SCRATCH_DIR=/scratch \
    && cd ${SCRATCH_DIR}/llvm \
    && python3 buildbot/configure.py --cuda \
    && python3 buildbot/compile.py \
    && mkdir -p ${SYCL_DIR} \
    && mv ${SCRATCH_DIR}/llvm/build/install/* ${SYCL_DIR} \
    && echo "${SYCL_DIR}/lib" > /etc/ld.so.conf.d/sycl.conf \
    && ldconfig \
    && rm -rf ${SCRATCH_DIR}

ENV PATH=${SYCL_DIR}/bin:$PATH
