git: 2313549e74be - main - devel/corrade: fix build on aarch64, missing FreeBSD code

From: Robert Clausecker <fuz_at_FreeBSD.org>
Date: Thu, 25 May 2023 09:44:03 UTC
The branch main has been updated by fuz:

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

commit 2313549e74bebb854ba9f5088fc9d883ea6a6545
Author:     Robert Clausecker <fuz@FreeBSD.org>
AuthorDate: 2023-05-22 12:33:20 +0000
Commit:     Robert Clausecker <fuz@FreeBSD.org>
CommitDate: 2023-05-25 09:39:32 +0000

    devel/corrade: fix build on aarch64, missing FreeBSD code
    
     - add CPU detection code for armv7, aarch64
       (armv7 is still broken for other reasons)
     - add missing FreeBSD support code for executableLocation()
     - hook up test suite
    
    See also:       https://github.com/mosra/corrade/issues/171
    Approved by:    yuri (maintainer)
    Differential Revision: https://reviews.freebsd.org/D40202
---
 devel/corrade/Makefile                             |  5 ++-
 devel/corrade/files/patch-src_Corrade_Cpu.cpp      | 34 +++++++++++++++++++
 devel/corrade/files/patch-src_Corrade_Cpu.h        | 38 ++++++++++++++++++++++
 .../files/patch-src_Corrade_Utility_Path.cpp       | 33 +++++++++++++++++++
 4 files changed, 109 insertions(+), 1 deletion(-)

diff --git a/devel/corrade/Makefile b/devel/corrade/Makefile
index cd0cba4b7151..815f347cd220 100644
--- a/devel/corrade/Makefile
+++ b/devel/corrade/Makefile
@@ -11,7 +11,7 @@ WWW=		https://magnum.graphics/corrade/
 LICENSE=	MIT
 LICENSE_FILE=	${WRKSRC}/COPYING
 
-USES=		cmake compiler:c++14-lang
+USES=		cmake:testing compiler:c++14-lang
 USE_LDCONFIG=	yes
 
 USE_GITHUB=	yes
@@ -20,4 +20,7 @@ GH_TUPLE=	mosra:toolchains:65568a9:toolchains/toolchains
 
 CMAKE_ARGS=	-DLIB_SUFFIX:STRING=""
 
+OPTIONS_DEFINE=	TEST
+TEST_CMAKE_BOOL=	CORRADE_BUILD_TESTS
+
 .include <bsd.port.mk>
