Skip to content

Add support for CYGWIN#2012

Open
carlo-bramini wants to merge 1 commit intoabseil:masterfrom
carlo-bramini:add-cygwin-support
Open

Add support for CYGWIN#2012
carlo-bramini wants to merge 1 commit intoabseil:masterfrom
carlo-bramini:add-cygwin-support

Conversation

@carlo-bramini
Copy link
Copy Markdown

@carlo-bramini carlo-bramini commented Feb 11, 2026

This patch adds support for CYGWIN.
Hopefully, very few changes are needed.

absl/base/attributes.h
Talking about shared libraries, CYGWIN shares the same behaviour of the traditional WIN32 binaries with DLLs.
So, exactly like MinGW, the compiler doesn't complain about the weak attribute until it fails at the link step.
Here, the solution is to avoid the weak attribute, exactly like it has been already done for the existing MinGW support.

absl/base/internal/low_level_alloc.h
CYGWIN lacks support for low-level allocation of virtual memory, so here it follows again the same behaviour of WIN32.

absl/base/internal/sysinfo.cc
absl/base/internal/sysinfo.h
On CYGWIN, the function GetTID() cannot be compiled because pid_t and the return value of pthread_self() are not compatible.
pid_t is an int type, so it's 32 bit on CYGWIN.
pthread_self() returns a pthread_t which is an opaque object.
And, on CYGWIN, pthread_t is a typedef to a pointer.
When compiling for x86_64, the size of the pointer is 64bit.
So, there is a mismatch because 32bit != 64bit.
Hopefully, it is already possible to support a different pid_t into absl/base/internal/sysinfo.h, so I did the same thing that it has been done for _WIN32 and I added it to be an uintptr_t, which is good for all conditions.
However, into absl/base/internal/sysinfo.cc, the static_cast is not able to convert yet.
It can work if pthread_self() returns an int, but since pthread_t is an opaque object and it must be assumed to be like that, here the reinterpret_cast looks a better solution.

absl/base/policy_checks.h
Since CYGWIN is supported after these changes, the lines for blocking the execution of the build process are not needed anymore and they have been removed from the code.

===
The library compiled fine in all conditions.
Tested build with both shared and static libraries.
Tested build with ABSL_BUILD_MONOLITHIC_SHARED_LIBS to be ON and OFF.

Sadly, I have no chance to execute bazel or Docker inside CYGWIN for running the tests because they seem to be not supported.
However, the chance that everything is working fine looks very high because CYGWIN is using code that already existed.
A direct test has been done with direct use, when building gstreamer-1.0, since abseil-cpp is a dependency.
If you think that this may be enough or something more can be done, please let me know.

I hope that you will find this patch useful.
Sincerely.

Carlo Bramini.

===
Thank you for your contribution to Abseil!

Before submitting this PR, please be sure to read our contributing
guidelines
.

If you are a Googler, please also note that it is required that you send us a
Piper CL instead of using the GitHub pull-request process. The code propagation
process will deliver the change to GitHub.

phdye pushed a commit to phdye-cygwin/abseil-cpp that referenced this pull request Apr 7, 2026
Cygwin (POSIX on Windows/PE-COFF) was blocked by missing __CYGWIN__
guards in platform-detection lists throughout the codebase. Each
omission caused a different failure mode: compile errors, silent
data loss, ABI mismatches, or wrong runtime behavior.

Library patches (8):
- policy_checks.h: remove #error "Cygwin is not supported"
- attributes.h: disable ABSL_ATTRIBUTE_WEAK (PE/COFF has no ELF
  weak symbols; they cause virtual dispatch table collapse)
- config.h: add ABSL_HAVE_MMAP (Cygwin has working mmap)
- low_level_alloc.h: Cygwin can allocate via mmap but lacks
  async-signal-safe allocation (same as Windows)
- sysinfo.cc: reinterpret_cast for GetTID (pthread_t is a pointer
  on Cygwin; static_cast to int fails at compile time)
- sysinfo.h: pid_t = uintptr_t on Cygwin (prevents truncation of
  8-byte pthread_t to 4-byte int)
- log/internal/config.h: Tid = uint64_t on Cygwin (log entries were
  truncating thread IDs from 8 bytes to 4, causing collisions)
- raw_logging.cc: add __CYGWIN__ to ABSL_HAVE_POSIX_WRITE list
  (raw log output was silently discarded via no-op fallback)

Test patches (2):
- charconv_test.cc: disable strtod NaN payload comparison on Cygwin
  (unspecified IEEE 754 behavior differs from glibc)
- stripping_test.cc: add __CYGWIN__ to /proc/self/exe guard
  (Cygwin provides /proc/self/exe like Linux)

Build requirement: -DGTEST_HAS_PTHREAD=1 in CMAKE_CXX_FLAGS.
googletest's auto-detection omits GTEST_OS_CYGWIN from its pthread
platform list, causing a Mutex ABI mismatch between libgmock.a
(real pthread_mutex_t) and test binaries (no-op Mutex).

5 of the original 8 library patches are from abseil/abseil-cpp
PR abseil#2012 (Carlo Bramini). The remaining 3 library patches and
both test patches are new.

Test results: 218/218 pass (ctest --timeout 300).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant