git: 386f6c8ea584 - main - www/deno: Fix build on aarch64

From: Mikael Urankar <mikael_at_FreeBSD.org>
Date: Sun, 20 Nov 2022 12:14:59 UTC
The branch main has been updated by mikael:

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

commit 386f6c8ea584fb79d747b07bed7480da5c78b178
Author:     Mikael Urankar <mikael@FreeBSD.org>
AuthorDate: 2022-11-20 10:48:13 +0000
Commit:     Mikael Urankar <mikael@FreeBSD.org>
CommitDate: 2022-11-20 12:14:54 +0000

    www/deno: Fix build on aarch64
---
 www/deno/Makefile                                  |  1 +
 ...atch-cargo-crates_v8_third__party_zlib_BUILD.gn | 11 +++++
 ...rgo-crates_v8_third__party_zlib_cpu__features.c | 48 ++++++++++++++++++++++
 3 files changed, 60 insertions(+)

diff --git a/www/deno/Makefile b/www/deno/Makefile
index e5360310cce1..b824f02a35a2 100644
--- a/www/deno/Makefile
+++ b/www/deno/Makefile
@@ -578,6 +578,7 @@ BINARY_ALIAS+=		ar=/usr/bin/llvm-ar \
 post-patch:
 	${REINPLACE_CMD} "s|%%LOCALBASE%%|${LOCALBASE}|" \
 		${WRKSRC}/cargo-crates/v8-${V8_VERS}/buildtools/third_party/libc++/BUILD.gn
+	${MKDIR} ${WRKSRC}/cargo-crates/v8-${V8_VERS}/v8/tools/builtins-pgo/arm64.profile
 	${MKDIR} ${WRKSRC}/cargo-crates/v8-${V8_VERS}/v8/tools/builtins-pgo/x64.profile
 
 do-install:
diff --git a/www/deno/files/patch-cargo-crates_v8_third__party_zlib_BUILD.gn b/www/deno/files/patch-cargo-crates_v8_third__party_zlib_BUILD.gn
new file mode 100644
index 000000000000..1bdb45200080
--- /dev/null
+++ b/www/deno/files/patch-cargo-crates_v8_third__party_zlib_BUILD.gn
@@ -0,0 +1,11 @@
+--- cargo-crates/v8-0.55.0/third_party/zlib/BUILD.gn.orig	2022-11-20 11:42:33 UTC
++++ cargo-crates/v8-0.55.0/third_party/zlib/BUILD.gn
+@@ -119,6 +119,8 @@ if (use_arm_neon_optimizations) {
+       defines = [ "CRC32_ARMV8_CRC32" ]
+       if (is_android) {
+         defines += [ "ARMV8_OS_ANDROID" ]
++      } else if (is_bsd) {
++        defines += [ "ARMV8_OS_FREEBSD" ]
+       } else if (is_linux || is_chromeos) {
+         defines += [ "ARMV8_OS_LINUX" ]
+       } else if (is_mac) {
diff --git a/www/deno/files/patch-cargo-crates_v8_third__party_zlib_cpu__features.c b/www/deno/files/patch-cargo-crates_v8_third__party_zlib_cpu__features.c
new file mode 100644
index 000000000000..fc3a6b915b5b
--- /dev/null
+++ b/www/deno/files/patch-cargo-crates_v8_third__party_zlib_cpu__features.c
@@ -0,0 +1,48 @@
+--- cargo-crates/v8-0.55.0/third_party/zlib/cpu_features.c.orig	2022-11-20 11:40:38 UTC
++++ cargo-crates/v8-0.55.0/third_party/zlib/cpu_features.c
+@@ -31,11 +31,20 @@ int ZLIB_INTERNAL x86_cpu_enable_simd = 0;
+ 
+ #ifndef CPU_NO_SIMD
+ 
+-#if defined(ARMV8_OS_ANDROID) || defined(ARMV8_OS_LINUX) || defined(ARMV8_OS_FUCHSIA)
++#if defined(ARMV8_OS_ANDROID) || defined(ARMV8_OS_LINUX) || defined(ARMV8_OS_FUCHSIA) || defined(ARMV8_OS_FREEBSD)
+ #include <pthread.h>
+ #endif
+ 
+-#if defined(ARMV8_OS_ANDROID)
++#if defined(ARMV8_OS_FREEBSD)
++#include <machine/armreg.h>
++#include <sys/types.h>
++#ifndef ID_AA64ISAR0_AES_VAL
++#define ID_AA64ISAR0_AES_VAL ID_AA64ISAR0_AES
++#endif
++#ifndef ID_AA64ISAR0_CRC32_VAL
++#define ID_AA64ISAR0_CRC32_VAL ID_AA64ISAR0_CRC32
++#endif
++#elif defined(ARMV8_OS_ANDROID)
+ #include <cpu-features.h>
+ #elif defined(ARMV8_OS_LINUX)
+ #include <asm/hwcap.h>
+@@ -56,7 +65,7 @@ static void _cpu_check_features(void);
+ static void _cpu_check_features(void);
+ #endif
+ 
+-#if defined(ARMV8_OS_ANDROID) || defined(ARMV8_OS_LINUX) || defined(ARMV8_OS_MACOS) || defined(ARMV8_OS_FUCHSIA) || defined(X86_NOT_WINDOWS)
++#if defined(ARMV8_OS_ANDROID) || defined(ARMV8_OS_LINUX) || defined(ARMV8_OS_MACOS) || defined(ARMV8_OS_FUCHSIA) || defined(X86_NOT_WINDOWS) || defined(ARMV8_OS_FREEBSD)
+ #if !defined(ARMV8_OS_MACOS)
+ // _cpu_check_features() doesn't need to do anything on mac/arm since all
+ // features are known at build time, so don't call it.
+@@ -123,6 +132,13 @@ static void _cpu_check_features(void)
+ #elif defined(ARMV8_OS_WINDOWS)
+     arm_cpu_enable_crc32 = IsProcessorFeaturePresent(PF_ARM_V8_CRC32_INSTRUCTIONS_AVAILABLE);
+     arm_cpu_enable_pmull = IsProcessorFeaturePresent(PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE);
++#elif defined(ARMV8_OS_FREEBSD)
++    uint64_t id_aa64isar0;
++    id_aa64isar0 = READ_SPECIALREG(id_aa64isar0_el1);
++    if (ID_AA64ISAR0_AES_VAL(id_aa64isar0) == ID_AA64ISAR0_AES_PMULL)
++        arm_cpu_enable_pmull = 1;
++    if (ID_AA64ISAR0_CRC32_VAL(id_aa64isar0) == ID_AA64ISAR0_CRC32_BASE)
++        arm_cpu_enable_crc32 = 1;
+ #endif
+ }
+ #endif