abseil / abseil-cpp

Abseil Common Libraries (C++)
https://abseil.io
Apache License 2.0
14.94k stars 2.62k forks source link

Add support for NetBSD #641

Open moubctez opened 4 years ago

moubctez commented 4 years ago

NetBSD supports mmap() and pthread_getschedparam():

--- absl/base/config.h.orig
+++ absl/base/config.h
@@ -365,6 +365,7 @@ static_assert(ABSL_INTERNAL_INLINE_NAMES
 #ifdef ABSL_HAVE_MMAP
 #error ABSL_HAVE_MMAP cannot be directly set
 #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) ||   \
+    defined(__NetBSD__) || \
     defined(__ros__) || defined(__native_client__) || defined(__asmjs__) || \
     defined(__wasm__) || defined(__Fuchsia__) || defined(__sun) || \
     defined(__ASYLO__)
@@ -378,6 +379,7 @@ static_assert(ABSL_INTERNAL_INLINE_NAMES
 #ifdef ABSL_HAVE_PTHREAD_GETSCHEDPARAM
 #error ABSL_HAVE_PTHREAD_GETSCHEDPARAM cannot be directly set
 #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
+    defined(__NetBSD__) || \
     defined(__ros__)
 #define ABSL_HAVE_PTHREAD_GETSCHEDPARAM 1
 #endif

Also _XOPEN_SOURCE must not be defined, so either apply the following, or exclude defining it only for NetBSD (by the way, Darwin/macOS does not need either).

--- absl/time/internal/cctz/src/time_zone_format.cc.orig
+++ absl/time/internal/cctz/src/time_zone_format.cc
@@ -18,11 +18,6 @@
 #endif
 #endif

-#if defined(HAS_STRPTIME) && HAS_STRPTIME
-#if !defined(_XOPEN_SOURCE)
-#define _XOPEN_SOURCE  // Definedness suffices for strptime.
-#endif
-#endif

 #include "absl/base/config.h"
 #include "absl/time/internal/cctz/include/cctz/time_zone.h"
zhangxy988 commented 4 years ago

Thank you for the suggestion. Since we don't actively try to support every platform, we take a passive approach to adopt any "harmless" patches. I think this patch seems fit in the category. However, please note that we don't have any test coverage for NetBSD and don't intend to add the coverage. That said, it would be ideal for you to test the patch on your platform to make sure it works and send us a PR. Otherwise, I can blindly apply the patch but won't have a way to verify its correctness. In addition, the second half of the change seems to be in cctz and Abseil regularly syncs with it, so you will need to open a PR in https://github.com/google/cctz.