[Replicant] Introducing ccache to Replicant 6

Tobias Tefke tefke at stud.fh-sm.de
Thu Apr 2 11:58:37 UTC 2020


Hi,


The following patch set introduces ccache to Replicant 6.

Ccache is a compiler cache for C/C++ [1] licensed under the GNU GPL
version 3 [2].

Including it speeds up the build time for me about 1/3.


The following environment variables can be set to use ccache:

USE_CCACHE: setting it enables ccache during the build [3]

CCACHE_DIR: allows to set a custom directory where compiled files are
cached.

Otherwise the files will be stored at $HOME/.ccache [4]


Running ./toolchain/ccache/ccache -M SIZE allows the user to modify the
maximum size of files

that are stored. Note that you have to put the unit directly after the size

so setting the size at 50GB has to be done the following way:

./toolchain/ccache/ccache -M 50G [4]


References:

[1] https://ccache.dev/

[2] https://ccache.dev/license.html

[3] build/core/ccache.mk

[4] https://ccache.dev/manual/3.7.9.html


Patches:


The first patch must be applied to the manifest to track the latest
stable version available on GitHub:


From d7c92d450b23bd39246702c2022c81ee837bb1df Mon Sep 17 00:00:00 2001
From: Tobias Tefke <t.tefke at stud.fh-sm.de>
Date: Thu, 2 Apr 2020 13:28:11 +0200
Subject: [PATCH] [1/3] Track ccache for toolchain

Signed-off-by: Tobias Tefke <t.tefke at stud.fh-sm.de>
---
 default.xml | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/default.xml b/default.xml
index caca595..d4ac716 100644
--- a/default.xml
+++ b/default.xml
@@ -19,6 +19,9 @@
   <remote  name="private"
            fetch="ssh://git@github.com" />
 
+  <remote name="github"
+          fetch="https://github.com" />
+
   <default revision="refs/heads/cm-13.0"
            remote="lineage-mirror"
            sync-c="true"
@@ -514,6 +517,7 @@
 <project path="toolchain/src/gcc" name="replicant/toolchain_gcc.git"
remote="replicant" revision="master" />
 <project path="toolchain/src/jack" name="replicant/toolchain_jack.git"
remote="replicant" />
 <project path="toolchain/src/jill" name="replicant/toolchain_jill.git"
remote="replicant" />
+<project path="toolchain/src/ccache" name="ccache/ccache.git"
revision="3.7-maint" remote="github" />
 
 <!-- KERNEL -->
   <project path="kernel/samsung/smdk4412"
name="replicant/kernel_samsung_smdk4412.git" remote="replicant" />
-- 
2.11.0


The second patch must be applied to build/core to change the ccacke.mk
file according to our needs:


From e7fdddc62b2ed255864a7dc76a6bd0cbd5a852d0 Mon Sep 17 00:00:00 2001
From: Tobias Tefke <t.tefke at stud.fh-sm.de>
Date: Thu, 2 Apr 2020 13:31:10 +0200
Subject: [PATCH] [2/3] Use our own ccache binary if requested

Signed-off-by: Tobias Tefke <t.tefke at stud.fh-sm.de>
---
 core/ccache.mk | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/core/ccache.mk b/core/ccache.mk
index bd60ebf26..2414a6be3 100644
--- a/core/ccache.mk
+++ b/core/ccache.mk
@@ -39,17 +39,25 @@ ifneq ($(USE_CCACHE),)
   export CCACHE_CPP2 := true
 
   # Detect if the system already has ccache installed to use instead of
the prebuilt
-  ccache := $(shell which ccache)
+  #ccache := $(shell which ccache)
 
-  ifeq ($(ccache),)
-    CCACHE_HOST_TAG := $(HOST_PREBUILT_TAG)
+  #ifeq ($(ccache),)
+    #CCACHE_HOST_TAG := $(HOST_PREBUILT_TAG)
     # If we are cross-compiling Windows binaries on Linux
     # then use the linux ccache binary instead.
-    ifeq ($(HOST_OS)-$(BUILD_OS),windows-linux)
-      CCACHE_HOST_TAG := linux-$(HOST_PREBUILT_ARCH)
-    endif
-    ccache := prebuilts/misc/$(CCACHE_HOST_TAG)/ccache/ccache
-  endif
+    #ifeq ($(HOST_OS)-$(BUILD_OS),windows-linux)
+    #  CCACHE_HOST_TAG := linux-$(HOST_PREBUILT_ARCH)
+    #endif
+    #ccache := prebuilts/misc/$(CCACHE_HOST_TAG)/ccache/ccache
+  #endif
+
+  # We don't need the commented lines above.
+  # We should't check for a prebuilt version of ccache because
+  # we should build the binaries we use ourself.
+  # The only platform Replicant should be built on is GNU/Linux.
+  # Therefore we don't need binaries for other platforms.
+  # This allows us to directly include the binary we built for our
toolchain.
+  ccache := toolchain/ccache/ccache
 
   # Check that the executable is here.
   ccache := $(strip $(wildcard $(ccache)))
-- 
2.11.0


The last patch must be applied to vendor/replicant to build our own
ccache binary while building the toolchain:


From 3326ad820b94d4d779edf3721d25bda19206b42b Mon Sep 17 00:00:00 2001
From: Tobias Tefke <t.tefke at stud.fh-sm.de>
Date: Thu, 2 Apr 2020 13:32:24 +0200
Subject: [PATCH] [3/3] toolchain: build ccache

Signed-off-by: Tobias Tefke <t.tefke at stud.fh-sm.de>
---
 build-toolchain | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/build-toolchain b/build-toolchain
index 727bd81b..1046ebba 100755
--- a/build-toolchain
+++ b/build-toolchain
@@ -182,4 +182,13 @@ cd ../src/jill
 ant clean dist
 cp ../../jack_jill/build/jill/dist/jill.jar ../../jack_jill/
 
+# ccache
+mkdir -p $BASEDIR/toolchain/ccache
+cd ../ccache
+./autogen.sh
+./configure
+make
+cp ccache ../../ccache
+make clean
+
 cd $BASEDIR
-- 
2.11.0


Yours,


Tobias


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.osuosl.org/pipermail/replicant/attachments/20200402/8582c483/attachment.asc>


More information about the Replicant mailing list