Tuesday, June 28, 2022

Re: scons and ccache

On 2022/06/28 12:47, Omar Polo wrote:
> This is an attempt to use ccache with scons. I'd really like to have
> something like this to avoid waiting 30/40 minutes for Godot to build.
>
> part of the issue is that scons executes the compiler in a clear
> environment for some reasons and thus we loose CCACHE_DIR, ccache then
> tries to write to $HOME/.ccache and so we can't just unsed NO_CCACHE
> from scons.port.mk and enjoy the speed-up.
>
> However, scons uses the compiler we want, so if we tweak the compiler
> wrapper to inject CCACHE_DIR we win!
>
> This allows to pass from:
> 2244.08 real 7359.21 user 644.35 sys
> to
> 213.30 real 147.20 user 162.25 sys
>
> when building games/godot with a warm cache. it's really nice :)
>
> To be fair, scons has its own caching mechanism built-in[0] but I don't
> think we can use it as we would need to patch the SConscript files to
> add CacheDir (well, we have to patch 'em anyway almost always in the
> end, but i don't think it'd be a good idea to add this too.)
>
> [0]: https://scons.org/doc/production/HTML/scons-user.html#chap-caching
>
> There are also other things that we may consider in the future to speed
> up scons builds a little bit more. The recent-ish support for building
> with ninja is interesting for example, with that over ccache I can build
> godot with a warm cache in 197s, but it's still marked as experimental.
>
> Thoughts?
>
> Index: infrastructure/mk/bsd.port.mk
> ===================================================================
> RCS file: /home/cvs/ports/infrastructure/mk/bsd.port.mk,v
> retrieving revision 1.1573
> diff -u -p -r1.1573 bsd.port.mk
> --- infrastructure/mk/bsd.port.mk 19 May 2022 13:12:40 -0000 1.1573
> +++ infrastructure/mk/bsd.port.mk 28 Jun 2022 10:13:18 -0000
> @@ -447,7 +447,7 @@ CCACHE_ENV ?=
> CCACHE_DIR ?= ${WRKOBJDIR_${PKGPATH}}/.ccache
> MAKE_ENV += CCACHE_DIR=${CCACHE_DIR} ${CCACHE_ENV}
> CONFIGURE_ENV += CCACHE_DIR=${CCACHE_DIR}
> -COMPILER_WRAPPER += ccache
> +COMPILER_WRAPPER += env CCACHE_DIR=${CCACHE_DIR} ccache

In case somebody set another flag in CCACHE_ENV as well, it should add that,
and I think it's worth a comment in this case:

# scons cleans the environment when calling the compiler
COMPILER_WRAPPER += env CCACHE_DIR=${CCACHE_DIR} ${CCACHE_ENV} ccache

Otherwise OK, though I do wonder if scons.port.mk could arrange something so
that ${MAKE_ENV} is passed through properly..

> . if !exists(${LOCALBASE}/bin/ccache)
> ERRORS += "Fatal: USE_CCACHE is set, but ccache is not installed."
> . endif
> Index: devel/scons/scons.port.mk
> ===================================================================
> RCS file: /home/cvs/ports/devel/scons/scons.port.mk,v
> retrieving revision 1.11
> diff -u -p -r1.11 scons.port.mk
> --- devel/scons/scons.port.mk 7 Jun 2022 11:38:09 -0000 1.11
> +++ devel/scons/scons.port.mk 28 Jun 2022 10:13:44 -0000
> @@ -20,7 +20,6 @@ MODSCONS_ENV?= CC="${CC}" \
>
> MODSCONS_FLAGS?=
> ALL_TARGET?=
> -NO_CCACHE?=Yes
>
> MODSCONS_BUILD_TARGET = \
> ${SETENV} ${MAKE_ENV} ${MODSCONS_BIN} -C ${WRKSRC} \
>

No comments:

Post a Comment