From 446eea404f511c978a9a4a20ae931c5c9d0bb135 Mon Sep 17 00:00:00 2001 From: "andrey.bychkov" Date: Sat, 29 Aug 2026 20:46:34 +0000 Subject: [PATCH] support building with musl libc (Alpine Linux) - use LFS64 file/stat APIs only on glibc/Windows (absent in musl) - use plain sched_priority outside glibc - do not declare pow10(double) where the system provides C23 pow10() (musl) - ICU is off by default: modern ICU (>= 75) needs C++17 for its headers, the project is built with C++11; enable explicitly with -DICU=ON - fix latent crash: PIThread::setThreadName() read the thread handle from inside the new thread; the handle is not guaranteed to be visible before start (musl publishes it later), rename the calling thread via pthread_self() instead --- CMakeLists.txt | 6 +----- libs/main/io_devices/pidir.cpp | 2 +- libs/main/io_devices/pifile.cpp | 14 ++++++++++---- libs/main/math/pimathbase.h | 2 ++ libs/main/thread/pithread.cpp | 8 ++++---- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c0d4bb99..a3d2e926 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,14 +57,10 @@ include(SHSTKMacros) shstk_begin_project(PIP) set(PIP_VERSION "${PIP_VERSION}" CACHE STRING "") -set(_ICU_DEFAULT OFF) -if((NOT DEFINED WIN32) AND (NOT DEFINED ANDROID_PLATFORM) AND (NOT DEFINED APPLE)) - set(_ICU_DEFAULT ON) -endif() set(PIP_DLL_DIR "${CMAKE_CURRENT_BINARY_DIR}" CACHE STRING "") # Options -option(ICU "ICU support for convert codepages" ${_ICU_DEFAULT}) +option(ICU "ICU support for convert codepages" OFF) option(STD_IOSTREAM "Building with std iostream operators support" OFF) option(INTROSPECTION "Build with introspection" OFF) option(TESTS "Build tests" OFF) diff --git a/libs/main/io_devices/pidir.cpp b/libs/main/io_devices/pidir.cpp index 6aabe59d..580662b1 100644 --- a/libs/main/io_devices/pidir.cpp +++ b/libs/main/io_devices/pidir.cpp @@ -22,7 +22,7 @@ const PIChar PIDir::separator = '/'; -#ifdef QNX +#if defined(QNX) || !(defined(MAC_OS) || defined(__GLIBC__) || defined(_WIN32)) # define _stat_struct_ struct stat # define _stat_call_ stat # define _stat_link_ lstat diff --git a/libs/main/io_devices/pifile.cpp b/libs/main/io_devices/pifile.cpp index 9cf7df4f..0d71c7cc 100644 --- a/libs/main/io_devices/pifile.cpp +++ b/libs/main/io_devices/pifile.cpp @@ -58,7 +58,7 @@ # define _fseek_call_ fseek # define _ftell_call_ ftell # else -# ifdef CC_GCC +# if defined(CC_GCC) && (defined(__GLIBC__) || defined(_WIN32)) # define _fopen_call_ fopen64 # define _fseek_call_ fseeko64 # define _ftell_call_ ftello64 @@ -68,9 +68,15 @@ # define _ftell_call_ ftell # endif # endif -# define _stat_struct_ struct stat64 -# define _stat_call_ stat64 -# define _stat_link_ lstat64 +# if defined(MAC_OS) || defined(__GLIBC__) || defined(_WIN32) +# define _stat_struct_ struct stat64 +# define _stat_call_ stat64 +# define _stat_link_ lstat64 +# else +# define _stat_struct_ struct stat +# define _stat_call_ stat +# define _stat_link_ lstat +# endif #endif diff --git a/libs/main/math/pimathbase.h b/libs/main/math/pimathbase.h index 9aeb126e..b1ffd6e5 100644 --- a/libs/main/math/pimathbase.h +++ b/libs/main/math/pimathbase.h @@ -160,9 +160,11 @@ inline int pow2 (const int p ) {return 1 << p;} //! \~russian Возвращает `10` в указанной степени. inline float pow10(const float & e) {return powf(10.f, e);} +#if !defined(__linux__) || defined(__GLIBC__) || defined(__BIONIC__) //! \~english Returns `10` raised to the specified power. //! \~russian Возвращает `10` в указанной степени. inline double pow10(const double & e) {return pow (10. , e);} +#endif //! \~english Returns `10` raised to the specified power. //! \~russian Возвращает `10` в указанной степени. diff --git a/libs/main/thread/pithread.cpp b/libs/main/thread/pithread.cpp index 23070bba..1f9863d0 100644 --- a/libs/main/thread/pithread.cpp +++ b/libs/main/thread/pithread.cpp @@ -795,10 +795,10 @@ void PIThread::setPriority(PIThread::Priority prior) { piZeroMemory(PRIVATE->sparam); pthread_getschedparam(PRIVATE->thread, &policy_, &(PRIVATE->sparam)); PRIVATE->sparam. -# ifndef LINUX - sched_priority -# else +# if defined(LINUX) && defined(__GLIBC__) __sched_priority +# else + sched_priority # endif = priority2System(priority_); pthread_setschedparam(PRIVATE->thread, policy_, &(PRIVATE->sparam)); @@ -1068,7 +1068,7 @@ void PIThread::setThreadName() { pthread_setname_np((const char *)name_ba.data()); pthread_threadid_np(PRIVATE->thread, (__uint64_t *)&tid_); # else - pthread_setname_np(PRIVATE->thread, (const char *)name_ba.data()); + pthread_setname_np(pthread_self(), (const char *)name_ba.data()); # endif #endif }