Hi all,

Below is a diff for bsd.port.mk that allows us to set USE_SCCACHE=Yes
in /etc/mk.conf to use sccache. Manual page updates are included,
which I copied and adapted from the ccache bits.

Note that with the diff below, sccache is only used for Rust code,
not for C/C++ (which sccache also supports). So at least at this
moment, USE_CCACHE=Yes and USE_SCCACHE=Yes don't bite each other
(ccache will cache C/C++ compilation results, sccache will cache
Rust compilation results). This may change later if we want to use
sccache for C/C++ too, which at the moment does not work yet.

Another thing to note is that sccache uses a client-server model;
quote from the README:

> sccache works using a client-server model, where the server runs
> locally on the same machine as the client. The client-server model
> allows the server to be more efficient by keeping some state in
> memory. The sccache command will spawn a server process if one is
> not already running, or you can run sccache --start-server to start
> the background server process without performing any compilation.
> 
> You can run sccache --stop-server to terminate the server. It will
> also terminate after (by default) 10 minutes of inactivity.

So don't be surprised if a sccache process is still running when
you hit ^C on the compilation process.

I have used this now for quite some time and I didn't find any
problems so far. Comments or OKs?

First follows the diff for bsd.port.mk, and after that the diff for
its manual page.

Caspar


Index: bsd.port.mk
===================================================================
RCS file: /cvs/ports/infrastructure/mk/bsd.port.mk,v
retrieving revision 1.1630
diff -u -p -r1.1630 bsd.port.mk
--- bsd.port.mk 26 Oct 2023 19:26:56 -0000      1.1630
+++ bsd.port.mk 9 Nov 2023 16:18:45 -0000
@@ -228,6 +228,7 @@ PARALLEL_MAKE_FLAGS ?= -j${MAKE_JOBS}
 TRY_BROKEN ?= No
 
 USE_CCACHE ?= No
+USE_SCCACHE ?= No
 
 WARNINGS ?= no
 
@@ -446,6 +447,17 @@ CONFIGURE_ENV += CCACHE_DIR=${CCACHE_DIR
 COMPILER_WRAPPER += env CCACHE_DIR=${CCACHE_DIR} ${CCACHE_ENV} ccache
 .  if !exists(${LOCALBASE}/bin/ccache)
 ERRORS += "Fatal: USE_CCACHE is set, but ccache is not installed."
+.  endif
+.endif
+NO_SCCACHE ?= No
+SCCACHE_ENV ?=
+.if ${USE_SCCACHE:L} == "yes" && ${NO_SCCACHE:L} == "no" && ${NO_BUILD:L} == 
"no"
+SCCACHE_DIR ?= ${WRKOBJDIR_${PKGPATH}}/.sccache
+MAKE_ENV += SCCACHE_DIR=${SCCACHE_DIR} ${SCCACHE_ENV}
+MAKE_ENV += RUSTC_WRAPPER=${LOCALBASE}/bin/sccache
+CONFIGURE_ENV += SCCACHE_DIR=${SCCACHE_DIR}
+.  if !exists(${LOCALBASE}/bin/sccache)
+ERRORS += "Fatal: USE_SCCACHE is set, but sccache is not installed."
 .  endif
 .endif
 


Index: bsd.port.mk.5
===================================================================
RCS file: /cvs/src/share/man/man5/bsd.port.mk.5,v
retrieving revision 1.638
diff -u -p -r1.638 bsd.port.mk.5
--- bsd.port.mk.5       2 Nov 2023 16:14:46 -0000       1.638
+++ bsd.port.mk.5       9 Nov 2023 16:19:23 -0000
@@ -2523,6 +2523,13 @@ See also
 .Ev IGNORE
 and
 .Ev TRY_BROKEN .
+.It Ev NO_SCCACHE
+Set to
+.Sq Yes
+to prevent sccache from being used when building a certain port,
+even when
+.Ev USE_SCCACHE
+is set.
 .It Ev NO_TEST
 Port does not have any regression tests.
 Only set to
@@ -3171,6 +3178,15 @@ The corresponding packages will be built
 stage, and
 .Xr pkg_add 1
 will take care of installing them.
+.It Ev SCCACHE_DIR
+Sets the cache directory used when
+.Ev USE_SCCACHE
+is set to yes.
+Defaults to ${WRKOBJDIR}/.sccache.
+.It Ev SCCACHE_ENV
+Sets additional environment variables when
+.Ev USE_SCCACHE
+is set to yes.
 .It Ev SEPARATE_BUILD
 Many GNU configure ports can be built in a directory distinct from the
 place they were unpacked.
@@ -3656,6 +3672,12 @@ adding
 .Fl -no-execute-only .
 Use when a port does not work with execute-only (unreadable) code sections
 which are used by default by the linker on some architectures.
+.It Ev USE_SCCACHE
+User settings.
+Set to
+.Sq Yes
+to use sccache when building ports.
+Sets up the build environment so that it is used.
 .It Ev USE_WXNEEDED
 If set to
 .Sq Yes ,

Reply via email to