Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support support for musl libc on linux #1632

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
71 changes: 71 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,77 @@ jobs:
python3 -c 'import pyxrootd; print(pyxrootd)'
python3 -c 'from XRootD import client; print(client.FileSystem("root://someserver:1094"))'

cmake-voidlinux:

runs-on: ubuntu-latest
container: 'ghcr.io/void-linux/xbps-src-masterdir:20220527RC01-x86_64-musl'

steps:
- name: Install external dependencies with xbps
run: |
# Sync and upgrade once, assume error comes from xbps update
xbps-install -Syu || xbps-install -yu xbps
# Upgrade again (in case there was a xbps update)
xbps-install -Syu
# Install script dependencies
xbps-install -y \
gcc \
git \
cmake \
make \
pkg-config \
libuuid-devel \
openssl-devel \
readline-devel \
libexecinfo-devel \
zlib-devel \
python3 \
python3-pip \
python3-wheel \
python3-devel

- name: Clone repository
uses: actions/checkout@v1
with:
fetch-depth: 1

- name: Build with cmake
run: |
git config --global --add safe.directory "$PWD"
cd ..
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/ \
-DPYTHON_EXECUTABLE=$(command -v python3) \
-DENABLE_TESTS=ON \
-DCMAKE_CXX_STANDARD_LIBRARIES=-lexecinfo \
-DPIP_OPTIONS="--verbose" \
-S xrootd \
-B build
cmake build -LH
cmake \
--build build \
--clean-first \
--parallel $(($(nproc) - 1))
cmake --build build --target install
python3 -m pip list

- name: Verify install
run: |
command -v xrootd
command -v xrdcp

- name: Verify Python bindings
run: |
export LD_LIBRARY_PATH="/usr/local/lib64:${LD_LIBRARY_PATH}"
export PYTHON_VERSION_MINOR=$(python3 -c 'import sys; print(f"{sys.version_info.minor}")')
export PYTHONPATH="/usr/local/lib/python3.${PYTHON_VERSION_MINOR}/site-packages:${PYTHONPATH}"
python3 --version --version
python3 -m pip list
python3 -m pip show xrootd
python3 -c 'import XRootD; print(XRootD)'
python3 -c 'import pyxrootd; print(pyxrootd)'
python3 -c 'from XRootD import client; print(client.FileSystem("root://someserver:1094"))'

cmake-macos:

runs-on: macos-latest
Expand Down
18 changes: 18 additions & 0 deletions cmake/XRootDOSDefs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#-------------------------------------------------------------------------------

include( CheckCXXSourceRuns )
include( CheckFunctionExists )
include( CheckSymbolExists )
include( CheckIncludeFile )


