Skip to content

Commit 98d6917

Browse files
committed
Add Cygwin support: 10 patches for full platform port
Cygwin (POSIX on Windows/PE-COFF) was blocked by missing __CYGWIN__ guards in platform-detection lists. Each omission caused a different failure mode: compile errors, silent data loss, ABI mismatches, or wrong runtime behavior. The patches fall into three categories: platform detection and feature guards, type width corrections where pthread_t is pointer-sized instead of int-sized, and two test accommodations for Cygwin-specific behavior. 5 patches derive from abseil/abseil-cpp PR abseil#2012 (Carlo Bramini). The remaining 5 address issues not covered by that PR. Build requirement: -DGTEST_HAS_PTHREAD=1 — GoogleTest's auto-detection omits Cygwin from its pthread platform list, causing a Mutex ABI mismatch between libgmock and test binaries.
1 parent 76bb243 commit 98d6917

File tree

10 files changed

+24
-11
lines changed

10 files changed

+24
-11
lines changed

absl/base/attributes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
(!defined(_WIN32) || \
144144
(defined(__clang__) && __clang_major__ >= 9 && \
145145
!defined(ABSL_BUILD_DLL) && !defined(ABSL_CONSUME_DLL))) && \
146-
!defined(__MINGW32__)
146+
!defined(__MINGW32__) && !defined(__CYGWIN__)
147147
#undef ABSL_ATTRIBUTE_WEAK
148148
#define ABSL_ATTRIBUTE_WEAK __attribute__((weak))
149149
#define ABSL_HAVE_ATTRIBUTE_WEAK 1

absl/base/config.h

100644100755
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
377377
defined(__asmjs__) || defined(__EMSCRIPTEN__) || defined(__Fuchsia__) || \
378378
defined(__sun) || defined(__myriad2__) || defined(__HAIKU__) || \
379379
defined(__OpenBSD__) || defined(__NetBSD__) || defined(__QNX__) || \
380-
defined(__VXWORKS__) || defined(__hexagon__) || defined(__XTENSA__)
380+
defined(__VXWORKS__) || defined(__hexagon__) || defined(__XTENSA__) || \
381+
defined(__CYGWIN__)
381382
#define ABSL_HAVE_MMAP 1
382383
#endif
383384

absl/base/internal/low_level_alloc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
// LowLevelAlloc.
3737
#ifdef ABSL_LOW_LEVEL_ALLOC_MISSING
3838
#error ABSL_LOW_LEVEL_ALLOC_MISSING cannot be directly set
39-
#elif !defined(ABSL_HAVE_MMAP) && !defined(_WIN32)
39+
#elif !defined(ABSL_HAVE_MMAP) && !defined(_WIN32) && !defined(__CYGWIN__)
4040
#define ABSL_LOW_LEVEL_ALLOC_MISSING 1
4141
#endif
4242

@@ -47,7 +47,7 @@
4747
#ifdef ABSL_LOW_LEVEL_ALLOC_ASYNC_SIGNAL_SAFE_MISSING
4848
#error ABSL_LOW_LEVEL_ALLOC_ASYNC_SIGNAL_SAFE_MISSING cannot be directly set
4949
#elif defined(_WIN32) || defined(__asmjs__) || defined(__wasm__) || \
50-
defined(__hexagon__)
50+
defined(__hexagon__) || defined(__CYGWIN__)
5151
#define ABSL_LOW_LEVEL_ALLOC_ASYNC_SIGNAL_SAFE_MISSING 1
5252
#endif
5353

absl/base/internal/raw_logging.cc

100644100755
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
4545
defined(__hexagon__) || defined(__Fuchsia__) || \
4646
defined(__native_client__) || defined(__OpenBSD__) || \
47-
defined(__EMSCRIPTEN__) || defined(__ASYLO__)
47+
defined(__EMSCRIPTEN__) || defined(__ASYLO__) || \
48+
defined(__CYGWIN__)
4849

4950
#include <unistd.h>
5051

absl/base/internal/sysinfo.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ pid_t GetTID() {
481481
pid_t GetTID() {
482482
// `pthread_t` need not be arithmetic per POSIX; platforms where it isn't
483483
// should be handled above.
484-
return static_cast<pid_t>(pthread_self());
484+
return reinterpret_cast<pid_t>(pthread_self());
485485
}
486486

487487
#endif

absl/base/internal/sysinfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ int NumCPUs();
5757
// return types of GetProcessId() and GetThreadId() are both DWORD, an unsigned
5858
// 32-bit type.
5959
using pid_t = uint32_t;
60+
#elif defined(__CYGWIN__)
61+
// On CYGWIN, this works on both i686 (deprecated) and x64 targets.
62+
using pid_t = uintptr_t;
6063
#endif
6164
pid_t GetTID();
6265

absl/base/policy_checks.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@
3838
// Operating System Check
3939
// -----------------------------------------------------------------------------
4040

41-
#if defined(__CYGWIN__)
42-
#error "Cygwin is not supported."
43-
#endif
44-
4541
// -----------------------------------------------------------------------------
4642
// Toolchain Check
4743
// -----------------------------------------------------------------------------

absl/log/internal/config.h

100644100755
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ namespace log_internal {
3434

3535
#ifdef _WIN32
3636
using Tid = uint32_t;
37+
#elif defined(__CYGWIN__)
38+
// Cygwin's GetTID() returns reinterpret_cast<uintptr_t>(pthread_self()),
39+
// which is an 8-byte pointer on x86_64. System pid_t is int (4 bytes)
40+
// and would truncate the thread ID, causing collisions in log output.
41+
using Tid = uint64_t;
3742
#else
3843
using Tid = pid_t;
3944
#endif

absl/log/stripping_test.cc

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class StrippingTest : public ::testing::Test {
170170
// Opens this program's executable file. Returns `nullptr` and writes to
171171
// `stderr` on failure.
172172
std::unique_ptr<FILE, std::function<void(FILE*)>> OpenTestExecutable() {
173-
#if defined(__linux__)
173+
#if defined(__linux__) || defined(__CYGWIN__)
174174
std::unique_ptr<FILE, std::function<void(FILE*)>> fp(
175175
fopen("/proc/self/exe", "rb"), [](FILE* fp) { fclose(fp); });
176176
if (!fp) {

absl/strings/charconv_test.cc

100644100755
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@
3131
#ifdef _MSC_FULL_VER
3232
#define ABSL_COMPILER_DOES_EXACT_ROUNDING 0
3333
#define ABSL_STRTOD_HANDLES_NAN_CORRECTLY 0
34+
#elif defined(__CYGWIN__)
35+
#define ABSL_COMPILER_DOES_EXACT_ROUNDING 1
36+
// Cygwin's strtod() handles NaN payloads differently for large or
37+
// non-numeric n-char-sequences (e.g., "abc123", very long digit strings).
38+
// The NaN payload encoding is unspecified per IEEE 754, so this is a
39+
// platform difference, not a bug.
40+
#define ABSL_STRTOD_HANDLES_NAN_CORRECTLY 0
3441
#else
3542
#define ABSL_COMPILER_DOES_EXACT_ROUNDING 1
3643
#define ABSL_STRTOD_HANDLES_NAN_CORRECTLY 1

0 commit comments

Comments
 (0)