From 151db45a4208e22d97a03556b3eb55faf5ebaf18 Mon Sep 17 00:00:00 2001
From: Wouter Deconinck <wdconinc@gmail.com>
Date: Sat, 18 Feb 2023 18:16:16 +0000
Subject: [PATCH] feat: setup reconstruction and detectors with ccache

---
 containers/jug/setup_detectors.py |  1 +
 containers/jug/xl.Dockerfile      | 15 ++++++++++++---
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/containers/jug/setup_detectors.py b/containers/jug/setup_detectors.py
index 20c9c8403..a2611a043 100755
--- a/containers/jug/setup_detectors.py
+++ b/containers/jug/setup_detectors.py
@@ -122,6 +122,7 @@ if __name__ == '__main__':
                             detector=proj),
                        '&&',
                        'cmake -B /tmp/build -S /tmp/det -DCMAKE_CXX_STANDARD=17',
+                       '-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache',
                        '-DCMAKE_INSTALL_PREFIX={prefix}'.format(prefix=prefix),
                        '&&',
                        'cmake --build /tmp/build -j$(($(($(nproc)/4))+1)) -- install']
diff --git a/containers/jug/xl.Dockerfile b/containers/jug/xl.Dockerfile
index 657c22b03..2ec20bf72 100644
--- a/containers/jug/xl.Dockerfile
+++ b/containers/jug/xl.Dockerfile
@@ -8,6 +8,7 @@ ARG INTERNAL_TAG="testing"
 ## EIC builder image with spack
 ## ========================================================================================
 FROM ${DOCKER_REGISTRY}${BASE_IMAGE}:${INTERNAL_TAG}
+ARG TARGETPLATFORM
 
 ARG EICWEB="https://eicweb.phy.anl.gov/api/v4/projects"
 ARG JUGGLER_VERSION="main"
@@ -20,8 +21,11 @@ ARG JUG_VERSION=1
 RUN cd /tmp                                                                     \
  && echo " - jug_xl: ${JUG_VERSION}" >> /etc/jug_info
 
+ENV CCACHE_DIR=/ccache/$TARGETPLATFORM
+
 ADD ${EICWEB}/369/repository/tree?ref=${JUGGLER_VERSION} /tmp/369.json
-RUN cd /tmp                                                                     \
+RUN --mount=type=cache,target=/ccache/                                          \
+    cd /tmp                                                                     \
  && echo "INSTALLING JUGGLER"                                                   \
  && git clone -b ${JUGGLER_VERSION} --depth 1                                   \
         https://eicweb.phy.anl.gov/EIC/juggler.git                              \
@@ -29,6 +33,7 @@ RUN cd /tmp
           -DCMAKE_CXX_STANDARD=17                                               \
           -DCMAKE_INSTALL_PREFIX=/usr/local                                     \
           -DCMAKE_BUILD_TYPE=Release                                            \
+          -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
  && cmake --build build -j12 -- install                                         \
  && pushd juggler                                                               \
  && echo " - juggler: ${JUGGLER_VERSION}-$(git rev-parse HEAD)"                 \
@@ -37,7 +42,8 @@ RUN cd /tmp
  && rm -rf build juggler
 
 ADD https://api.github.com/repos/eic/eicrecon/commits/${EICRECON_VERSION} /tmp/eicrecon.json
-RUN cd /tmp                                                                     \
+RUN --mount=type=cache,target=/ccache/                                          \
+    cd /tmp                                                                     \
  && echo "INSTALLING EICRECON"                                                  \
  && git clone -b ${EICRECON_VERSION} --depth 1                                  \
         https://github.com/eic/eicrecon.git                                     \
@@ -45,6 +51,7 @@ RUN cd /tmp
           -DCMAKE_CXX_STANDARD=17                                               \
           -DCMAKE_INSTALL_PREFIX=/usr/local                                     \
           -DCMAKE_BUILD_TYPE=Release                                            \
+          -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
  && cmake --build build -j12 -- install                                         \
  && pushd eicrecon                                                              \
  && echo " - eicrecon: ${EICRECON_VERSION}-$(git rev-parse HEAD)"               \
@@ -121,10 +128,12 @@ ADD https://api.github.com/repos/eic/ip6 /tmp/ip6.json
 ADD https://api.github.com/repos/eic/epic /tmp/epic.json
 COPY setup_detectors.py /tmp
 COPY detectors.yaml /tmp
-RUN cd /tmp                                                                     \
+RUN --mount=type=cache,target=/ccache/                                          \
+    cd /tmp                                                                     \
  && [ "z$NIGHTLY" = "z1" ] && NIGHTLY_FLAG="--nightly" || NIGHTLY_FLAG=""       \
  && /tmp/setup_detectors.py --prefix /opt/detector --config /tmp/detectors.yaml \
                          $NIGHTLY_FLAG                                          \
+ && ccache --show-stats                                                         \
  && rm /tmp/setup_detectors.py
 
 ## Hotfix for misbehaving OSG nodes
-- 
GitLab