set( LINUX FALSE )
set( KFREEBSD FALSE )
Expand Down Expand Up @@ -70,6 +74,20 @@ if( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" )
set( LINUX TRUE )
include( GNUInstallDirs )
set( EXTRA_LIBS rt )

check_symbol_exists( __GLIBC__ features.h HAVE_GLIBC )
if ( LINUX AND NOT HAVE_GLIBC )
check_function_exists( __fseterr HAVE_fseterr )
check_include_file( bits/alltypes.h HAVE_BITS_ALLTYPES )
check_include_file( stdio_ext.h HAVE_STDIO_EXT )
if ( HAVE_fseterr AND HAVE_BITS_ALLTYPES AND HAVE_STDIO_EXT )
add_definitions( -DHAVE_MUSL_LIBC )
check_include_file( execinfo.h HAVE_EXECINFO )
if ( NOT HAVE_EXECINFO )
message(FATAL_ERROR "Cannot find execinfo.h!")
endif()
endif()
endif()
endif()

#-------------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions src/Xrd/XrdConfig.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
#include "Xrd/XrdProtLoad.hh"
#include "Xrd/XrdProtocol.hh"

#if defined(__linux__) && defined(HAVE_MUSL_LIBC)
#define __NEED_mode_t
#include <bits/alltypes.h>
#endif

class XrdSysError;
class XrdTcpMonInfo;
class XrdNetSecurity;
Expand Down
2 changes: 1 addition & 1 deletion src/Xrd/XrdPoll.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/* specific prior written permission of the institution or contributor. */
/******************************************************************************/

#include <sys/poll.h>
#include <poll.h>
#include "XrdSys/XrdSysPthread.hh"

#define XRD_NUMPOLLERS 3
Expand Down
8 changes: 8 additions & 0 deletions src/XrdAcc/XrdAccGroups.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
#include "XrdAcc/XrdAccGroups.hh"
#include "XrdAcc/XrdAccPrivs.hh"

#if defined(__linux__) && defined(HAVE_MUSL_LIBC)
int innetgr(const char *netgroup, const char *host, const char *user,
const char *domain)
{
return 0;
}
#endif

// Additionally, this routine does not support a user in more than
// NGROUPS_MAX groups. This is a standard unix limit defined in limits.h.

Expand Down
6 changes: 6 additions & 0 deletions src/XrdCl/XrdClFileStateHandler.hh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
#include <sys/uio.h>
#include <cstdint>

#if defined(__linux__) && defined(HAVE_MUSL_LIBC)
#define __NEED_suseconds_t
#define __NEED_struct_timeval
#include <bits/alltypes.h>
#endif

namespace
{
class PgReadHandler;
Expand Down
6 changes: 6 additions & 0 deletions src/XrdCl/XrdClMonitor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@

#include "XrdCl/XrdClFileSystem.hh"

#if defined(__linux__) && defined(HAVE_MUSL_LIBC)
#define __NEED_suseconds_t
#define __NEED_struct_timeval
#include <bits/alltypes.h>
#endif

namespace XrdCl
{
class URL;
Expand Down
2 changes: 1 addition & 1 deletion src/XrdNet/XrdNetMsg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/******************************************************************************/

#include <cerrno>
#include <sys/poll.h>
#include <poll.h>

#include "XrdNet/XrdNet.hh"
#include "XrdNet/XrdNetMsg.hh"
Expand Down
4 changes: 3 additions & 1 deletion src/XrdNet/XrdNetSecurity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@
#include <sys/types.h>
#include <Winsock2.h>
#include <io.h>
#include "XrdSys/XrdWin32.hh"
#endif
#if WIN32 || defined(__linux__) && defined(HAVE_MUSL_LIBC)
int innetgr(const char *netgroup, const char *host, const char *user,
const char *domain)
{
return 0;
}
#include "XrdSys/XrdWin32.hh"
#endif

#include "XrdNet/XrdNetAddr.hh"
Expand Down
2 changes: 1 addition & 1 deletion src/XrdOfs/XrdOfsHandle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include <cstdio>
#include <ctime>
#include <sys/errno.h>
#include <errno.h>
#include <sys/types.h>

#include "XrdOfs/XrdOfsHandle.hh"
Expand Down
2 changes: 1 addition & 1 deletion src/XrdOssCsi/XrdOssCsiTagstoreFile.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <memory>
#include <mutex>

#if defined(__GLIBC__) || defined(__BIONIC__) || defined(__CYGWIN__)
#if defined(__GLIBC__) || defined(HAVE_MUSL_LIBC) || defined(__BIONIC__) || defined(__CYGWIN__)
#include <byteswap.h>
#elif defined(__APPLE__)
// Make sure that byte swap functions are not already defined.
Expand Down
11 changes: 9 additions & 2 deletions src/XrdPosix/XrdPosix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
#include <fcntl.h>
#include <unistd.h>
#include <sys/uio.h>
#if defined(__linux__) && defined(HAVE_MUSL_LIBC)
#include <stdio_ext.h>
#endif

#include "XrdSys/XrdSysHeaders.hh"
#include "XrdPosix/XrdPosixLinkage.hh"
Expand Down Expand Up @@ -310,9 +313,11 @@ size_t XrdPosix_Fread(void *ptr, size_t size, size_t nitems, FILE *stream)
//
if (bytes > 0 && size) rc = bytes/size;
#ifndef SUNX86
#if defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
#if defined(__GLIBC__) || defined(__GNU__)
else if (bytes < 0) stream->_flags |= _IO_ERR_SEEN;
else stream->_flags |= _IO_EOF_SEEN;
#elif defined(HAVE_MUSL_LIBC)
else if (bytes < 0) __fseterr(stream);
#elif defined(__APPLE__) || defined(__FreeBSD__)
else if (bytes < 0) stream->_flags |= __SEOF;
else stream->_flags |= __SERR;
Expand Down Expand Up @@ -481,8 +486,10 @@ size_t XrdPosix_Fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream
//
if (bytes > 0 && size) rc = bytes/size;
#ifndef SUNX86
#if defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
#if defined(__GLIBC__) || defined(__GNU__)
else stream->_flags |= _IO_ERR_SEEN;
#elif defined(HAVE_MUSL_LIBC)
else __fseterr(stream);
#elif defined(__APPLE__) || defined(__FreeBSD__)
else stream->_flags |= __SERR;
#else
Expand Down
1 change: 1 addition & 0 deletions src/XrdPosix/XrdPosixLinkage.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <unistd.h>

#include "XrdPosix/XrdPosixOsDep.hh"
#include "XrdPosix/XrdPosixXrootd.hh"
#include "XrdSys/XrdSysPlatform.hh"

/******************************************************************************/
Expand Down
5 changes: 5 additions & 0 deletions src/XrdPosix/XrdPosixMap.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
#include "XrdCl/XrdClFileSystem.hh"
#include "XrdCl/XrdClXRootDResponses.hh"

#if defined(__linux__) && defined(HAVE_MUSL_LIBC)
#define __NEED_dev_t
#include <bits/alltypes.h>
#endif

class XrdPosixMap
{
public:
Expand Down
16 changes: 16 additions & 0 deletions src/XrdPosix/XrdPosixPreload.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@

#include "XrdPosix/XrdPosixExtern.hh"

#ifdef creat64
#undef creat64
#undef fseeko64
#undef ftello64
#undef ftruncate64
#undef lseek64
#undef open64
#undef pread64
#undef pwrite64
#undef readdir64
#undef readdir64_r
#undef statfs64
#undef statvfs64
#undef truncate64
#endif

/******************************************************************************/
/* G l o b a l D e c l a r a t i o n s */
/******************************************************************************/
Expand Down
10 changes: 1 addition & 9 deletions src/XrdSys/XrdSysPlatform.hh
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,8 @@ extern "C"
#if defined(_AIX) || \
(defined(XR__SUNGCC3) && !defined(__arch64__))
# define SOCKLEN_t size_t
#elif defined(XR__GLIBC) || \
defined(__FreeBSD__) || \
(defined(__FreeBSD_kernel__) && defined(__GLIBC__)) || \
(defined(XR__SUNGCC3) && defined(__arch64__)) || defined(__APPLE__) || \
(defined(__sun) && defined(_SOCKLEN_T))
# ifndef SOCKLEN_t
# define SOCKLEN_t socklen_t
# endif
#elif !defined(SOCKLEN_t)
# define SOCKLEN_t int
# define SOCKLEN_t socklen_t
#endif

#ifdef _LP64
Expand Down
4 changes: 2 additions & 2 deletions src/XrdSys/XrdSysPthread.hh
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ enum PrefType {prefWR=1};

XrdSysRWLock(PrefType ptype)
{
#ifdef __linux__
#ifdef __GLIBC__
pthread_rwlockattr_t attr;
pthread_rwlockattr_setkind_np(&attr,
PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
Expand All @@ -367,7 +367,7 @@ enum PrefType {prefWR=1};
inline void ReInitialize(PrefType ptype)
{
pthread_rwlock_destroy(&lock);
#ifdef __linux__
#ifdef __GLIBC__
pthread_rwlockattr_t attr;
pthread_rwlockattr_setkind_np(&attr,
PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
Expand Down
2 changes: 1 addition & 1 deletion src/XrdTls/XrdTlsTempCA.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <cstdlib>
#include <fcntl.h>
#include <dirent.h>
#include <sys/poll.h>
#include <poll.h>

#include <unordered_set>
#include <memory>
Expand Down
2 changes: 1 addition & 1 deletion src/XrdVoms/XrdVomsMapfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include <vector>
#include <string>
#include <fcntl.h>
#include <sys/poll.h>
#include <poll.h>

bool XrdVomsMapfile::tried_configure = false;
std::unique_ptr<XrdVomsMapfile> XrdVomsMapfile::mapper;
Expand Down