[HarfBuzz] Patches for building HarfBuzz with mingw.org's MinGW

Eli Zaretskii eliz at gnu.org
Sun Jun 2 16:35:37 UTC 2019


Hi,

I'd like to submit a few small patches that allow HarfBuzz to be built
on Windows with mingw.org's MinGW toolchain.  (And before you ask: the
reason you don't see the problems I describe below in your MinGW
builds is that you use MinGW64, which is a different flavor of MinGW.)

The patches are against HarfBuzz 2.5.1.

Here are the patches, with explanations:

1. This patch is needed because MinGW doesn't have _BitScanForward and
_BitScanReverse.  They are only used with old GCC versions, so
conditioning their calls by those old versions of GCC is good enough,
IMO.

--- src/hb-algs.hh~0	2019-06-01 08:49:47.000000000 +0300
+++ src/hb-algs.hh	2019-06-02 11:03:52.373677900 +0300
@@ -400,7 +400,7 @@
     return sizeof (unsigned long long) * 8 - __builtin_clzll (v);
 #endif
 
-#if (defined(_MSC_VER) && _MSC_VER >= 1500) || defined(__MINGW32__)
+#if (defined(_MSC_VER) && _MSC_VER >= 1500) || (defined(__MINGW32__) && (__GNUC__ < 4))
   if (sizeof (T) <= sizeof (unsigned int))
   {
     unsigned long where;
@@ -474,7 +474,7 @@
     return __builtin_ctzll (v);
 #endif
 
-#if (defined(_MSC_VER) && _MSC_VER >= 1500) || defined(__MINGW32__)
+#if (defined(_MSC_VER) && _MSC_VER >= 1500) || (defined(__MINGW32__) && (__GNUC__ < 4))
   if (sizeof (T) <= sizeof (unsigned int))
   {
     unsigned long where;


2. This patch is needed because mingw.org's MinGW defines
MemoryBarrier as an inline function, not as a macro.
__MINGW32_VERSION is defined only by mingw.org's MinGW, so the change
shouldn't affect MinGW64.

--- src/hb-atomic.hh~0	2019-05-27 20:07:58.000000000 +0300
+++ src/hb-atomic.hh	2019-06-02 10:55:49.013099500 +0300
@@ -107,7 +107,7 @@
 
 static inline void _hb_memory_barrier ()
 {
-#ifndef MemoryBarrier
+#if !defined(MemoryBarrier) && !defined(__MINGW32_VERSION)
   /* MinGW has a convoluted history of supporting MemoryBarrier. */
   LONG dummy = 0;
   InterlockedExchange (&dummy, 1);


3. This patch is needed because MinGW doesn't define
E_NOT_SUFFICIENT_BUFFER.

--- src/hb-uniscribe.cc~0	2019-05-14 03:28:16.000000000 +0300
+++ src/hb-uniscribe.cc	2019-06-02 11:04:43.843081900 +0300
@@ -31,6 +31,10 @@
 #include <usp10.h>
 #include <rpc.h>
 
+#ifndef E_NOT_SUFFICIENT_BUFFER
+#define E_NOT_SUFFICIENT_BUFFER HRESULT_FROM_WIN32 (ERROR_INSUFFICIENT_BUFFER)
+#endif
+
 #include "hb-uniscribe.h"
 
 #include "hb-open-file.hh"


4. This patch is needed because mingw.org's MinGW doesn't have the
intrin.h header file; instead, the intrinsics are declared by
including windows.h.

--- src/hb.hh~0	2019-05-14 09:42:00.000000000 +0300
+++ src/hb.hh	2019-06-02 11:06:01.413041500 +0300
@@ -183,8 +183,15 @@
 #include <stdarg.h>
 
 #if (defined(_MSC_VER) && _MSC_VER >= 1500) || defined(__MINGW32__)
+#ifdef __MINGW32_VERSION
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN 1
+#endif
+#include <windows.h>
+#else
 #include <intrin.h>
 #endif
+#endif
 
 #define HB_PASTE1(a,b) a##b
 #define HB_PASTE(a,b) HB_PASTE1(a,b)


Thank you for developing HarfBuzz.


More information about the HarfBuzz mailing list