When we migrated Inkscape to Gitlab we were excited about setting up the CI tools that they have. I was able to get the build going and Mc got the tests running. We’re off! The problem is that the Inkscape build was taking about 80 minutes, plus the tests. That’s really no fun for anyone as it’s a walk away from the computer amount of time.

Gitlab has a caching feature in their CI runners that allows you to move data from one build to another. While it can be tricky to manage a cache between builds; ccache will do it for you on C/C++ projects. This took the rebuild time for a branch down to a more reasonable 20 minutes.

I couldn’t find any tutorial or example on this, so I thought I’d write up what I did to enable ccache for people who aren’t as familiar with it. Starting out our .gitlab-ci.yml looked (simplified) like this:

image: ubuntu:16.04

before_script:
  - apt-get update -yqq 
  - apt-get install -y -qq # List truncated for web

inkscape:
  stage: build
  script:
    - mkdir -p build
    - cd build
    - cmake ..
    - make

First you need to add ccache to the list of packages you install and setup the environment for ccache in your before_script:

before_script:
  - apt-get update -yqq 
  - apt-get install -y -qq # List truncated for web
  # CCache Config
  - mkdir -p ccache
  - export CCACHE_BASEDIR=${PWD}
  - export CCACHE_DIR=${PWD}/ccache

You then need to tell the Gitlab CI infrastructure to save the ccache directory:

cache:
  paths:
    - ccache/

And lastly tell your build system to use the ccache compiler, for us in CMake that is using the COMPILER_LAUNCHER defines:

inkscape:
  stage: build
  script:
    - mkdir -p build
    - cd build
    - cmake .. -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
    - make

Final simplified .gitlab-ci.yml file:

image: ubuntu:16.04

before_script:
  - apt-get update -yqq 
  - apt-get install -y -qq # List truncated for web
  # CCache Config
  - mkdir -p ccache
  - export CCACHE_BASEDIR=${PWD}
  - export CCACHE_DIR=${PWD}/ccache

cache:
  paths:
    - ccache/

inkscape:
  stage: build
  script:
    - mkdir -p build
    - cd build
    - cmake .. -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
    - make

If you’d like to see the full version at the time of writing it is there. Also, assuming you are reading this in the future, you might be interesting in the current Gitlab CI config for Inkscape.


posted Jun 10, 2017 | permanent link