diff --git a/Makefile b/Makefile index e42b8b3..e06b8ab 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,9 @@ all: DOCKER_EXPORT = CAMKES_VM_APP export DOCKER_EXPORT +build_cache: + @scripts/build_cache.sh + build_camkes: .config @scripts/build_camkes.sh diff --git a/README.md b/README.md index aac432f..d1dc2d1 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,21 @@ host% echo 'export YOCTO_SOURCE_MIRROR_DIR='${YOCTO_SOURCE_MIRROR_DIR} >> ~/. host% mkdir ${YOCTO_SOURCE_MIRROR_DIR} +## Configure build cache directory + +Compiling Haskell packages takes quite a long time, several minutes on a power machine. +The ```make``` equivalent, ```stack```, is able to cache the build results and because the +Haskell sources stay the same for most of the time (versions used are configured in +```capdl.git```), it is advisable to export a host directory to container to store +the cached build results across containers. Note that for CI purposes you need to judge +yourself when to enable the cache. + +
+host% export BUILD_CACHE_DIR=~/.tii_sel4_build
+host% echo 'export BUILD_CACHE_DIR='${BUILD_CACHE_DIR} >> ~/.bashrc
+host% mkdir ${BUILD_CACHE_DIR}
+
+ ## Check out sources
 # Choose a working directory, this will be visible in the container at /workspace
@@ -87,6 +102,11 @@ host% repo sync
 host% make docker
 
+## Prepopulate build cache +
+host% make build_cache
+
+ ## Use it!
diff --git a/docker/Dockerfile b/docker/Dockerfile
index b1c4144..61856f6 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -101,18 +101,6 @@ RUN pip3 install \
     pyfdt \
     pyyaml
 
-# Let's build all the capdl's dependencies. Downloading, compiling and
-# installing the correct GHC version and all of the dependencies takes
-# lots of time and we don't want to redo that everytime we restart the
-# container.
-
-RUN \
-    git clone https://github.com/seL4/capdl.git /home/build/capdl && \
-    cd /home/build/capdl/capDL-tool && \
-    stack build --only-dependencies && \
-    cd /home/build && \
-    rm -rf /home/build/capdl
-
 ENV WORKSPACE=/workspace
 
 WORKDIR /workspace
diff --git a/docker/enter_container.sh b/docker/enter_container.sh
index 0c632d9..049d28c 100755
--- a/docker/enter_container.sh
+++ b/docker/enter_container.sh
@@ -38,6 +38,7 @@ exec ${CONTAINER_ENGINE} run --rm ${INTERACTIVE} \
   -v "${DIR}:/workspace:z" \
   ${YOCTO_SOURCE_MIRROR_DIR:+--env YOCTO_SOURCE_MIRROR_DIR=/workspace/downloads} \
   ${YOCTO_SOURCE_MIRROR_DIR:+-v "${YOCTO_SOURCE_MIRROR_DIR}":/workspace/downloads:z} \
+  ${BUILD_CACHE_DIR:+-v "${BUILD_CACHE_DIR}"/stack:/home/build/.stack:z} \
   -v "${HOME}/.ssh:/home/build/.ssh:z" \
   -v "${HOME}/.gitconfig:/home/build/.gitconfig:z" \
   ${CONTAINER_ENGINE_OPTS} \
diff --git a/scripts/build_cache.sh b/scripts/build_cache.sh
new file mode 100755
index 0000000..8e896db
--- /dev/null
+++ b/scripts/build_cache.sh
@@ -0,0 +1,13 @@
+#! /bin/sh
+
+set -e
+
+. ${0%/*}/functions.sh
+
+TMPDIR=`mktemp -d ${HOME}/capdl.XXXXXX`
+
+git clone https://github.com/seL4/capdl.git ${TMPDIR}/capdl
+cd ${TMPDIR}/capdl/capDL-tool
+stack build --only-dependencies
+cd ${HOME}
+rm -rf ${TMPDIR}