diff --git a/devel/corrade/files/patch-src_Corrade_Cpu.cpp b/devel/corrade/files/patch-src_Corrade_Cpu.cpp
new file mode 100644
index 000000000000..aab22a1bb3fd
--- /dev/null
+++ b/devel/corrade/files/patch-src_Corrade_Cpu.cpp
@@ -0,0 +1,34 @@
+--- src/Corrade/Cpu.cpp.orig	2023-05-22 11:59:16 UTC
++++ src/Corrade/Cpu.cpp
+@@ -34,7 +34,7 @@
+ /** @todo these are indented to work around acme.py extracting them to the top,
+     fix properly */
+ /* getauxval() for ARM on Linux and Android with API level 18+ */
+-#if defined(CORRADE_TARGET_ARM) && defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18)
++#if defined(CORRADE_TARGET_ARM) && (defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18) || defined(__FreeBSD__))
+     #include <sys/auxv.h>
+ /* sysctlbyname() for ARM on macOS / iOS */
+ #elif defined(CORRADE_TARGET_ARM) && defined(CORRADE_TARGET_APPLE)
+@@ -80,7 +80,7 @@ int appleSysctlByName(const char* name) {
+ }
+ #endif
+ 
+-#if defined(CORRADE_TARGET_ARM) && ((defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18)) || defined(CORRADE_TARGET_APPLE))
++#if defined(CORRADE_TARGET_ARM) && ((defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18)) || defined(CORRADE_TARGET_APPLE) || defined(__FreeBSD__))
+ Features runtimeFeatures() {
+     /* Use getauxval() on ARM on Linux and Android */
+     #if defined(CORRADE_TARGET_ARM) && defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18)
+@@ -130,6 +130,13 @@ Features runtimeFeatures() {
+     /* No other (deinlined) implementation at the moment. The function should
+        not be even defined here in that case -- it's inlined in the header
+        instead, including the x86 implementation. */
++    #elif defined(CORRADE_TARGET_ARM) && defined(__FreeBSD__)
++    /* use elf_aux_info() on ARM on FreeBSD */
++    unsigned long hwcap = 0;
++
++    elf_aux_info(AT_HWCAP, &hwcap, sizeof hwcap);
++
++    return Implementation::runtimeFeatures(hwcap);
+     #else
+     #error
+     #endif
diff --git a/devel/corrade/files/patch-src_Corrade_Cpu.h b/devel/corrade/files/patch-src_Corrade_Cpu.h
new file mode 100644
index 000000000000..7cb1c95f83db
--- /dev/null
+++ b/devel/corrade/files/patch-src_Corrade_Cpu.h
@@ -0,0 +1,38 @@
+--- src/Corrade/Cpu.h.orig	2023-05-22 12:04:59 UTC
++++ src/Corrade/Cpu.h
+@@ -1357,7 +1357,7 @@ equivalent:
+ */
+ template<class T> constexpr T tag() { return T{Implementation::Init}; }
+ 
+-#if defined(CORRADE_TARGET_ARM) && defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18)
++#if defined(CORRADE_TARGET_ARM) && (defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18) || defined(__FreeBSD__))
+ namespace Implementation {
+     /* Needed for a friend declaration, implementation is at the very end of
+        the header */
+@@ -1496,7 +1496,7 @@ class Features {
+         #endif
+         Features runtimeFeatures();
+         #endif
+-        #if defined(CORRADE_TARGET_ARM) && defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18)
++        #if defined(CORRADE_TARGET_ARM) && (defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18) || defined(__FreeBSD__))
+         friend Features Implementation::runtimeFeatures(unsigned long);
+         #endif
+ 
+@@ -1775,7 +1775,7 @@ value is equal to @ref Scalar, which in turn is equiva
+ default-constructed) @ref Features.
+ @see @ref DefaultBase, @ref DefaultExtra, @ref Default
+ */
+-#if (defined(CORRADE_TARGET_X86) && (defined(CORRADE_TARGET_MSVC) || defined(CORRADE_TARGET_GCC))) || (defined(CORRADE_TARGET_ARM) && ((defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18)) || defined(CORRADE_TARGET_APPLE))) || defined(DOXYGEN_GENERATING_OUTPUT)
++#if (defined(CORRADE_TARGET_X86) && (defined(CORRADE_TARGET_MSVC) || defined(CORRADE_TARGET_GCC))) || (defined(CORRADE_TARGET_ARM) && ((defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18)) || defined(CORRADE_TARGET_APPLE) || defined(__FreeBSD__))) || defined(DOXYGEN_GENERATING_OUTPUT)
+ #ifdef CORRADE_TARGET_ARM
+ CORRADE_UTILITY_EXPORT /* Inlined on x86 at the very end of the header */
+ #endif
+@@ -3214,7 +3214,7 @@ inline Features runtimeFeatures() {
+ /** @todo If AT_HWCAP2 or other bits are needed, it's passed to ifunc resolvers
+     only since glibc 2.30 (and Android API 30+, which is the same as before):
+     https://github.com/bminor/glibc/commit/2b8a3c86e7606cf1b0a997dad8af2d45ae8989c3 */
+-#if defined(CORRADE_TARGET_ARM) && defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18)
++#if defined(CORRADE_TARGET_ARM) && (defined(__linux__) && !(defined(CORRADE_TARGET_ANDROID) && __ANDROID_API__ < 18) || defined(__FreeBSD__))
+ namespace Implementation {
+     inline Features runtimeFeatures(const unsigned long caps) {
+         unsigned int out = 0;
diff --git a/devel/corrade/files/patch-src_Corrade_Utility_Path.cpp b/devel/corrade/files/patch-src_Corrade_Utility_Path.cpp
new file mode 100644
index 000000000000..a60703fdb2b6
--- /dev/null
+++ b/devel/corrade/files/patch-src_Corrade_Utility_Path.cpp
@@ -0,0 +1,33 @@
+--- src/Corrade/Utility/Path.cpp.orig	2023-01-12 11:52:02 UTC
++++ src/Corrade/Utility/Path.cpp
+@@ -89,6 +89,11 @@
+ #include <io.h>
+ #endif
+ 
++#ifdef __FreeBSD__
++#include <sys/types.h>
++#include <sys/sysctl.h>
++#endif
++
+ #include "Corrade/configure.h"
+ #include "Corrade/Containers/Array.h"
+ #include "Corrade/Containers/GrowableArray.h"
+@@ -540,6 +545,18 @@ Containers::Optional<Containers::String> executableLoc
+     /* hardcoded for Emscripten */
+     #elif defined(CORRADE_TARGET_EMSCRIPTEN)
+     return Containers::String{"/app.js"_s};
++
++    #elif defined(__FreeBSD__)
++    Containers::Array<char> path;
++    size_t size;
++    const int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
++
++    sysctl(mib, 4, nullptr, &size, NULL, 0);
++    arrayResize(path, NoInit, size + 1);
++    sysctl(mib, 4, path, &size, NULL, 0);
++    path[size] = '\0';
++    const auto deleter = path.deleter();
++    return Containers::String{path.release(), size, deleter};
+ 
+     /* Not implemented */
+     #else