#!/usr/bin/env bash set -e SCRIPT_DIR="$(dirname "$BASH_SOURCE")" SCRIPT_DIR="$(realpath "$SCRIPT_DIR")" num_vcpus=$(nproc) NUM_WORKERS=${NUM_WORKERS:-$num_vcpus} DEPS_DIR="${DEPS_DIR:-$SCRIPT_DIR/build.deps}" depsSrcDir="$DEPS_DIR/src" depsToolsetDir="$DEPS_DIR/mingw" lz4SrcDir="${depsSrcDir}/lz4" lz4Dir="${depsToolsetDir}/lz4" lz4Tag="v1.9.2" sslTag="OpenSSL_1_1_1c" sslDir="${depsToolsetDir}/openssl" sslSrcDir="${depsSrcDir}/openssl" curlTag="curl-7_66_0" curlSrcDir="${depsSrcDir}/curl" curlDir="${depsToolsetDir}/curl" # For now, we'll keep the version number within the file path when not using git. boostUrl="https://dl.bintray.com/boostorg/release/1.73.0/source/boost_1_73_0.tar.gz" boostSrcDir="${depsSrcDir}/boost_1_73_0" boostDir="${depsToolsetDir}/boost" zlibDir="${depsToolsetDir}/zlib" zlibSrcDir="${depsSrcDir}/zlib" backtraceDir="${depsToolsetDir}/libbacktrace" backtraceSrcDir="${depsSrcDir}/libbacktrace" snappySrcDir="${depsSrcDir}/snappy" snappyDir="${depsToolsetDir}/snappy" snappyTag="1.1.7" # Additional Windows libraries, which aren't provided by Mingw winLibDir="${depsToolsetDir}/windows/lib" wnbdUrl="https://github.com/cloudbase/wnbd" wnbdTag="master" wnbdSrcDir="${depsSrcDir}/wnbd" wnbdLibDir="${depsToolsetDir}/wnbd/lib" dokanUrl="https://github.com/dokan-dev/dokany" dokanTag="v1.3.1.1000" dokanSrcDir="${depsSrcDir}/dokany" dokanLibDir="${depsToolsetDir}/dokany/lib" # Allow for OS specific customizations through the OS flag (normally # passed through from win32_build). # Valid options are currently "ubuntu" and "suse". OS=${OS:-"ubuntu"} function _make() { make -j $NUM_WORKERS $@ } if [[ -d $DEPS_DIR ]]; then echo "Cleaning up dependency build dir: $DEPS_DIR" rm -rf $DEPS_DIR fi mkdir -p $DEPS_DIR mkdir -p $depsToolsetDir mkdir -p $depsSrcDir case "$OS" in ubuntu) sudo apt-get update sudo apt-get -y install mingw-w64 cmake pkg-config \ python3-dev python3-pip python3-yaml \ autoconf libtool ninja-build zip sudo python3 -m pip install cython ;; suse) for PKG in mingw64-cross-gcc-c++ mingw64-libgcc_s_seh1 mingw64-libstdc++6 \ cmake pkgconf python3-devel autoconf libtool ninja zip \ python3-Cython python3-PyYAML \ gcc patch wget git; do rpm -q $PKG >/dev/null || zypper -n install $PKG done ;; esac MINGW_CMAKE_FILE="$DEPS_DIR/mingw.cmake" source "$SCRIPT_DIR/mingw_conf.sh" cd $depsSrcDir if [[ ! -d $zlibSrcDir ]]; then git clone https://github.com/madler/zlib fi cd $zlibSrcDir # Apparently the configure script is broken... sed -e s/"PREFIX = *$"/"PREFIX = ${MINGW_PREFIX}"/ -i win32/Makefile.gcc _make -f win32/Makefile.gcc _make BINARY_PATH=$zlibDir \ INCLUDE_PATH=$zlibDir/include \ LIBRARY_PATH=$zlibDir/lib \ SHARED_MODE=1 \ -f win32/Makefile.gcc install cd $depsToolsetDir if [[ ! -d $lz4Dir ]]; then git clone https://github.com/lz4/lz4 cd $lz4Dir; git checkout $lz4Tag fi cd $lz4Dir _make BUILD_STATIC=no CC=${MINGW_CC%-posix*} \ DLLTOOL=${MINGW_DLLTOOL} \ WINDRES=${MINGW_WINDRES} \ TARGET_OS=Windows_NT cd $depsSrcDir if [[ ! -d $sslSrcDir ]]; then git clone https://github.com/openssl/openssl cd $sslSrcDir; git checkout $sslTag fi cd $sslSrcDir mkdir -p $sslDir CROSS_COMPILE="${MINGW_PREFIX}" ./Configure \ mingw64 shared --prefix=$sslDir --libdir="$sslDir/lib" _make depend _make _make install cd $depsSrcDir if [[ ! -d $curlSrcDir ]]; then git clone https://github.com/curl/curl cd $curlSrcDir && git checkout $curlTag fi cd $curlSrcDir ./buildconf ./configure --prefix=$curlDir --with-ssl=$sslDir --with-zlib=$zlibDir \ --host=${MINGW_BASE} --libdir="$curlDir/lib" _make _make install cd $depsSrcDir if [[ ! -d $boostSrcDir ]]; then wget -qO- $boostUrl | tar xz fi cd $boostSrcDir echo "using gcc : mingw32 : ${MINGW_CXX} ;" > user-config.jam # Workaround for https://github.com/boostorg/thread/issues/156 # Older versions of mingw provided a different pthread lib. sed -i 's/lib$(libname)GC2.a/lib$(libname).a/g' ./libs/thread/build/Jamfile.v2 sed -i 's/mthreads/pthreads/g' ./tools/build/src/tools/gcc.py sed -i 's/mthreads/pthreads/g' ./tools/build/src/tools/gcc.jam sed -i 's/pthreads/mthreads/g' ./tools/build/src/tools/gcc.py sed -i 's/pthreads/mthreads/g' ./tools/build/src/tools/gcc.jam export PTW32_INCLUDE=${PTW32Include} export PTW32_LIB=${PTW32Lib} # Fix getting Windows page size # TODO: send this upstream and maybe use a fork until it merges. # Meanwhile, we might consider moving those to ceph/cmake/modules/BuildBoost.cmake. # This cmake module will first have to be updated to support Mingw though. patch -N boost/thread/pthread/thread_data.hpp < +#endif + #include #include @@ -54,6 +58,10 @@ if (size==0) return; #ifdef BOOST_THREAD_USES_GETPAGESIZE std::size_t page_size = getpagesize(); +#elif _WIN32 + SYSTEM_INFO system_info; + ::GetSystemInfo (&system_info); + std::size_t page_size = system_info.dwPageSize; #else std::size_t page_size = ::sysconf( _SC_PAGESIZE); #endif EOL # Use pthread if requested patch -N boost/asio/detail/thread.hpp < +#elif defined(BOOST_ASIO_HAS_PTHREADS) +# include #elif defined(BOOST_ASIO_WINDOWS) # if defined(UNDER_CE) # include @@ -27,8 +29,6 @@ # else # include # endif -#elif defined(BOOST_ASIO_HAS_PTHREADS) -# include #elif defined(BOOST_ASIO_HAS_STD_THREAD) # include #else @@ -41,6 +41,8 @@ #if !defined(BOOST_ASIO_HAS_THREADS) typedef null_thread thread; +#elif defined(BOOST_ASIO_HAS_PTHREADS) +typedef posix_thread thread; #elif defined(BOOST_ASIO_WINDOWS) # if defined(UNDER_CE) typedef wince_thread thread; @@ -49,8 +51,6 @@ # else typedef win_thread thread; # endif -#elif defined(BOOST_ASIO_HAS_PTHREADS) -typedef posix_thread thread; #elif defined(BOOST_ASIO_HAS_STD_THREAD) typedef std_thread thread; #endif EOL # Unix socket support for Windows is currently disabled by Boost. # https://github.com/huangqinjin/asio/commit/d27a8ad1870 patch -N boost/asio/detail/socket_types.hpp <=1.75, it's unreleased as of 1.74. patch -N boost/process/detail/windows/handle_workaround.hpp < $winLibDir/mswsock.def <