Menu

#298 Support buildng via compiler cache (ccache)

3.x Stable
open
nobody
None
5
2020-09-01
2020-08-25
f0rt
No

Debian's Gitlab continous integration (CI) pipeline uses the compiler cache.

ccache depends on the CCACHE_DIR environment variable. As a consequence scons would need to propagate this environment variable. A possible patch could look like the following:

--- a/SConstruct
+++ b/SConstruct
@@ -201,6 +201,9 @@
 opts.Update(defenv)
 Help(opts.GenerateHelpText(defenv))

+for key in(filter(lambda key: key in os.environ, ['CCACHE_DIR'])):
+   defenv['ENV'][key] = os.environ[key]
+
 if defenv['TARGET_ARCH'] != 'x86':
    defenv['UNICODE'] = True

Discussion

  • Amir Szekely

    Amir Szekely - 2020-08-25

    Let's do something simpler like:

    if 'CCACHE_DIR' in os.environ:
      defenv['ENV']['CCACHE_DIR'] = os.environ['CCACHE_DIR']
    
     
  • f0rt

    f0rt - 2020-08-26

    I agree. I would appreciate if you could integrate your code.

     
  • Amir Szekely

    Amir Szekely - 2020-08-29

    Have you tried something like scons CC="CCACHE_DIR=/tmp/whatever ccache"? Seems to work for me in a very limited test.

     
  • f0rt

    f0rt - 2020-08-31

    Your proposal to propagate the CCACHE_DIR environment variable via the command line argument CC="CACHE_DIR=/tmp/whatever ccache" seems to work.

    I assume the same has to be done for CXX and for the cross compilers (i686-w64-mingw32-gcc, i686-w64-mingw32-g++).

    This feels more like a workaround than a solution.

    main.c

    int main(int argc, char *argv[]) { return 42; }
    

    SConstruct

    defenv = DefaultEnvironment()
    Export('defenv')
    
    opts = Variables()
    opts.Add(('CC', 'Override C compiler', None))
    opts.Update(defenv)
    
    defenv.Program('main.c')
    print(defenv.Dump())
    

    Test setting of ${CCACHE_DIR} environment variable

    scons CC='CCACHE_DIR=/tmp/ccache; echo $${CCACHE_DIR}'
    
    scons: Building targets ...
    CCACHE_DIR=/tmp/ccache; echo ${CCACHE_DIR} -o main.o -c main.c
    /tmp/ccache -o main.o -c main.c
    CCACHE_DIR=/tmp/ccache; echo ${CCACHE_DIR} -o main main.o
    /tmp/ccache -o main main.o
    scons: done building targets.
    
     

    Last edit: f0rt 2020-08-31
  • Amir Szekely

    Amir Szekely - 2020-08-31

    SCons doesn't have built-in support for ccache, so it's all workarounds unless there is a proper tool definition. Don't you already need to override CC and CXX with ccache anyway?

    If we add a tool like the ones in SCons/Tools, then it would be an even simpler scons TOOLS=ccache.

     
  • f0rt

    f0rt - 2020-09-01

    Thanks a lot for your explanation. I am going to give the idea of overriding CC adn CXX more thought.

    Currently there is no need to override CC and CXX.

    scons picks up the installed GNU C and C++ compiler (symbolic link named as the respective compiler pointing to the ccache executable).

    For example the following command line is used to build the makensis compiler

    scons APPEND_CCFLAGS="-Wdate-time -D_FORTIFY_SOURCE=2 -g -O2 -fdebug-prefix-map=/builds/debian/nsis/debian/output/nsis-3.06.1=. -fstack-protector-strong -Wformat -Werror=format-security" APPEND_LINKFLAGS="-Wl,-z,relro -Wl,-z,now"  VERSION=3.06.1-1+salsaci VER_MAJOR=3 VER_MINOR=06 VER_REVISION=1 PREFIX=/usr PREFIX_CONF=/etc CHMDOCS=0 STRIP_CP=no  UNICODE=yes SKIPPLUGINS=all SKIPSTUBS=all SKIPUTILS='Library/RegTool,MakeLangId,Makensisw,NSIS Menu,UIs,SubStart,zip2exe' SKIPDOC=COPYING makensis
    

    and scons is invoked for cross compiling of stubs, plugins and utilities such as:

    scons  VERSION=3.06.1-1+salsaci VER_MAJOR=3 VER_MINOR=06 VER_REVISION=1 PREFIX=/usr PREFIX_CONF=/etc CHMDOCS=0 STRIP_CP=no  UNICODE=yes SKIPUTILS=',MakeLangId,Makensisw,NSIS Menu,SubStart,VPatch/Source/GenPat,zip2exe' SKIPDOC=COPYING PREFIX_PLUGINAPI_INC=/usr/i686-w64-mingw32/include/ PREFIX_PLUGINAPI_LIB=/usr/i686-w64-mingw32/lib/ XGCC_W32_PREFIX=i686-w64-mingw32- TARGET_ARCH=x86 stubs plugins util
    
     

Log in to post a comment.