5 SCRIPT_DIR="$(dirname "$BASH_SOURCE")"
6 SCRIPT_DIR="$(realpath "$SCRIPT_DIR")"
8 num_vcpus=$(( $(lscpu -p | tail -1 | cut -d "," -f 1) + 1 ))
9 NUM_WORKERS=${NUM_WORKERS:-$num_vcpus}
11 DEPS_DIR="${DEPS_DIR:-$SCRIPT_DIR/build.deps}"
12 depsSrcDir="$DEPS_DIR/src"
13 depsToolsetDir="$DEPS_DIR/mingw"
15 lz4SrcDir="${depsSrcDir}/lz4"
16 lz4Dir="${depsToolsetDir}/lz4"
19 sslDir="${depsToolsetDir}/openssl"
20 sslSrcDir="${depsSrcDir}/openssl-${sslVersion}"
23 curlSrcDir="${depsSrcDir}/curl"
24 curlDir="${depsToolsetDir}/curl"
26 # For now, we'll keep the version number within the file path when not using git.
27 boostUrl="https://dl.bintray.com/boostorg/release/1.70.0/source/boost_1_70_0.tar.gz"
28 boostSrcDir="${depsSrcDir}/boost_1_70_0"
29 boostDir="${depsToolsetDir}/boost"
30 zlibDir="${depsToolsetDir}/zlib"
31 zlibSrcDir="${depsSrcDir}/zlib"
32 backtraceDir="${depsToolsetDir}/backtrace"
33 backtraceSrcDir="${depsSrcDir}/backtrace"
34 snappySrcDir="${depsSrcDir}/snappy"
35 snappyDir="${depsToolsetDir}/snappy"
37 # Additional Windows libraries, which aren't provided by Mingw
38 winLibDir="${depsToolsetDir}/windows/lib"
41 MINGW_PREFIX="x86_64-w64-mingw32-"
44 make -j $NUM_WORKERS $@
48 mkdir -p $depsToolsetDir
51 MINGW_CMAKE_FILE="$DEPS_DIR/mingw.cmake"
52 cat > $MINGW_CMAKE_FILE <<EOL
53 set(CMAKE_SYSTEM_NAME Windows)
54 set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
56 # We'll need to use posix threads in order to use
57 # C++11 features, such as std::thread.
58 set(CMAKE_C_COMPILER \${TOOLCHAIN_PREFIX}-gcc-posix)
59 set(CMAKE_CXX_COMPILER \${TOOLCHAIN_PREFIX}-g++-posix)
60 set(CMAKE_RC_COMPILER \${TOOLCHAIN_PREFIX}-windres)
62 set(CMAKE_FIND_ROOT_PATH /usr/\${TOOLCHAIN_PREFIX} /usr/lib/gcc/\${TOOLCHAIN_PREFIX}/7.3-posix)
63 set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
64 set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
65 set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
68 sudo apt-get -y install mingw-w64 cmake pkg-config python3-dev python3-pip \
69 autoconf libtool ninja-build
70 sudo python3 -m pip install cython
73 if [[ ! -d $zlibDir ]]; then
74 git clone https://github.com/madler/zlib
77 # Apparently the configure script is broken...
78 sed -e s/"PREFIX ="/"PREFIX = x86_64-w64-mingw32-"/ -i win32/Makefile.gcc
79 _make -f win32/Makefile.gcc
80 _make BINARY_PATH=$zlibDir \
81 INCLUDE_PATH=$zlibDir/include \
82 LIBRARY_PATH=$zlibDir/lib \
84 -f win32/Makefile.gcc install
87 if [[ ! -d $lz4Dir ]]; then
88 git clone https://github.com/lz4/lz4
92 _make BUILD_STATIC=no CC=x86_64-w64-mingw32-gcc \
93 DLLTOOL=x86_64-w64-mingw32-dlltool OS=Windows_NT
96 if [[ ! -d $sslSrcDir ]]; then
97 curl "https://www.openssl.org/source/openssl-${sslVersion}.tar.gz" | tar xz
101 CROSS_COMPILE="x86_64-w64-mingw32-" ./Configure \
102 mingw64 shared --prefix=$sslDir
108 if [[ ! -d $curlSrcDir ]]; then
109 git clone https://github.com/curl/curl
112 git checkout $curlTag
114 ./configure --prefix=$curlDir --with-ssl=$sslDir --with-zlib=$zlibDir \
115 --host=x86_64-w64-mingw32
121 if [[ ! -d $boostSrcDir ]]; then
122 wget -qO- $boostUrl | tar xz
126 echo "using gcc : mingw32 : x86_64-w64-mingw32-g++-posix ;" > user-config.jam
128 # Workaround for https://github.com/boostorg/thread/issues/156
129 # Older versions of mingw provided a different pthread lib.
130 sed -i 's/lib$(libname)GC2.a/lib$(libname).a/g' ./libs/thread/build/Jamfile.v2
131 sed -i 's/mthreads/pthreads/g' ./tools/build/src/tools/gcc.py
132 sed -i 's/mthreads/pthreads/g' ./tools/build/src/tools/gcc.jam
134 sed -i 's/pthreads/mthreads/g' ./tools/build/src/tools/gcc.py
135 sed -i 's/pthreads/mthreads/g' ./tools/build/src/tools/gcc.jam
137 export PTW32_INCLUDE=/usr/share/mingw-w64/include
138 export PTW32_LIB=/usr/x86_64-w64-mingw32/lib
140 # Fix getting Windows page size
141 # TODO: send this upstream and maybe use a fork until it merges.
142 # Meanwhile, we might consider moving those to ceph/cmake/modules/BuildBoost.cmake.
143 # This cmake module will first have to be updated to support Mingw though.
144 cat | patch -N boost/thread/pthread/thread_data.hpp <<EOL
145 --- boost/thread/pthread/thread_data.hpp 2019-10-11 15:26:15.678703586 +0300
146 +++ boost/thread/pthread/thread_data.hpp.new 2019-10-11 15:26:07.321463698 +0300
152 +#include <windows.h>
160 #ifdef BOOST_THREAD_USES_GETPAGESIZE
161 std::size_t page_size = getpagesize();
163 + SYSTEM_INFO system_info;
164 + ::GetSystemInfo (&system_info);
165 + std::size_t page_size = system_info.dwPageSize;
167 std::size_t page_size = ::sysconf( _SC_PAGESIZE);
171 # Use pthread if requested
172 cat | patch -N boost/asio/detail/thread.hpp <<EOL
173 --- boost/asio/detail/thread.hpp 2019-10-11 16:26:11.191094656 +0300
174 +++ boost/asio/detail/thread.hpp.new 2019-10-11 16:26:03.310542438 +0300
177 #if !defined(BOOST_ASIO_HAS_THREADS)
178 # include <boost/asio/detail/null_thread.hpp>
179 +#elif defined(BOOST_ASIO_HAS_PTHREADS)
180 +# include <boost/asio/detail/posix_thread.hpp>
181 #elif defined(BOOST_ASIO_WINDOWS)
182 # if defined(UNDER_CE)
183 # include <boost/asio/detail/wince_thread.hpp>
186 # include <boost/asio/detail/win_thread.hpp>
188 -#elif defined(BOOST_ASIO_HAS_PTHREADS)
189 -# include <boost/asio/detail/posix_thread.hpp>
190 #elif defined(BOOST_ASIO_HAS_STD_THREAD)
191 # include <boost/asio/detail/std_thread.hpp>
195 #if !defined(BOOST_ASIO_HAS_THREADS)
196 typedef null_thread thread;
197 +#elif defined(BOOST_ASIO_HAS_PTHREADS)
198 +typedef posix_thread thread;
199 #elif defined(BOOST_ASIO_WINDOWS)
200 # if defined(UNDER_CE)
201 typedef wince_thread thread;
204 typedef win_thread thread;
206 -#elif defined(BOOST_ASIO_HAS_PTHREADS)
207 -typedef posix_thread thread;
208 #elif defined(BOOST_ASIO_HAS_STD_THREAD)
209 typedef std_thread thread;
213 # Unix socket support for Windows is currently disabled by Boost.
214 # https://github.com/huangqinjin/asio/commit/d27a8ad1870
215 cat | patch -N boost/asio/detail/socket_types.hpp <<EOL
216 --- boost/asio/detail/socket_types.hpp 2019-11-29 16:50:58.647125797 +0000
217 +++ boost/asio/detail/socket_types.hpp.new 2020-01-13 11:45:05.015104678 +0000
219 typedef ipv6_mreq in6_mreq_type;
220 typedef sockaddr_in6 sockaddr_in6_type;
221 typedef sockaddr_storage sockaddr_storage_type;
222 +struct sockaddr_un_type { u_short sun_family;
223 + char sun_path[108]; }; /* copy from afunix.h */
224 typedef addrinfo addrinfo_type;
226 typedef ::linger linger_type;
228 cat | patch -N boost/asio/detail/config.hpp <<EOL
229 --- boost/asio/detail/config.hpp 2019-11-29 16:50:58.691126211 +0000
230 +++ boost/asio/detail/config.hpp.new 2020-01-13 13:09:17.966771750 +0000
231 @@ -1142,13 +1142,9 @@
232 // UNIX domain sockets.
233 #if !defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
234 # if !defined(BOOST_ASIO_DISABLE_LOCAL_SOCKETS)
235 -# if !defined(BOOST_ASIO_WINDOWS) \\
236 - && !defined(BOOST_ASIO_WINDOWS_RUNTIME) \\
237 - && !defined(__CYGWIN__)
238 +# if !defined(BOOST_ASIO_WINDOWS_RUNTIME)
239 # define BOOST_ASIO_HAS_LOCAL_SOCKETS 1
240 -# endif // !defined(BOOST_ASIO_WINDOWS)
241 - // && !defined(BOOST_ASIO_WINDOWS_RUNTIME)
242 - // && !defined(__CYGWIN__)
243 +# endif // !defined(BOOST_ASIO_WINDOWS_RUNTIME)
244 # endif // !defined(BOOST_ASIO_DISABLE_LOCAL_SOCKETS)
245 #endif // !defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
250 ./b2 install --user-config=user-config.jam toolset=gcc-mingw32 \
251 target-os=windows release \
252 threadapi=pthread --prefix=$boostDir \
253 address-model=64 architecture=x86 \
254 binary-format=pe abi=ms -j $NUM_WORKERS \
255 -sZLIB_INCLUDE=$zlibDir/include -sZLIB_LIBRARY_PATH=$zlibDir/lib \
256 --without-python --without-mpi
259 if [[ ! -d $backtraceSrcDir ]]; then
260 git clone https://github.com/ianlancetaylor/libbacktrace
262 mkdir libbacktrace/build
263 cd libbacktrace/build
264 ../configure --prefix=$backtraceDir --exec-prefix=$backtraceDir \
265 --host x86_64-w64-mingw32 --enable-host-shared
266 _make LDFLAGS="-no-undefined"
268 cp $backtraceDir/lib/libbacktrace.a $backtraceDir/lib/libbacktrace.dll.a
271 if [[ ! -d $snappySrcDir ]]; then
272 git clone https://github.com/google/snappy
274 mkdir -p snappy/build
275 cd snappy && git checkout $snappyTag
278 cmake -DCMAKE_INSTALL_PREFIX=$snappyDir \
279 -DCMAKE_BUILD_TYPE=Release \
280 -DBUILD_SHARED_LIBS=ON \
281 -DSNAPPY_BUILD_TESTS=OFF \
282 -DCMAKE_TOOLCHAIN_FILE=$MINGW_CMAKE_FILE \
287 cmake -DCMAKE_INSTALL_PREFIX=$snappyDir \
288 -DCMAKE_BUILD_TYPE=Release \
289 -DBUILD_SHARED_LIBS=OFF \
290 -DSNAPPY_BUILD_TESTS=OFF \
291 -DCMAKE_TOOLCHAIN_FILE=$MINGW_CMAKE_FILE \
296 # mswsock.lib is not provided by mingw, so we'll have to generate
299 cat > $winLibDir/mswsock.def <<EOF
305 GetAcceptExSockaddrs@32
314 MigrateWinsockConfiguration@12
325 s_perror@8sethostname@8
328 x86_64-w64-mingw32-dlltool -d $winLibDir/mswsock.def \
329 -l $winLibDir/libmswsock.a