From: Lucian Petrut Date: Thu, 3 Oct 2019 08:33:31 +0000 (+0300) Subject: [win32] Add build scripts X-Git-Tag: v15.1.1~328^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=0942873cfea7b410eb2741589dcccb42abd4f3e9;p=ceph.git [win32] Add build scripts This patch adds a couple of scripts that can be used for building Ceph for Windows along with its dependencies. For now, we're going to cross compile it using mingw. It's supposed to run on Ubuntu (feel free to update the command that's installing some of the dependencies within win32_deps_build.sh if you're interested in other distros). This commit also adds a short readme, describing the focus of the Windows porting effort, the building process and the current status. Signed-off-by: Lucian Petrut Signed-off-by: Alin Gabriel Serdean --- diff --git a/README.windows.rst b/README.windows.rst new file mode 100644 index 000000000000..f6a0ee8a9efa --- /dev/null +++ b/README.windows.rst @@ -0,0 +1,50 @@ +About +----- + +Ceph Windows support is currently a work in progress. For now, the main focus +is the client side, allowing Windows hosts to consume rados, rbd and cephfs +resources. + +Building +-------- + +At the moment, mingw gcc is the only supported compiler for building ceph +components for Windows. Support for msvc and clang will be added soon. + +`win32_build.sh`_ can be used for cross compiling Ceph and its dependencies. +It may be called from a Linux environment, including Windows Subsystem for +Linux. MSYS2 and CygWin may also work but those weren't tested. + +.. _win32_build.sh: win32_build.sh + +The script accepts the following flags: + +============ =============================== =============================== +Flag Description Default value +============ =============================== =============================== +CEPH_DIR The Ceph source code directory. The same as the script. +BUILD_DIR The directory where the $CEPH_DIR/build + generated artifacts will be + placed. +DEPS_DIR The directory where the Ceph $CEPH_DIR/build.deps + dependencies will be built. +NUM_WORKERS The number of workers to use The number of vcpus + when building Ceph. available +NINJA_BUILD Use Ninja instead of make. +CLEAN_BUILD Clean the build directory. +SKIP_BUILD Run cmake without actually + performing the build. +============ =============================== =============================== + +Current status +-------------- + +The rados and rbd binaries and libs compile successfully and can be used on +Windows, successfully connecting to the cluster and consuming pools. + +The libraries have to be built statically at the moment. The reason is that +there are a few circular library dependencies or unspecified dependencies, +which isn't supported when building DLLs. This mostly affects ``cls`` libraries. + +A significant number of tests from the ``tests`` directory have been port, +providing adequate coverage. diff --git a/win32_build.sh b/win32_build.sh new file mode 100755 index 000000000000..441cffe48289 --- /dev/null +++ b/win32_build.sh @@ -0,0 +1,127 @@ +#!/usr/bin/env bash + +set -e + +SCRIPT_DIR="$(dirname "$BASH_SOURCE")" +SCRIPT_DIR="$(realpath "$SCRIPT_DIR")" + +num_vcpus=$(( $(lscpu -p | tail -1 | cut -d "," -f 1) + 1 )) + +CEPH_DIR="${CEPH_DIR:-$SCRIPT_DIR}" +BUILD_DIR="${BUILD_DIR:-${CEPH_DIR}/build}" +DEPS_DIR="${DEPS_DIR:-$CEPH_DIR/build.deps}" + +CLEAN_BUILD=${CLEAN_BUILD:-} +SKIP_BUILD=${SKIP_BUILD:-} +NUM_WORKERS=${NUM_WORKERS:-$num_vcpus} +NINJA_BUILD=${NINJA_BUILD:-} +DEV_BUILD=${DEV_BUILD:-} + +# We'll have to be explicit here since auto-detecting doesn't work +# properly when cross compiling. +ALLOCATOR=${ALLOCATOR:-libc} +# Debug builds don't work with MINGW for the time being, failing with +# can't close : File too big +# -Wa,-mbig-obj does not help. +CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-RelWithDebInfo} + +depsSrcDir="$DEPS_DIR/src" +depsToolsetDir="$DEPS_DIR/mingw" + +lz4Dir="${depsToolsetDir}/lz4" +sslDir="${depsToolsetDir}/openssl" +curlDir="${depsToolsetDir}/curl" +boostDir="${depsToolsetDir}/boost" +zlibDir="${depsToolsetDir}/zlib" +backtraceDir="${depsToolsetDir}/backtrace" +snappyDir="${depsToolsetDir}/snappy" +winLibDir="${depsToolsetDir}/windows/lib" +if [[ -n $NINJA_BUILD ]]; then + generatorUsed="Ninja" +else + generatorUsed="Unix Makefiles" +fi + +pyVersion=`python -c "import sys; print('%d.%d' % (sys.version_info.major, sys.version_info.minor))"` + +depsDirs="$lz4Dir;$curlDir;$sslDir;$boostDir;$zlibDir;$backtraceDir;$snappyDir" +depsDirs+=";$winLibDir" + +# That's actually a dll, we may want to rename the file. +lz4Lib="${lz4Dir}/lib/liblz4.so.1.9.2" +lz4Include="${lz4Dir}/lib" +curlLib="${curlDir}/lib/libcurl.dll.a" +curlInclude="${curlDir}/include" + +if [[ -n $CLEAN_BUILD ]]; then + echo "Cleaning up build dir: $BUILD_DIR" + rm -rf $BUILD_DIR +fi + +if [[ ! -d $DEPS_DIR ]]; then + echo "Preparing dependencies: $DEPS_DIR" + NUM_WORKERS=$NUM_WORKERS DEPS_DIR=$DEPS_DIR \ + "$SCRIPT_DIR/win32_deps_build.sh" +fi + +mkdir -p $BUILD_DIR +cd $BUILD_DIR + +# We'll need to cross compile Boost.Python before enabling +# "WITH_MGR". +echo "Generating solution. Log: ${BUILD_DIR}/cmake.log" + +# This isn't propagated to some of the subprojects, we'll use an env variable +# for now. +export CMAKE_PREFIX_PATH=$depsDirs + +if [[ -n $DEV_BUILD ]]; then + echo "Dev build enabled." + echo "Git versioning will be disabled." + ENABLE_GIT_VERSION="OFF" +else + ENABLE_GIT_VERSION="ON" +fi + +# As opposed to Linux, Windows shared libraries can't have unresolved +# symbols. Until we fix the dependencies (which are either unspecified +# or circular), we'll have to stick to static linking. +cmake -D CMAKE_PREFIX_PATH=$depsDirs \ + -D CMAKE_TOOLCHAIN_FILE="$CEPH_DIR/cmake/toolchains/mingw32.cmake" \ + -D WITH_PYTHON2=OFF -D WITH_PYTHON3=ON \ + -D MGR_PYTHON_VERSION=$pyVersion \ + -D WITH_RDMA=OFF -D WITH_OPENLDAP=OFF \ + -D WITH_GSSAPI=OFF -D WITH_FUSE=OFF -D WITH_XFS=OFF \ + -D WITH_BLUESTORE=OFF -D WITH_LEVELDB=OFF \ + -D WITH_LTTNG=OFF -D WITH_BABELTRACE=OFF \ + -D WITH_SYSTEM_BOOST=ON -D WITH_MGR=OFF \ + -D WITH_LIBCEPHFS=OFF -D WITH_KRBD=OFF -D WITH_RADOSGW=OFF \ + -D ENABLE_SHARED=OFF -D WITH_RBD=ON -D BUILD_GMOCK=OFF \ + -D WITH_CEPHFS=OFF -D WITH_MANPAGE=OFF \ + -D WITH_MGR_DASHBOARD_FRONTEND=OFF -D WITH_SYSTEMD=OFF -D WITH_TESTS=OFF \ + -D LZ4_INCLUDE_DIR=$lz4Include -D LZ4_LIBRARY=$lz4Lib \ + -D Backtrace_Header="$backtraceDir/include/backtrace.h" \ + -D Backtrace_INCLUDE_DIR="$backtraceDir/include" \ + -D Backtrace_LIBRARY="$backtraceDir/lib/libbacktrace.dll.a" \ + -D Boost_THREADAPI="pthread" \ + -D ENABLE_GIT_VERSION=$ENABLE_GIT_VERSION \ + -D ALLOCATOR="$ALLOCATOR" -D CMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE \ + -G "$generatorUsed" \ + $CEPH_DIR 2>&1 | tee "${BUILD_DIR}/cmake.log" + +if [[ -z $SKIP_BUILD ]]; then + echo "Building using $NUM_WORKERS workers. Log: ${BUILD_DIR}/build.log" + echo "NINJA_BUILD = $NINJA_BUILD" + + # We're currently limitting the build scope to the rados/rbd binaries. + if [[ -n $NINJA_BUILD ]]; then + cd $BUILD_DIR + ninja -v rados.exe rbd.exe compressor | tee "${BUILD_DIR}/build.log" + else + cd $BUILD_DIR/src/tools + make -j $NUM_WORKERS 2>&1 | tee "${BUILD_DIR}/build.log" + + cd $BUILD_DIR/src/compressor + make -j $NUM_WORKERS 2>&1 | tee -a "${BUILD_DIR}/build.log" + fi +fi diff --git a/win32_deps_build.sh b/win32_deps_build.sh new file mode 100755 index 000000000000..e31eadd7cb89 --- /dev/null +++ b/win32_deps_build.sh @@ -0,0 +1,329 @@ +#!/usr/bin/env bash + +set -e + +SCRIPT_DIR="$(dirname "$BASH_SOURCE")" +SCRIPT_DIR="$(realpath "$SCRIPT_DIR")" + +num_vcpus=$(( $(lscpu -p | tail -1 | cut -d "," -f 1) + 1 )) +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" +sslVersion="1.1.1c" +sslDir="${depsToolsetDir}/openssl" +sslSrcDir="${depsSrcDir}/openssl-${sslVersion}" + +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.70.0/source/boost_1_70_0.tar.gz" +boostSrcDir="${depsSrcDir}/boost_1_70_0" +boostDir="${depsToolsetDir}/boost" +zlibDir="${depsToolsetDir}/zlib" +zlibSrcDir="${depsSrcDir}/zlib" +backtraceDir="${depsToolsetDir}/backtrace" +backtraceSrcDir="${depsSrcDir}/backtrace" +snappySrcDir="${depsSrcDir}/snappy" +snappyDir="${depsToolsetDir}/snappy" +snappyTag="1.1.7" +# Additional Windows libraries, which aren't provided by Mingw +winLibDir="${depsToolsetDir}/windows/lib" + + +MINGW_PREFIX="x86_64-w64-mingw32-" + +function _make() { + make -j $NUM_WORKERS $@ +} + +mkdir -p $DEPS_DIR +mkdir -p $depsToolsetDir +mkdir -p $depsSrcDir + +MINGW_CMAKE_FILE="$DEPS_DIR/mingw.cmake" +cat > $MINGW_CMAKE_FILE < 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=/usr/share/mingw-w64/include +export PTW32_LIB=/usr/x86_64-w64-mingw32/lib + +# 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. +cat | 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 +cat | 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 +cat | patch -N boost/asio/detail/socket_types.hpp < $winLibDir/mswsock.def <