git: 967022fd812c - main - Mk/Uses/cargo.mk: Enable WITH_LTO by default

From: Daniel Engberg <diizzy_at_FreeBSD.org>
Date: Sat, 07 Jan 2023 19:24:40 UTC
The branch main has been updated by diizzy:

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

commit 967022fd812cf67dec264ee4e53bd016b69e7a2b
Author:     Daniel Engberg <diizzy@FreeBSD.org>
AuthorDate: 2023-01-07 19:08:44 +0000
Commit:     Daniel Engberg <diizzy@FreeBSD.org>
CommitDate: 2023-01-07 19:22:36 +0000

    Mk/Uses/cargo.mk: Enable WITH_LTO by default
    
    Ports utilizing Cargo will now enable Link Time Optimization (LTO),
    set error handling mechanism to abort and codegen-units to 1 by default.
    Exceptions are powerpc64 and riscv64 where LTO is known to be broken
    and disabled to avoid unnecessary breakage. Ports utilizing LTO will
    output "Additional optimization to port applied" during build.
    WITH_LTO is handled by Mk/Features/lto.mk and to disable define
    LTO_UNSAFE=yes.
    
    I'd also like to mention arrowd and tobik for helpful input
    and thanks to everyone involved.
    
    Reviewed by:    mikael (via irc), pkubaj
    Tested by:      eduardo (build)
    Approved by:    rust (mikael, pkubaj)
    Differential Revision:  https://reviews.freebsd.org/D36736
---
 Mk/Uses/cargo.mk | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/Mk/Uses/cargo.mk b/Mk/Uses/cargo.mk
index 5b6dfd268404..d3d7556c7630 100644
--- a/Mk/Uses/cargo.mk
+++ b/Mk/Uses/cargo.mk
@@ -139,6 +139,11 @@ CARGO_ENV+= \
 CARGO_ENV+=	RUST_BACKTRACE=1
 .  endif
 
+.  if !defined(LTO_UNSAFE) || (defined(LTO_DISABLE_CHECK) && ${ARCH} == powerpc64) || (defined(LTO_DISABLE_CHECK) && ${ARCH} == riscv64)
+_CARGO_MSG=	"===>   Additional optimization to port applied"
+WITH_LTO=	yes
+.  endif
+
 # Adjust -C target-cpu if -march/-mcpu is set by bsd.cpu.mk
 .  if ${ARCH} == amd64 || ${ARCH} == i386
 RUSTFLAGS+=	${CFLAGS:M-march=*:S/-march=/-C target-cpu=/}
@@ -295,6 +300,9 @@ cargo-configure:
 # Check that the running kernel has COMPAT_FREEBSD11 required by lang/rust post-ino64
 	@${SETENV} CC="${CC}" OPSYS="${OPSYS}" OSVERSION="${OSVERSION}" WRKDIR="${WRKDIR}" \
 		${SH} ${SCRIPTSDIR}/rust-compat11-canary.sh
+.    if defined(_CARGO_MSG)
+	@${ECHO_MSG} ${_CARGO_MSG}
+.    endif
 	@${ECHO_MSG} "===>   Cargo config:"
 	@${MKDIR} ${WRKDIR}/.cargo
 	@: > ${WRKDIR}/.cargo/config.toml