Index: Mk/bsd.port.mk =================================================================== --- Mk/bsd.port.mk +++ Mk/bsd.port.mk @@ -2106,6 +2106,7 @@ .endif .include "${PORTSDIR}/Mk/bsd.ccache.mk" +.include "${PORTSDIR}/Mk/bsd.sccache.mk" .if !make(makesum) FETCH_ENV?= SSL_NO_VERIFY_PEER=1 SSL_NO_VERIFY_HOSTNAME=1 Index: Mk/bsd.sccache.mk =================================================================== --- /dev/null +++ Mk/bsd.sccache.mk @@ -0,0 +1,43 @@ +# Add wrapper for sccache. Note the binary needs to be provided +# by the system, as to avoid a chicken-egg problem in lang/rust +# which can benefit greatly from this. So other than ccache, we +# won't pull in a dpeendency on the port itself. +# +# User settable: +# +# - SCCACHE_DIR - path to the sccache directory +# - SCCACHE_BIN - path to the sccache binary - defaults to ${SCCACHE_DIR}/sccache +# this makes it easy to inject sccache into poudriere +# - SCCACHE_SIZE - size of the cache - defaults to 16G +# +# Usable by ports: +# +# - SCCACHE_ENABLED - set if SCCACHE is usable +# - NO_SCCACHE - disable sccache for the port +# +# + +COMMANDS_Include_MAINTAINER= portmgr@FreeBSD.org + +.if !defined(_SCCACHE_INCLUDED) +_SCCACHE_INCLUDED= yes +_SCCACHE_SIZE_DEFAULT= 16G + +. if defined(SCCACHE_DIR) +SCCACHE_BIN?= ${SCCACHE_DIR}/sccache +. endif + +. if !defined(NO_SCCACHE) +. if defined(SCCACHE_BIN) && exists(${SCCACHE_BIN}) +SCCACHE_ENABLED= y +SCCACHE_SIZE?= ${_SCCACHE_SIZE_DEFAULT} + +_SCCACHE_ENV= RUSTC_WRAPPER="${SCCACHE_BIN}" \ + SCCACHE_DIR="${SCCACHE_DIR}" \ + SCCACHE_SIZE="${SCCACHE_SIZE}" + +CONFIGURE_ENV+= ${_SCCACHE_ENV} +MAKE_ENV+= ${_SCCACHE_ENV} +. endif +. endif +.endif Index: lang/rust/Makefile =================================================================== --- lang/rust/Makefile +++ lang/rust/Makefile @@ -161,6 +161,9 @@ @${ECHO_CMD} 'target=[${_RUST_TARGETS:@.target.@"${.target.}"@:ts,}]' >> ${WRKSRC}/config.toml @${ECHO_CMD} 'cargo="${WRKDIR}/bootstrap/bin/cargo"' >> ${WRKSRC}/config.toml @${ECHO_CMD} 'rustc="${WRKDIR}/bootstrap/bin/rustc"' >> ${WRKSRC}/config.toml +.if defined(SCCACHE_ENABLED) + @${ECHO_CMD} 'rustc-wrapper="${SCCACHE_BIN}"' >> ${WRKSRC}/config.toml +.endif @${ECHO_CMD} 'tools=[${_RUST_TOOLS:@.tool.@"${.tool.}"@:ts,}]' >> ${WRKSRC}/config.toml @${ECHO_CMD} '[install]' >> ${WRKSRC}/config.toml @${ECHO_CMD} 'prefix="${PREFIX}"' >> ${WRKSRC}/config.toml @@ -221,6 +224,18 @@ @${ECHO_CMD} 'missing-tools=true' >> ${WRKSRC}/config.toml .endif +.if defined(SCCACHE_ENABLE) +EXTRA_PATCHES+= ${FILES_DIR}/extra-patch-sccache +.endif + +pre-configure: +.if defined(SCCACHE_ENABLE) + ${REINPLACE_CMD} -e 's|%%SCCACHE_DIR%%|${SCCACHE_DIR}|' \ + -e 's|%%SCCACHE_BIN%%|${SCCACHE_BIN}|' \ + -e 's|%%SCCACHE_SIZE%%|${SCCACHE_SIZE}|' \ + ${CONFIGURE_WRKSRC}/src/bootstrap/builder.rs +.endif + do-build: @cd ${WRKSRC} && \ ${SETENV} ${MAKE_ENV} ${PYTHON_CMD} x.py build --jobs=${MAKE_JOBS_NUMBER} Index: lang/rust/files/extra-patch-sccache =================================================================== --- /dev/null +++ lang/rust/files/extra-patch-sccache @@ -0,0 +1,12 @@ +--- src/bootstrap/builder.rs.orig 2021-07-20 13:51:10 UTC ++++ src/bootstrap/builder.rs +@@ -1068,6 +1068,9 @@ impl<'a> Builder<'a> { + if cmd != "clippy" { + cargo.env("RUSTC", self.out.join("bootstrap/debug/rustc")); + } ++ cargo.env("RUSTC_WRAPPER", "%%SCCACHE_BIN%%"); ++ cargo.env("SCCACHE_DIR", "%%SCCACHE_DIR%%"); ++ cargo.env("SCCACHE_CACHE_SIZE", "%%SCCACHE_SIZE%%"); + + // Dealing with rpath here is a little special, so let's go into some + // detail. First off, `-rpath` is a linker option on Unix platforms