git: dd2c7b778901 - main - www/qt6-webengine: fix build on armv7

From: Robert Clausecker <fuz_at_FreeBSD.org>
Date: Mon, 05 Jun 2023 16:54:09 UTC
The branch main has been updated by fuz:

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

commit dd2c7b778901a7b310d37f044c0018de1603c37f
Author:     Robert Clausecker <fuz@FreeBSD.org>
AuthorDate: 2023-05-03 14:59:15 +0000
Commit:     Robert Clausecker <fuz@FreeBSD.org>
CommitDate: 2023-06-05 16:53:00 +0000

    www/qt6-webengine: fix build on armv7
    
    Improve two patches with more complete variants from devel/electron19.
    Patch bundled boringssl with additional patches from the same port.
    Avoid an OOM condition by using the same extra patch previously only
    used on i386.  In that patch, decreate BROTLI_PARAM_QUALITY further
    to 4 to avoid flakiness on armv7.
    
    Obtained from:  devel/electron19
    Approved by:    kai (with hat: kde, maintainer)
    PR:             271228
---
 www/qt6-webengine/Makefile                         |  6 +--
 ...iles_js => extra-patch-32bit-compress_files_js} |  2 +-
 ...mium_third__party_boringssl_BUILD.generated.gni |  9 ++--
 ..._party_boringssl_src_crypto_cpu__arm__freebsd.c | 55 ++++++++++++++++++++++
 ...y_chromium_third__party_skia_src_core_SkCpu.cpp | 25 +++++++++-
 ...romium_v8_src_base_platform_platform-freebsd.cc |  2 +-
 6 files changed, 90 insertions(+), 9 deletions(-)

diff --git a/www/qt6-webengine/Makefile b/www/qt6-webengine/Makefile
index 1785daecb9f1..2e4d8f546493 100644
--- a/www/qt6-webengine/Makefile
+++ b/www/qt6-webengine/Makefile
@@ -15,7 +15,7 @@
 
 PORTNAME=	webengine
 DISTVERSION=	${QT6_VERSION}
-PORTREVISION=	5
+PORTREVISION=	6
 CATEGORIES=	www
 PKGNAMEPREFIX=	qt6-
 
@@ -109,8 +109,8 @@ SNDIO_CMAKE_OFF=	-DQT_FEATURE_webengine_system_sndio:BOOL=OFF
 
 .include <bsd.port.pre.mk>
 
-.if ${ARCH} == i386
-EXTRA_PATCHES+=	${PATCHDIR}/extra-patch-i386-compress_files_js
+.if ${ARCH} == i386 || ${ARCH} == armv7
+EXTRA_PATCHES+=	${PATCHDIR}/extra-patch-32bit-compress_files_js
 .endif
 
 post-extract:
