From f9bd1e056781088e726853e4dd0dfa15d578bde4 Mon Sep 17 00:00:00 2001
From: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
Date: Tue, 27 Aug 2024 10:45:27 -0400
Subject: [PATCH] libressl: fix iOS build

OSByteOrder.h on macOS does not include the
required macro definitions. Applied the fix suggested
in https://github.com/libressl/portable/issues/1025.

Change-Id: I033fb5f405aed6fb8bcf859ea13bc8d3cb4959f1
---
 .../libressl/ios-add-byte-order-macros.patch  | 25 +++++++++++++++++++
 contrib/src/libressl/rules.mak                |  7 ++++++
 2 files changed, 32 insertions(+)
 create mode 100644 contrib/src/libressl/ios-add-byte-order-macros.patch

diff --git a/contrib/src/libressl/ios-add-byte-order-macros.patch b/contrib/src/libressl/ios-add-byte-order-macros.patch
new file mode 100644
index 0000000000..cecfee7351
--- /dev/null
+++ b/contrib/src/libressl/ios-add-byte-order-macros.patch
@@ -0,0 +1,25 @@
+diff --git a/.DS_Store b/.DS_Store
+index d154117..67f406e 100644
+Binary files a/.DS_Store and b/.DS_Store differ
+diff --git a/include/compat/endian.h b/include/compat/endian.h
+index 5376c1a..2a318af 100644
+--- a/include/compat/endian.h
++++ b/include/compat/endian.h
+@@ -62,7 +62,7 @@
+ #endif
+ #endif
+ 
+-#if defined(__APPLE__) && !defined(HAVE_ENDIAN_H)
++#if defined(__APPLE__) && !defined(be16toh)
+ #include <libkern/OSByteOrder.h>
+ #define be16toh(x) OSSwapBigToHostInt16((x))
+ #define htobe16(x) OSSwapHostToBigInt16((x))
+@@ -74,7 +74,7 @@
+ #define htobe64(x) OSSwapHostToBigInt64(x)
+ #define le64toh(x) OSSwapLittleToHostInt64(x)
+ #define be64toh(x) OSSwapBigToHostInt64(x)
+-#endif /* __APPLE__ && !HAVE_ENDIAN_H */
++#endif /* __APPLE__ && !be16toh */
+ 
+ #if defined(_WIN32) && !defined(HAVE_ENDIAN_H)
+ #include <winsock2.h>
diff --git a/contrib/src/libressl/rules.mak b/contrib/src/libressl/rules.mak
index 59d9b985d2..31762433c0 100644
--- a/contrib/src/libressl/rules.mak
+++ b/contrib/src/libressl/rules.mak
@@ -33,6 +33,9 @@ $(TARBALLS)/$(LIBRESSL_VERSION).tar.gz:
 
 libressl: $(LIBRESSL_VERSION).tar.gz
 	$(UNPACK)
+ifdef HAVE_IOS
+	$(APPLY) $(SRC)/libressl/ios-add-byte-order-macros.patch
+endif
 	$(MOVE)
 
 LIBRESSL_CONF := \
@@ -50,6 +53,10 @@ ifeq ($(HOST_ARCH),arm-linux-gnueabihf)
 LIBRESSL_CONF += -DCMAKE_SYSTEM_PROCESSOR=arm -DENABLE_ASM=Off -DCMAKE_C_FLAGS='-march=armv7-a -mfpu=neon-vfpv4 -mfloat-abi=hard'
 endif
 
+ifdef HAVE_IOS
+LIBRESSL_CONF += -DCMAKE_SYSTEM_PROCESSOR=aarch64 -DENABLE_ASM=Off
+endif
+
 .libressl: libressl .sum-libressl
 	mkdir -p "$(PREFIX)/include"
 ifdef HAVE_WIN32
-- 
GitLab