From ed291840d3a841bb5b49457c88c57e8467e4a5b0 Mon Sep 17 00:00:00 2001 From: "Joshua M. Clulow" Date: Thu, 29 Apr 2021 06:40:08 -0700 Subject: [PATCH] add illumos support (#1501) --- CMake/TdSetUpCompiler.cmake | 12 +++++++++++- CMake/illumos.cmake | 11 +++++++++++ CMakeLists.txt | 2 ++ README.md | 2 +- td/generate/tl-parser/portable_endian.h | 2 +- tdutils/td/utils/port/config.h | 3 +++ tdutils/td/utils/port/platform.h | 1 + tdutils/td/utils/port/uname.cpp | 2 +- 8 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 CMake/illumos.cmake diff --git a/CMake/TdSetUpCompiler.cmake b/CMake/TdSetUpCompiler.cmake index 11a681c1f..73f74cbdb 100644 --- a/CMake/TdSetUpCompiler.cmake +++ b/CMake/TdSetUpCompiler.cmake @@ -5,6 +5,8 @@ function(td_set_up_compiler) set(CMAKE_POSITION_INDEPENDENT_CODE ON PARENT_SCOPE) + include(illumos) + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set(GCC 1) set(GCC 1 PARENT_SCOPE) @@ -58,7 +60,9 @@ function(td_set_up_compiler) else() set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections -Wl,--exclude-libs,ALL") + if (NOT ILLUMOS) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--gc-sections -Wl,--exclude-libs,ALL") + endif() endif() if (WIN32 OR CYGWIN) @@ -81,6 +85,12 @@ function(td_set_up_compiler) add_definitions(-D_FILE_OFFSET_BITS=64) endif() + if (ILLUMOS) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -lnsl -lsocket") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lnsl -lsocket") + add_definitions(-DTD_ILLUMOS=1) + endif() + include(AddCXXCompilerFlag) if (NOT MSVC) add_cxx_compiler_flag("-Wall") diff --git a/CMake/illumos.cmake b/CMake/illumos.cmake new file mode 100644 index 000000000..b0b561743 --- /dev/null +++ b/CMake/illumos.cmake @@ -0,0 +1,11 @@ +if (CMAKE_SYSTEM_NAME STREQUAL "SunOS") + # + # Determine if the host is running an illumos distribution: + # + execute_process(COMMAND /usr/bin/uname -o OUTPUT_VARIABLE UNAME_O + OUTPUT_STRIP_TRAILING_WHITESPACE) + + if (UNAME_O STREQUAL "illumos") + set(ILLUMOS 1) + endif() +endif() diff --git a/CMakeLists.txt b/CMakeLists.txt index 93f9a442f..70acbdc96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,8 @@ if (POLICY CMP0060) cmake_policy(SET CMP0060 NEW) endif() +include(illumos) + include(PreventInSourceBuild) prevent_in_source_build() diff --git a/README.md b/README.md index 061f3cca3..22ed6f6ae 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ TDLib (Telegram Database library) is a cross-platform library for building [Tele `TDLib` has many advantages. Notably `TDLib` is: -* **Cross-platform**: `TDLib` can be used on Android, iOS, Windows, macOS, Linux, FreeBSD, OpenBSD, NetBSD, Windows Phone, WebAssembly, watchOS, tvOS, Tizen, Cygwin. It should also work on other *nix systems with or without minimal effort. +* **Cross-platform**: `TDLib` can be used on Android, iOS, Windows, macOS, Linux, FreeBSD, OpenBSD, NetBSD, illumos, Windows Phone, WebAssembly, watchOS, tvOS, Tizen, Cygwin. It should also work on other *nix systems with or without minimal effort. * **Multilanguage**: `TDLib` can be easily used with any programming language that is able to execute C functions. Additionally it already has native Java (using `JNI`) bindings and .NET (using `C++/CLI` and `C++/CX`) bindings. * **Easy to use**: `TDLib` takes care of all network implementation details, encryption and local data storage. * **High-performance**: in the [Telegram Bot API](https://core.telegram.org/bots/api), each `TDLib` instance handles more than 24000 active bots simultaneously. diff --git a/td/generate/tl-parser/portable_endian.h b/td/generate/tl-parser/portable_endian.h index 9f6d2f41c..7338c3aef 100644 --- a/td/generate/tl-parser/portable_endian.h +++ b/td/generate/tl-parser/portable_endian.h @@ -17,7 +17,7 @@ #endif -#if defined(__linux__) || defined(__CYGWIN__) +#if defined(__linux__) || defined(__CYGWIN__) || defined(__sun) # include diff --git a/tdutils/td/utils/port/config.h b/tdutils/td/utils/port/config.h index 65d809ab4..b431f41ad 100644 --- a/tdutils/td/utils/port/config.h +++ b/tdutils/td/utils/port/config.h @@ -34,6 +34,9 @@ #elif TD_WINDOWS #define TD_POLL_WINEVENT 1 #define TD_EVENTFD_WINDOWS 1 +#elif TD_ILLUMOS + #define TD_POLL_EPOLL 1 + #define TD_EVENTFD_LINUX 1 #else #error "Poll's implementation is not defined" #endif diff --git a/tdutils/td/utils/port/platform.h b/tdutils/td/utils/port/platform.h index 7ca2341b2..1a596c3ed 100644 --- a/tdutils/td/utils/port/platform.h +++ b/tdutils/td/utils/port/platform.h @@ -53,6 +53,7 @@ #define TD_CYGWIN 1 #elif defined(__EMSCRIPTEN__) #define TD_EMSCRIPTEN 1 +#elif defined(TD_ILLUMOS) #elif defined(__unix__) // all unices not caught above #warning "Probably unsupported Unix platform. Feel free to try to compile" #define TD_CYGWIN 1 diff --git a/tdutils/td/utils/port/uname.cpp b/tdutils/td/utils/port/uname.cpp index d2e5b741f..628cc5bd2 100644 --- a/tdutils/td/utils/port/uname.cpp +++ b/tdutils/td/utils/port/uname.cpp @@ -194,7 +194,7 @@ Slice get_operating_system_version() { } #endif - utsname name; + struct utsname name; int err = uname(&name); if (err == 0) { auto os_name = trim(PSTRING() << Slice(name.sysname, std::strlen(name.sysname)) << " "