On Thu, Nov 09, 2023 at 06:37:49PM +0000, Klemens Nanni wrote: > On Thu, Nov 09, 2023 at 07:26:41PM +0100, Caspar Schutijser wrote: > > On Thu, Nov 09, 2023 at 05:54:33PM +0100, Caspar Schutijser wrote: > > > 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. > > > > Here is an updated diff. kn@ made good point: a "normal" user may > > use sccache too, but then that user would end up using _pbuild's > > instance of sccache because sccache communicates over TCP and by > > default uses port 4226 (or the other way around, whichever starts the > > sccache server first). I picked 44226 as the port number that we'll > > use for bsd.port.mk. I don't think we need to document this. > > Unfortunately there's no way to communicate over a socket, which > > I would have preferred over using TCP for this. > > That makes sense, thanks. > > > > > Comments or OKs on this version? > > OK kn, but I'd also add blank lines around the ccache and sccache blocks.
Alright, thanks. Diff for that below (should be obvious). I also tweaked the manual page a little bit; at the bottom of the diff, I mention that USE_SCCACHE=Yes sets it up specifically for Rust (otherwise, people may expect it to cache results for C and C++ too, which is not true). Comments or OKs? 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 10 Nov 2023 11:52:50 -0000 @@ -228,6 +228,7 @@ PARALLEL_MAKE_FLAGS ?= -j${MAKE_JOBS} TRY_BROKEN ?= No USE_CCACHE ?= No +USE_SCCACHE ?= No WARNINGS ?= no @@ -436,6 +437,7 @@ MAKE_FLAGS += LIBTOOL="${_LIBTOOL}" ${_l .endif # log for the SHARED_LIBS override MAKE_FLAGS += SHARED_LIBS_LOG=${WRKBUILD}/shared_libs.log + NO_CCACHE ?= No CCACHE_ENV ?= .if ${USE_CCACHE:L} == "yes" && ${NO_CCACHE:L} == "no" && ${NO_BUILD:L} == "no" @@ -446,6 +448,18 @@ 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_SERVER_PORT=44226 SCCACHE_DIR=${SCCACHE_DIR} ${SCCACHE_ENV} +MAKE_ENV += RUSTC_WRAPPER=${LOCALBASE}/bin/sccache +CONFIGURE_ENV += SCCACHE_SERVER_PORT=44226 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 10 Nov 2023 11:55:20 -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 for Rust code. .It Ev USE_WXNEEDED If set to .Sq Yes ,