conan-package-tools icon indicating copy to clipboard operation
conan-package-tools copied to clipboard

Speedup of packages build in Docker with ccache

Open leugenea opened this issue 6 years ago • 11 comments

Description of Problem, Request, or Question

It might be helpful to allow using of ccache when building packages (if package support it, of course, in some way) inside Docker container to speedup rebuilds.

I'll try to illustrate it with simple workflow:

  1. we're building package A with version 1.0.0 with some set of sources,
  2. we're using it in release builds,
  3. some bug is found in A,
  4. we fix sources of A and create version 1.0.1 with almost same sources (let's assume that only a few .cpp files were modified),
  5. we have to fully rebuild all packages.

So, maybe at step 5 we could use ccache to rebuild only a few .cpp file that were modified. For libraries with hundreds of source files this really could make a difference.

leugenea avatar Sep 09 '19 13:09 leugenea

I know there are users that are taking benefit from the ccache but not sure if they are using conan package tools. Maybe @joaquin-herrero could give us a hint here

danimtb avatar Sep 10 '19 06:09 danimtb

CPT uses Conan create to build any package, so the build_folder is discarded when a new build starts. I can't see an easy integration with ccache

uilianries avatar Sep 10 '19 17:09 uilianries

@uilianries, we could mount ccache cache location (could be set via CCACHE_DIR env variable for example, see docs) to Docker container (just like we mount source root) and reuse it between builds.

leugenea avatar Sep 10 '19 17:09 leugenea

I'm reading ccache docs, and for Conan Package Tools it's not a problem I think. You only need to set CC=<ccache_folder>/gcc and you are good to go. IF you are not using docker.

Conan Docker Tools is only about Docker images, so we need to install ccache for every Docker image and change the compiler paths to ccache link, but is a problem because we need know about any side-effect.

Also, re-using cache folder between builds is not a good practice. We saw some issues from users in the past.

uilianries avatar Sep 10 '19 18:09 uilianries

I'm not suggesting to re-use Conan cache folder between builds, I'm suggesting to re-use ccache cache.

It's not a big deal for me to install ccache inside all Docker images as we use our custom images. It's also not a problem to set correct environment vars to tell build system to use ccache.

The problem is that CPT doesn't allow me to mount ccache cache directory from host machine. Without this ability using of ccache is absolutely pointless.

leugenea avatar Sep 11 '19 10:09 leugenea

If you only want to add an extra volume, you can pass it by Docker options:

https://github.com/conan-io/conan-package-tools#passing-additional-docker-parameters-during-build

Also, if you need an extra some extra step when running your docker container, you can set an entry script

https://github.com/conan-io/conan-package-tools/#running-scripts-and-executing-commands-before-to-build-on-docker

uilianries avatar Sep 11 '19 12:09 uilianries

Oh… you're absolutely right! Looks like I've missed it.

But, returning to the question, it would be nice if CPT provided this as an option for multipackager.

About the safety of this solution. I've done some quick research about it, and looks like ccache can calculate hash of compiler binary (compiler_check parameter set to content), so there couldn't be any collisions between different OS's/compilers/etc.

leugenea avatar Sep 11 '19 14:09 leugenea

But, returning to the question, it would be nice if CPT provided this as an option for multipackager.

What do you mean? Passing a new volume is not enough for ccache usage?

uilianries avatar Sep 11 '19 16:09 uilianries

Of course it's enough, but I'm talking about native and simple integration.

My point is that CPT provides a lot of customization points like used Docker container, entry script, etc. It could be handy if MultiPackager class provided argument like docker_image, but for ccache. Something like ccache_data_dir.

leugenea avatar Sep 13 '19 10:09 leugenea

Okay, but only the directory path is enough? What about env var? As your original question requires Docker, we would need to create a docker container and inject a bunch of env vars, but I have no idea about those variables, even reading the docs.

uilianries avatar Sep 13 '19 11:09 uilianries

As far as I can see, mounting host cache directory and setting env variables CCACHE_DIR (to the mounted dir) and CCACHE_COMPILERCHECK (to content) should be enough.

leugenea avatar Sep 17 '19 08:09 leugenea