git: d4f780099d80 - main - lang/swift510: fix build on low RAM, ccache support

From: Matthias Andree <mandree_at_FreeBSD.org>
Date: Mon, 30 Jun 2025 13:21:47 UTC
The branch main has been updated by mandree:

URL: https://cgit.FreeBSD.org/ports/commit/?id=d4f780099d800b87701e4341a68666b318219097

commit d4f780099d800b87701e4341a68666b318219097
Author:     Matthias Andree <mandree@FreeBSD.org>
AuthorDate: 2025-06-30 09:16:04 +0000
Commit:     Matthias Andree <mandree@FreeBSD.org>
CommitDate: 2025-06-30 13:21:35 +0000

    lang/swift510: fix build on low RAM, ccache support
    
    The port did not pass down MAKE_JOBS_NUMBER to swift's build
    scripts, and Swiwt/LLVM are C++ ports and memory hungry.
    
    Also, due to lack of CCACHE support, the port cannot pick up
    where the OOM killer struck easily in, say poudriere.
    
    Pass down --jobs ${MAKE_JOBS_NUMBER} if MAKE_JOBS_NUMBER is
    defined and not empty.
    
    While here, also support CCACHE builds so we can actually restart
    in case the MAKE_JOBS_NUMBER is still too high relative to the
    build host's memory.
    
    This let me successfully build in one single attempt
    with MAKE_JOBS_NUMBER=5 in /etc/make.conf on a 16 GB computer
    that previously failed persistently because the port
    attempted to build with all I have, meaning 16 jobs.
    
    While here, support CCACHE build.
    
    Approved by:    portmgr@ (blanket just-fix-it)
---
 lang/swift510/Makefile             | 6 +++++-
 lang/swift510/files/start-build.sh | 5 +++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/lang/swift510/Makefile b/lang/swift510/Makefile
index 4e57dce3f519..b22f7ca799ec 100644
--- a/lang/swift510/Makefile
+++ b/lang/swift510/Makefile
@@ -94,7 +94,11 @@ post-patch:
 
 do-build:
 	@${MKDIR} ${early_stage_dir}
-	@${SH} ${FILESDIR}/start-build.sh ${WRKSRC} ${early_stage_dir} ${swift_install_prefix} ${WRKDIR}/clang-module-cache
+	${SETENV} \
+		CCACHE_WRAPPER_PATH=${CCACHE_WRAPPER_PATH} \
+		MAKE_JOBS_NUMBER=${MAKE_JOBS_NUMBER} \
+		${SH} -x ${FILESDIR}/start-build.sh ${WRKSRC} ${early_stage_dir} \
+			${swift_install_prefix} ${WRKDIR}/clang-module-cache
 
 do-install:
 	@${FIND} ${early_stage_dir}${swift_install_prefix}/bin -type f -not -name '*.py' -not -name '*.sh' -not -name '*.txt' -exec ${STRIP_CMD} '{}' ';' ; \
diff --git a/lang/swift510/files/start-build.sh b/lang/swift510/files/start-build.sh
index a15ad0440540..da8e7fbbe0b2 100644
--- a/lang/swift510/files/start-build.sh
+++ b/lang/swift510/files/start-build.sh
@@ -12,8 +12,9 @@ cd ${swift_project_dir}/swift &&
 utils/build-script --bootstrapping bootstrapping \
 --release \
 --assertions \
---host-cc /usr/bin/clang \
---host-cxx /usr/bin/clang++ \
+${MAKE_JOBS_NUMBER+--jobs} ${MAKE_JOBS_NUMBER} \
+--host-cc ${CCACHE_WRAPPER_PATH:-/usr/bin}/clang \
+--host-cxx ${CCACHE_WRAPPER_PATH:-/usr/bin}/clang++ \
 --llvm-targets-to-build 'AArch64;X86' \
 --skip-early-swift-driver \
 --skip-early-swiftsyntax \