git: 18b528bd087d - main - devel/electron17: fix build on armv7

From: Hiroki Tagato <tagattie_at_FreeBSD.org>
Date: Mon, 01 Aug 2022 09:00:31 UTC
The branch main has been updated by tagattie:

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

commit 18b528bd087d9158212e0854bb14403d005dd4a2
Author:     Robert Clausecker <fuz@fuz.su>
AuthorDate: 2022-08-01 08:58:46 +0000
Commit:     Hiroki Tagato <tagattie@FreeBSD.org>
CommitDate: 2022-08-01 09:00:12 +0000

    devel/electron17: fix build on armv7
    
    - add some missing bits of armv7 FreeBSD support code
      for the bundled boringssl
    - import V8 patch from bug #260651
    
    PR:             265438
    Reported by:    Robert Clausecker <fuz@fuz.su>
---
 ...atch-third__party_boringssl_BUILD.generated.gni | 10 +++-
 ...d__party_boringssl_src_crypto_cpu-arm-freebsd.c | 55 ++++++++++++++++++++++
 .../patch-third__party_skia_src_core_SkCpu.cpp     | 23 +++++++++
 .../patch-v8_src_base_platform_platform-freebsd.cc |  2 +-
 .../files/patch-v8_src_codegen_arm_cpu-arm.cc      | 18 +++++++
 5 files changed, 106 insertions(+), 2 deletions(-)

diff --git a/devel/electron17/files/patch-third__party_boringssl_BUILD.generated.gni b/devel/electron17/files/patch-third__party_boringssl_BUILD.generated.gni
index fa27e0bb40ff..19b8b96f4f61 100644
--- a/devel/electron17/files/patch-third__party_boringssl_BUILD.generated.gni
+++ b/devel/electron17/files/patch-third__party_boringssl_BUILD.generated.gni
@@ -1,6 +1,14 @@
 --- third_party/boringssl/BUILD.generated.gni.orig	2022-05-11 07:17:05 UTC
 +++ third_party/boringssl/BUILD.generated.gni
-@@ -183,6 +183,7 @@ crypto_sources = [
+@@ -81,6 +81,7 @@ crypto_sources = [
+   "src/crypto/cpu-aarch64-fuchsia.c",
+   "src/crypto/cpu-aarch64-linux.c",
+   "src/crypto/cpu-aarch64-win.c",
++  "src/crypto/cpu-arm-freebsd.c",
+   "src/crypto/cpu-arm-linux.c",
+   "src/crypto/cpu-arm-linux.h",
+   "src/crypto/cpu-arm.c",
+@@ -183,6 +184,7 @@ crypto_sources = [
    "src/crypto/rand_extra/deterministic.c",
    "src/crypto/rand_extra/forkunsafe.c",
    "src/crypto/rand_extra/fuchsia.c",
diff --git a/devel/electron17/files/patch-third__party_boringssl_src_crypto_cpu-arm-freebsd.c b/devel/electron17/files/patch-third__party_boringssl_src_crypto_cpu-arm-freebsd.c
new file mode 100644
index 000000000000..c2599cf6f5e9
--- /dev/null
+++ b/devel/electron17/files/patch-third__party_boringssl_src_crypto_cpu-arm-freebsd.c
@@ -0,0 +1,55 @@
+--- third_party/boringssl/src/crypto/cpu-arm-freebsd.c.orig	2022-07-31 03:32:48 UTC
++++ 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/devel/electron17/files/patch-third__party_skia_src_core_SkCpu.cpp b/devel/electron17/files/patch-third__party_skia_src_core_SkCpu.cpp
index cff64790931c..b509ae41afeb 100644
--- a/devel/electron17/files/patch-third__party_skia_src_core_SkCpu.cpp
+++ b/devel/electron17/files/patch-third__party_skia_src_core_SkCpu.cpp
@@ -24,3 +24,26 @@
  #elif defined(SK_CPU_ARM64) && __has_include(<sys/auxv.h>)
      #include <sys/auxv.h>
  
+@@ -115,6 +132,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/devel/electron17/files/patch-v8_src_base_platform_platform-freebsd.cc b/devel/electron17/files/patch-v8_src_base_platform_platform-freebsd.cc
index 43a6fe33253a..8785e355c9d8 100644
--- a/devel/electron17/files/patch-v8_src_base_platform_platform-freebsd.cc
+++ b/devel/electron17/files/patch-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
diff --git a/devel/electron17/files/patch-v8_src_codegen_arm_cpu-arm.cc b/devel/electron17/files/patch-v8_src_codegen_arm_cpu-arm.cc
new file mode 100644
index 000000000000..b80cc065e78c
--- /dev/null
+++ b/devel/electron17/files/patch-v8_src_codegen_arm_cpu-arm.cc
@@ -0,0 +1,18 @@
+--- v8/src/codegen/arm/cpu-arm.cc.orig	2022-07-25 18:25:18 UTC
++++ v8/src/codegen/arm/cpu-arm.cc
+@@ -2,12 +2,15 @@
+ // Use of this source code is governed by a BSD-style license that can be
+ // found in the LICENSE file.
+ 
++#include "include/v8config.h"
++
+ // CPU specific code for arm independent of OS goes here.
+ #ifdef __arm__
+ #ifdef __QNXNTO__
+ #include <sys/mman.h>  // for cache flushing.
+ #undef MAP_TYPE
+ #elif V8_OS_FREEBSD
++#include <sys/cdefs.h>
+ #include <machine/sysarch.h>  // for cache flushing
+ #include <sys/types.h>
+ #elif V8_OS_STARBOARD