From a122be2eff3e44ef7c039d052ac47da8361fd6ae Mon Sep 17 00:00:00 2001 From: Sam James Date: Sun, 1 Sep 2024 08:29:46 +0100 Subject: [PATCH 1/2] app-text/ghostscript-gpl: fix arm* build w/o neon Bug: https://bugs.gentoo.org/924757 Closes: https://bugs.gentoo.org/926891 Signed-off-by: Sam James --- ...ipt-gpl-10.03.1-arm64-neon-tesseract.patch | 35 +++++++++++++++++++ .../ghostscript-gpl-10.03.1.ebuild | 1 + 2 files changed, 36 insertions(+) create mode 100644 app-text/ghostscript-gpl/files/ghostscript-gpl-10.03.1-arm64-neon-tesseract.patch diff --git a/app-text/ghostscript-gpl/files/ghostscript-gpl-10.03.1-arm64-neon-tesseract.patch b/app-text/ghostscript-gpl/files/ghostscript-gpl-10.03.1-arm64-neon-tesseract.patch new file mode 100644 index 0000000000000..4b64fff16f5e2 --- /dev/null +++ b/app-text/ghostscript-gpl/files/ghostscript-gpl-10.03.1-arm64-neon-tesseract.patch @@ -0,0 +1,35 @@ +https://bugs.gentoo.org/926891 +https://bugs.gentoo.org/924757 +https://src.fedoraproject.org/rpms/tesseract/raw/rawhide/f/tesseract_neon.patch +(See https://github.com/tesseract-ocr/tesseract/pull/4154 too) +--- a/tesseract/CMakeLists.txt ++++ b/tesseract/CMakeLists.txt +@@ -249,7 +249,7 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64.*|AARCH64.*") + set(HAVE_AVX512F FALSE) + set(HAVE_FMA FALSE) + set(HAVE_SSE4_1 FALSE) +- set(HAVE_NEON TRUE) ++ check_cxx_compiler_flag("-mfpu=neon" HAVE_NEON) + + elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm.*") + +--- a/tesseract/src/arch/simddetect.cpp ++++ b/tesseract/src/arch/simddetect.cpp +@@ -254,7 +254,7 @@ SIMDDetect::SIMDDetect() { + // SSE detected. + SetDotProduct(DotProductSSE, &IntSimdMatrix::intSimdMatrixSSE); + #endif +-#if defined(HAVE_NEON) || defined(__aarch64__) ++#if defined(HAVE_NEON) + } else if (neon_available_) { + // NEON detected. + SetDotProduct(DotProductNEON, &IntSimdMatrix::intSimdMatrixNEON); +@@ -311,7 +311,7 @@ void SIMDDetect::Update() { + } else if (dotproduct == "accelerate") { + SetDotProduct(DotProductAccelerate, IntSimdMatrix::intSimdMatrix); + #endif +-#if defined(HAVE_NEON) || defined(__aarch64__) ++#if defined(HAVE_NEON) + } else if (dotproduct == "neon" && neon_available_) { + // NEON selected by config variable. + SetDotProduct(DotProductNEON, &IntSimdMatrix::intSimdMatrixNEON); diff --git a/app-text/ghostscript-gpl/ghostscript-gpl-10.03.1.ebuild b/app-text/ghostscript-gpl/ghostscript-gpl-10.03.1.ebuild index 54f3cdcf36f35..663558774565c 100644 --- a/app-text/ghostscript-gpl/ghostscript-gpl-10.03.1.ebuild +++ b/app-text/ghostscript-gpl/ghostscript-gpl-10.03.1.ebuild @@ -63,6 +63,7 @@ RDEPEND=" PATCHES=( "${FILESDIR}"/${PN}-10.03.0-c99.patch + "${FILESDIR}"/${PN}-10.03.1-arm64-neon-tesseract.patch ) src_prepare() { From 8db9f66124d9c5620f4f2f6db921125ba9c6fa74 Mon Sep 17 00:00:00 2001 From: Sam James Date: Sun, 1 Sep 2024 08:32:49 +0100 Subject: [PATCH 2/2] app-text/tesseract: fix arm* build w/o neon Bug: https://bugs.gentoo.org/926891 Closes: https://bugs.gentoo.org/924757 Signed-off-by: Sam James --- ...tesseract-5.4.1-arm64-neon-tesseract.patch | 57 +++++++++++++++++++ app-text/tesseract/tesseract-5.3.4.ebuild | 4 ++ app-text/tesseract/tesseract-5.4.1.ebuild | 4 ++ app-text/tesseract/tesseract-9999.ebuild | 4 ++ 4 files changed, 69 insertions(+) create mode 100644 app-text/tesseract/files/tesseract-5.4.1-arm64-neon-tesseract.patch diff --git a/app-text/tesseract/files/tesseract-5.4.1-arm64-neon-tesseract.patch b/app-text/tesseract/files/tesseract-5.4.1-arm64-neon-tesseract.patch new file mode 100644 index 0000000000000..d3869cfea1dd9 --- /dev/null +++ b/app-text/tesseract/files/tesseract-5.4.1-arm64-neon-tesseract.patch @@ -0,0 +1,57 @@ +https://bugs.gentoo.org/924757 +https://bugs.gentoo.org/926891 +https://github.com/tesseract-ocr/tesseract/pull/4154 + +(Note that if moving to CMake, can use the patch from ghostscript-gpl +instead, i.e. https://src.fedoraproject.org/rpms/tesseract/blob/rawhide/f/tesseract_neon.patch). + +From b1e48789d61d995740762f66f505385db42410a5 Mon Sep 17 00:00:00 2001 +From: Jan Palus +Date: Mon, 30 Oct 2023 01:36:57 +0100 +Subject: [PATCH] Check if NEON extension are actually available + +User may pass own compiler flags to configure which override those +provided by project through automake. Therefore it is possible for user +on ARM platform to pass CXXFLAGS=-mfpu=vfp which will effectively +disable NEON even though used compiler supports -mfpu=neon (since user +supplied flags take precedence compiler invocation will use flags: +-mfpu=neon -mfpu=vfp). Instead of checking whether compiler supports +-mfpu=neon flag, check if NEON extensions are available by checking if +__ARM_NEON is defined when compiling with -mfpu=neon and user supplied +flags combined. + +Signed-off-by: Jan Palus +--- + configure.ac | 18 ++++++++++++++---- + 1 file changed, 14 insertions(+), 4 deletions(-) + +diff --git a/configure.ac b/configure.ac +index 0b38537229..0514b619c5 100644 +--- a/configure.ac ++++ b/configure.ac +@@ -178,10 +178,20 @@ case "${host_cpu}" in + ;; + + arm*) +- +- AX_CHECK_COMPILE_FLAG([-mfpu=neon], [neon=true], [neon=false], [$WERROR]) +- AM_CONDITIONAL([HAVE_NEON], $neon) +- if $neon; then ++ SAVE_CXXFLAGS="$CXXFLAGS" ++ CXXFLAGS="-mfpu=neon $CXXFLAGS" ++ AC_MSG_CHECKING([for NEON support]) ++ AC_COMPILE_IFELSE( ++ [AC_LANG_PROGRAM([], [[ ++ #ifndef __ARM_NEON ++ #error ++ #endif ++ ]])], ++ [neon=yes], [neon=no]) ++ AC_MSG_RESULT([$neon]) ++ CXXFLAGS="$SAVE_CXXFLAGS" ++ AM_CONDITIONAL([HAVE_NEON], test "xyes" = "x$neon") ++ if test "xyes" = "$neon"; then + AC_DEFINE([HAVE_NEON], [1], [Enable NEON instructions]) + NEON_CXXFLAGS="-mfpu=neon" + AC_SUBST([NEON_CXXFLAGS]) + diff --git a/app-text/tesseract/tesseract-5.3.4.ebuild b/app-text/tesseract/tesseract-5.3.4.ebuild index d90adb970643b..af83b0284a3ac 100644 --- a/app-text/tesseract/tesseract-5.3.4.ebuild +++ b/app-text/tesseract/tesseract-5.3.4.ebuild @@ -37,6 +37,10 @@ DEPEND="${COMMON_DEPEND} dev-libs/libxslt doc? ( app-text/doxygen )" +PATCHES=( + "${FILESDIR}"/${PN}-5.4.1-arm64-neon-tesseract.patch +) + pkg_pretend() { [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp } diff --git a/app-text/tesseract/tesseract-5.4.1.ebuild b/app-text/tesseract/tesseract-5.4.1.ebuild index 1469566c29edf..d4438214a13db 100644 --- a/app-text/tesseract/tesseract-5.4.1.ebuild +++ b/app-text/tesseract/tesseract-5.4.1.ebuild @@ -32,6 +32,10 @@ DEPEND="${COMMON_DEPEND} dev-libs/libxslt doc? ( app-text/doxygen )" +PATCHES=( + "${FILESDIR}"/${PN}-5.4.1-arm64-neon-tesseract.patch +) + pkg_pretend() { [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp } diff --git a/app-text/tesseract/tesseract-9999.ebuild b/app-text/tesseract/tesseract-9999.ebuild index 4c31653fca31b..d3c34531c7240 100644 --- a/app-text/tesseract/tesseract-9999.ebuild +++ b/app-text/tesseract/tesseract-9999.ebuild @@ -32,6 +32,10 @@ DEPEND="${COMMON_DEPEND} dev-libs/libxslt doc? ( app-text/doxygen )" +PATCHES=( + "${FILESDIR}"/${PN}-5.4.1-arm64-neon-tesseract.patch +) + pkg_pretend() { [[ ${MERGE_TYPE} != binary ]] && use openmp && tc-check-openmp }