Skip to content

Commit

Permalink
**WIP**: Initial Cygwin build
Browse files Browse the repository at this point in the history
* Cygwin is a platform that shares some similarities with MinGW and Linux.

* Tested to pass the build with CMake.
* Compiles all the test cases. However, most tests are failing for now..

Signed-off-by: Ookiineko <[email protected]>
  • Loading branch information
Ookiineko committed Mar 16, 2024
1 parent 56d3f22 commit 78b76a0
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 11 deletions.
1 change: 1 addition & 0 deletions CMake/AbseilHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ function(absl_cc_test)
endif()
target_compile_options(${_NAME}
PRIVATE ${ABSL_CC_TEST_COPTS}
$<$<BOOL:${CYGWIN}>:-Wa,-mbig-obj>
)

target_link_libraries(${_NAME}
Expand Down
2 changes: 1 addition & 1 deletion absl/base/attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
#if (ABSL_HAVE_ATTRIBUTE(weak) || \
(defined(__GNUC__) && !defined(__clang__))) && \
(!defined(_WIN32) || (defined(__clang__) && __clang_major__ >= 9)) && \
!defined(__MINGW32__)
!defined(__MINGW32__) && !defined(__CYGWIN__)
#undef ABSL_ATTRIBUTE_WEAK
#define ABSL_ATTRIBUTE_WEAK __attribute__((weak))
#define ABSL_HAVE_ATTRIBUTE_WEAK 1
Expand Down
11 changes: 6 additions & 5 deletions absl/base/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,8 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
defined(__asmjs__) || defined(__EMSCRIPTEN__) || defined(__Fuchsia__) || \
defined(__sun) || defined(__ASYLO__) || defined(__myriad2__) || \
defined(__HAIKU__) || defined(__OpenBSD__) || defined(__NetBSD__) || \
defined(__QNX__) || defined(__VXWORKS__) || defined(__hexagon__)
defined(__QNX__) || defined(__VXWORKS__) || defined(__hexagon__) || \
defined(__CYGWIN__)
#define ABSL_HAVE_MMAP 1
#endif

Expand All @@ -428,7 +429,7 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
#error ABSL_HAVE_PTHREAD_GETSCHEDPARAM cannot be directly set
#elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
defined(_AIX) || defined(__ros__) || defined(__OpenBSD__) || \
defined(__NetBSD__) || defined(__VXWORKS__)
defined(__NetBSD__) || defined(__VXWORKS__) || defined(__CYGWIN__)
#define ABSL_HAVE_PTHREAD_GETSCHEDPARAM 1
#endif

Expand All @@ -437,7 +438,7 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
// Checks whether sched_getcpu is available.
#ifdef ABSL_HAVE_SCHED_GETCPU
#error ABSL_HAVE_SCHED_GETCPU cannot be directly set
#elif defined(__linux__)
#elif defined(__linux__) || defined(__CYGWIN__)
#define ABSL_HAVE_SCHED_GETCPU 1
#endif

Expand All @@ -448,7 +449,7 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
#ifdef ABSL_HAVE_SCHED_YIELD
#error ABSL_HAVE_SCHED_YIELD cannot be directly set
#elif defined(__linux__) || defined(__ros__) || defined(__native_client__) || \
defined(__VXWORKS__)
defined(__VXWORKS__) || defined(__CYGWIN__)
#define ABSL_HAVE_SCHED_YIELD 1
#endif

Expand All @@ -463,7 +464,7 @@ static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
// platforms.
#ifdef ABSL_HAVE_SEMAPHORE_H
#error ABSL_HAVE_SEMAPHORE_H cannot be directly set
#elif defined(__linux__) || defined(__ros__) || defined(__VXWORKS__)
#elif defined(__linux__) || defined(__ros__) || defined(__VXWORKS__) || defined(__CYGWIN__)
#define ABSL_HAVE_SEMAPHORE_H 1
#endif

Expand Down
2 changes: 1 addition & 1 deletion absl/base/internal/raw_logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
defined(__hexagon__) || defined(__Fuchsia__) || \
defined(__native_client__) || defined(__OpenBSD__) || \
defined(__EMSCRIPTEN__) || defined(__ASYLO__)
defined(__EMSCRIPTEN__) || defined(__ASYLO__) || defined(__CYGWIN__)

#include <unistd.h>

Expand Down
4 changes: 4 additions & 0 deletions absl/base/internal/sysinfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,10 @@ pid_t GetTID() {
return reinterpret_cast<pid_t>(thread);
}

#elif defined(__CYGWIN__)

pid_t GetTID() { return reinterpret_cast<pid_t>(pthread_self()); }

#else

// Fallback implementation of `GetTID` using `pthread_self`.
Expand Down
4 changes: 4 additions & 0 deletions absl/base/internal/sysinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ int NumCPUs();
// return types of GetProcessId() and GetThreadId() are both DWORD, an unsigned
// 32-bit type.
using pid_t = uint32_t;
#elif defined(__CYGWIN__)
// HACK: Shadowing the builtin pid_t type from the standard library.
// pthread_t on Cygwin is a pointer type, but pid_t is an int.
using pid_t = intptr_t;
#endif
pid_t GetTID();

Expand Down
3 changes: 0 additions & 3 deletions absl/base/policy_checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
// Operating System Check
// -----------------------------------------------------------------------------

#if defined(__CYGWIN__)
#error "Cygwin is not supported."
#endif

// -----------------------------------------------------------------------------
// Toolchain Check
Expand Down
5 changes: 5 additions & 0 deletions absl/debugging/failure_signal_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
// limitations under the License.
//

#ifdef __CYGWIN__
// for sched_getcpu()
#define _GNU_SOURCE
#endif

#include "absl/debugging/failure_signal_handler.h"

#include "absl/base/config.h"
Expand Down
2 changes: 1 addition & 1 deletion absl/log/stripping_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class StrippingTest : public ::testing::Test {
// Opens this program's executable file. Returns `nullptr` and writes to
// `stderr` on failure.
std::unique_ptr<FILE, std::function<void(FILE*)>> OpenTestExecutable() {
#if defined(__linux__)
#if defined(__linux__) || defined(__CYGWIN__)
std::unique_ptr<FILE, std::function<void(FILE*)>> fp(
fopen("/proc/self/exe", "rb"), [](FILE* fp) { fclose(fp); });
if (!fp) {
Expand Down

0 comments on commit 78b76a0

Please sign in to comment.