diff --git a/www/qt6-webengine/files/extra-patch-i386-compress_files_js b/www/qt6-webengine/files/extra-patch-32bit-compress_files_js
similarity index 92%
rename from www/qt6-webengine/files/extra-patch-i386-compress_files_js
rename to www/qt6-webengine/files/extra-patch-32bit-compress_files_js
index 80ea9a241cf1..f8841846ef6c 100644
--- a/www/qt6-webengine/files/extra-patch-i386-compress_files_js
+++ b/www/qt6-webengine/files/extra-patch-32bit-compress_files_js
@@ -8,7 +8,7 @@ node.js stops with either SIGSEGV or SIGABRT after ~530 processed files.
    output.write(Buffer.from(sizeHeader));
    return new Promise((resolve, reject) => {
 -    pipeline(Readable.from(sourceData), zlib.createBrotliCompress(), output, err => {
-+    pipeline(Readable.from(sourceData), zlib.createBrotliCompress({ params: { [zlib.constants.BROTLI_PARAM_QUALITY]: 5 } }), output, err => {
++    pipeline(Readable.from(sourceData), zlib.createBrotliCompress({ params: { [zlib.constants.BROTLI_PARAM_QUALITY]: 4 } }), output, err => {
        return err ? reject(err) : resolve();
      });
    });
diff --git a/www/qt6-webengine/files/patch-src_3rdparty_chromium_third__party_boringssl_BUILD.generated.gni b/www/qt6-webengine/files/patch-src_3rdparty_chromium_third__party_boringssl_BUILD.generated.gni
index d56bf128afe3..bf3f823921b2 100644
--- a/www/qt6-webengine/files/patch-src_3rdparty_chromium_third__party_boringssl_BUILD.generated.gni
+++ b/www/qt6-webengine/files/patch-src_3rdparty_chromium_third__party_boringssl_BUILD.generated.gni
@@ -1,14 +1,17 @@
---- src/3rdparty/chromium/third_party/boringssl/BUILD.generated.gni.orig	2022-09-26 10:05:50 UTC
+--- src/3rdparty/chromium/third_party/boringssl/BUILD.generated.gni.orig	2022-12-12 18:53:13 UTC
 +++ src/3rdparty/chromium/third_party/boringssl/BUILD.generated.gni
-@@ -81,6 +81,7 @@ crypto_sources = [
+@@ -81,8 +81,10 @@ crypto_sources = [
    "src/crypto/cpu_aarch64_apple.c",
    "src/crypto/cpu_aarch64_fuchsia.c",
    "src/crypto/cpu_aarch64_linux.c",
 +  "src/crypto/cpu_aarch64_openbsd.c",
    "src/crypto/cpu_aarch64_win.c",
    "src/crypto/cpu_arm.c",
++  "src/crypto/cpu_arm_freebsd.c",
    "src/crypto/cpu_arm_linux.c",
-@@ -186,6 +187,7 @@ crypto_sources = [
+   "src/crypto/cpu_arm_linux.h",
+   "src/crypto/cpu_intel.c",
+@@ -186,6 +188,7 @@ crypto_sources = [
    "src/crypto/rand_extra/deterministic.c",
    "src/crypto/rand_extra/forkunsafe.c",
    "src/crypto/rand_extra/fuchsia.c",
diff --git a/www/qt6-webengine/files/patch-src_3rdparty_chromium_third__party_boringssl_src_crypto_cpu__arm__freebsd.c b/www/qt6-webengine/files/patch-src_3rdparty_chromium_third__party_boringssl_src_crypto_cpu__arm__freebsd.c
new file mode 100644
index 000000000000..adc47e13ece5
--- /dev/null
+++ b/www/qt6-webengine/files/patch-src_3rdparty_chromium_third__party_boringssl_src_crypto_cpu__arm__freebsd.c
@@ -0,0 +1,55 @@
+--- src/3rdparty/chromium/third_party/boringssl/src/crypto/cpu_arm_freebsd.c.orig	2023-06-03 08:17:28 UTC
++++ src/3rdparty/chromium/third_party/boringssl/src/crypto/cpu_arm_freebsd.c
+@@ -0,0 +1,52 @@
++/* Copyright (c) 2016, Google Inc.
++ *
++ * Permission to use, copy, modify, and/or distribute this software for any
++ * purpose with or without fee is hereby granted, provided that the above
++ * copyright notice and this permission notice appear in all copies.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
++ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
++ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
++ * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
++ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
++ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
++ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
++
++#include "internal.h"
++
++#if defined(OPENSSL_ARM) && defined(OPENSSL_FREEBSD) && \
++    !defined(OPENSSL_STATIC_ARMCAP)
++#include <sys/types.h>
++#include <sys/auxv.h>
++
++#include <openssl/arm_arch.h>
++#include <openssl/mem.h>
++
++extern uint32_t OPENSSL_armcap_P;
++
++void OPENSSL_cpuid_setup(void) {
++  unsigned long hwcap = 0, hwcap2 = 0;
++
++  elf_aux_info(AT_HWCAP, &hwcap, sizeof hwcap);
++  elf_aux_info(AT_HWCAP2, &hwcap2, sizeof hwcap2);
++
++  // Matching OpenSSL, only report other features if NEON is present.
++  if (hwcap & HWCAP_NEON) {
++    OPENSSL_armcap_P |= ARMV7_NEON;
++
++    if (hwcap2 & HWCAP2_AES) {
++      OPENSSL_armcap_P |= ARMV8_AES;
++    }
++    if (hwcap2 & HWCAP2_PMULL) {
++      OPENSSL_armcap_P |= ARMV8_PMULL;
++    }
++    if (hwcap2 & HWCAP2_SHA1) {
++      OPENSSL_armcap_P |= ARMV8_SHA1;
++    }
++    if (hwcap2 & HWCAP2_SHA2) {
++      OPENSSL_armcap_P |= ARMV8_SHA256;
++    }
++  }
++}
++
++#endif  // OPENSSL_ARM && OPENSSL_OPENBSD && !OPENSSL_STATIC_ARMCAP
diff --git a/www/qt6-webengine/files/patch-src_3rdparty_chromium_third__party_skia_src_core_SkCpu.cpp b/www/qt6-webengine/files/patch-src_3rdparty_chromium_third__party_skia_src_core_SkCpu.cpp
index 9eec9fed6607..d7a0a931b2aa 100644
--- a/www/qt6-webengine/files/patch-src_3rdparty_chromium_third__party_skia_src_core_SkCpu.cpp
+++ b/www/qt6-webengine/files/patch-src_3rdparty_chromium_third__party_skia_src_core_SkCpu.cpp
@@ -1,4 +1,4 @@
---- src/3rdparty/chromium/third_party/skia/src/core/SkCpu.cpp.orig	2022-09-26 10:05:50 UTC
+--- src/3rdparty/chromium/third_party/skia/src/core/SkCpu.cpp.orig	2022-06-10 05:40:07 UTC
 +++ src/3rdparty/chromium/third_party/skia/src/core/SkCpu.cpp
 @@ -73,6 +73,42 @@
          return features;
@@ -43,3 +43,26 @@
  #elif defined(SK_CPU_ARM64) && __has_include(<sys/auxv.h>)
      #include <sys/auxv.h>
  
+@@ -115,6 +151,22 @@
+         return features;
+     }
+ 
++#elif defined(SK_CPU_ARM32) && defined(__FreeBSD__)
++    #include <sys/auxv.h>
++
++    static uint32_t read_cpu_features() {
++        unsigned long hwcaps = 0;
++        uint32_t features = 0;
++
++        elf_aux_info(AT_HWCAP, (void *)&hwcaps, sizeof hwcaps);
++        if (hwcaps & HWCAP_NEON) {
++            features |= SkCpu::NEON;
++            if (hwcaps & HWCAP_VFPv4) {
++                features |= SkCpu::NEON_FMA|SkCpu::VFP_FP16;
++            }
++        }
++        return features;
++    }
+ #elif defined(SK_CPU_ARM32) && __has_include(<sys/auxv.h>) && \
+     (!defined(__ANDROID_API__) || __ANDROID_API__ >= 18)
+     // sys/auxv.h will always be present in the Android NDK due to unified
diff --git a/www/qt6-webengine/files/patch-src_3rdparty_chromium_v8_src_base_platform_platform-freebsd.cc b/www/qt6-webengine/files/patch-src_3rdparty_chromium_v8_src_base_platform_platform-freebsd.cc
index 63441114dca2..eb34b5eb35c5 100644
--- a/www/qt6-webengine/files/patch-src_3rdparty_chromium_v8_src_base_platform_platform-freebsd.cc
+++ b/www/qt6-webengine/files/patch-src_3rdparty_chromium_v8_src_base_platform_platform-freebsd.cc
@@ -20,7 +20,7 @@
              lib_name = std::string(path);
            }
            result.push_back(SharedLibraryAddress(
-+#if defined(__i386__) || defined(OS_FREEBSD)
++#if defined(__i386__) || defined(__arm__) || defined(OS_FREEBSD)
 +              lib_name, static_cast<uintptr_t>(map->kve_start),
 +              static_cast<uintptr_t>(map->kve_end)));
 +#else