]> git.proxmox.com Git - ceph.git/blame - ceph/win32_deps_build.sh
bump version to 15.2.11-pve1
[ceph.git] / ceph / win32_deps_build.sh
CommitLineData
9f95a23c
TL
1#!/usr/bin/env bash
2
3set -e
4
5SCRIPT_DIR="$(dirname "$BASH_SOURCE")"
6SCRIPT_DIR="$(realpath "$SCRIPT_DIR")"
7
8num_vcpus=$(( $(lscpu -p | tail -1 | cut -d "," -f 1) + 1 ))
9NUM_WORKERS=${NUM_WORKERS:-$num_vcpus}
10
11DEPS_DIR="${DEPS_DIR:-$SCRIPT_DIR/build.deps}"
12depsSrcDir="$DEPS_DIR/src"
13depsToolsetDir="$DEPS_DIR/mingw"
14
15lz4SrcDir="${depsSrcDir}/lz4"
16lz4Dir="${depsToolsetDir}/lz4"
17lz4Tag="v1.9.2"
18sslVersion="1.1.1c"
19sslDir="${depsToolsetDir}/openssl"
20sslSrcDir="${depsSrcDir}/openssl-${sslVersion}"
21
22curlTag="curl-7_66_0"
23curlSrcDir="${depsSrcDir}/curl"
24curlDir="${depsToolsetDir}/curl"
25
26# For now, we'll keep the version number within the file path when not using git.
27boostUrl="https://dl.bintray.com/boostorg/release/1.70.0/source/boost_1_70_0.tar.gz"
28boostSrcDir="${depsSrcDir}/boost_1_70_0"
29boostDir="${depsToolsetDir}/boost"
30zlibDir="${depsToolsetDir}/zlib"
31zlibSrcDir="${depsSrcDir}/zlib"
32backtraceDir="${depsToolsetDir}/backtrace"
33backtraceSrcDir="${depsSrcDir}/backtrace"
34snappySrcDir="${depsSrcDir}/snappy"
35snappyDir="${depsToolsetDir}/snappy"
36snappyTag="1.1.7"
37# Additional Windows libraries, which aren't provided by Mingw
38winLibDir="${depsToolsetDir}/windows/lib"
39
40
41MINGW_PREFIX="x86_64-w64-mingw32-"
42
43function _make() {
44 make -j $NUM_WORKERS $@
45}
46
47mkdir -p $DEPS_DIR
48mkdir -p $depsToolsetDir
49mkdir -p $depsSrcDir
50
51MINGW_CMAKE_FILE="$DEPS_DIR/mingw.cmake"
52cat > $MINGW_CMAKE_FILE <<EOL
53set(CMAKE_SYSTEM_NAME Windows)
54set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
55
56# We'll need to use posix threads in order to use
57# C++11 features, such as std::thread.
58set(CMAKE_C_COMPILER \${TOOLCHAIN_PREFIX}-gcc-posix)
59set(CMAKE_CXX_COMPILER \${TOOLCHAIN_PREFIX}-g++-posix)
60set(CMAKE_RC_COMPILER \${TOOLCHAIN_PREFIX}-windres)
61
62set(CMAKE_FIND_ROOT_PATH /usr/\${TOOLCHAIN_PREFIX} /usr/lib/gcc/\${TOOLCHAIN_PREFIX}/7.3-posix)
63set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
64set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
65set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
66EOL
67
68sudo apt-get -y install mingw-w64 cmake pkg-config python3-dev python3-pip \
69 autoconf libtool ninja-build
70sudo python3 -m pip install cython
71
72cd $depsSrcDir
73if [[ ! -d $zlibDir ]]; then
74 git clone https://github.com/madler/zlib
75fi
76cd zlib
77# Apparently the configure script is broken...
78sed -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 \
83 SHARED_MODE=1 \
84 -f win32/Makefile.gcc install
85
86cd $depsToolsetDir
87if [[ ! -d $lz4Dir ]]; then
88 git clone https://github.com/lz4/lz4
89fi
90cd lz4
91git checkout $lz4Tag
92_make BUILD_STATIC=no CC=x86_64-w64-mingw32-gcc \
93 DLLTOOL=x86_64-w64-mingw32-dlltool OS=Windows_NT
94
95cd $depsSrcDir
96if [[ ! -d $sslSrcDir ]]; then
97 curl "https://www.openssl.org/source/openssl-${sslVersion}.tar.gz" | tar xz
98fi
99cd $sslSrcDir
100mkdir -p $sslDir
101CROSS_COMPILE="x86_64-w64-mingw32-" ./Configure \
102 mingw64 shared --prefix=$sslDir
103_make depend
104_make
105_make install
106
107cd $depsSrcDir
108if [[ ! -d $curlSrcDir ]]; then
109 git clone https://github.com/curl/curl
110fi
111cd $curlSrcDir
112git checkout $curlTag
113./buildconf
114./configure --prefix=$curlDir --with-ssl=$sslDir --with-zlib=$zlibDir \
115 --host=x86_64-w64-mingw32
116_make
117_make install
118
119
120cd $depsSrcDir
121if [[ ! -d $boostSrcDir ]]; then
122 wget -qO- $boostUrl | tar xz
123fi
124
125cd $boostSrcDir
126echo "using gcc : mingw32 : x86_64-w64-mingw32-g++-posix ;" > user-config.jam
127
128# Workaround for https://github.com/boostorg/thread/issues/156
129# Older versions of mingw provided a different pthread lib.
130sed -i 's/lib$(libname)GC2.a/lib$(libname).a/g' ./libs/thread/build/Jamfile.v2
131sed -i 's/mthreads/pthreads/g' ./tools/build/src/tools/gcc.py
132sed -i 's/mthreads/pthreads/g' ./tools/build/src/tools/gcc.jam
133
134sed -i 's/pthreads/mthreads/g' ./tools/build/src/tools/gcc.py
135sed -i 's/pthreads/mthreads/g' ./tools/build/src/tools/gcc.jam
136
137export PTW32_INCLUDE=/usr/share/mingw-w64/include
138export PTW32_LIB=/usr/x86_64-w64-mingw32/lib
139
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.
144cat | 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
147@@ -32,6 +32,10 @@
148 # endif
149 #endif
150
151+#if defined(_WIN32)
152+#include <windows.h>
153+#endif
154+
155 #include <pthread.h>
156 #include <unistd.h>
157
158@@ -54,6 +58,10 @@
159 if (size==0) return;
160 #ifdef BOOST_THREAD_USES_GETPAGESIZE
161 std::size_t page_size = getpagesize();
162+#elif _WIN32
163+ SYSTEM_INFO system_info;
164+ ::GetSystemInfo (&system_info);
165+ std::size_t page_size = system_info.dwPageSize;
166 #else
167 std::size_t page_size = ::sysconf( _SC_PAGESIZE);
168 #endif
169EOL
170
171# Use pthread if requested
172cat | 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
175@@ -19,6 +19,8 @@
176
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>
184@@ -27,8 +29,6 @@
185 # else
186 # include <boost/asio/detail/win_thread.hpp>
187 # endif
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>
192 #else
193@@ -41,6 +41,8 @@
194
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;
202@@ -49,8 +51,6 @@
203 # else
204 typedef win_thread thread;
205 # endif
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;
210 #endif
211EOL
212
213# Unix socket support for Windows is currently disabled by Boost.
214# https://github.com/huangqinjin/asio/commit/d27a8ad1870
215cat | 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
218@@ -200,6 +200,8 @@
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;
225 # endif
226 typedef ::linger linger_type;
227EOL
228cat | 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)
246EOL
247
248./bootstrap.sh
249
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
257
258cd $depsSrcDir
259if [[ ! -d $backtraceSrcDir ]]; then
260 git clone https://github.com/ianlancetaylor/libbacktrace
261fi
262mkdir libbacktrace/build
263cd libbacktrace/build
264../configure --prefix=$backtraceDir --exec-prefix=$backtraceDir \
265 --host x86_64-w64-mingw32 --enable-host-shared
266_make LDFLAGS="-no-undefined"
267_make install
268cp $backtraceDir/lib/libbacktrace.a $backtraceDir/lib/libbacktrace.dll.a
269
270cd $depsSrcDir
271if [[ ! -d $snappySrcDir ]]; then
272 git clone https://github.com/google/snappy
273fi
274mkdir -p snappy/build
275cd snappy && git checkout $snappyTag
276cd build
277
278cmake -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 \
283 ../
284_make
285_make install
286
287cmake -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 \
292 ../
293_make
294_make install
295
296# mswsock.lib is not provided by mingw, so we'll have to generate
297# it.
298mkdir -p $winLibDir
299cat > $winLibDir/mswsock.def <<EOF
300LIBRARY MSWSOCK.DLL
301EXPORTS
302AcceptEx@32
303EnumProtocolsA@12
304EnumProtocolsW@12
305GetAcceptExSockaddrs@32
306GetAddressByNameA@40
307GetAddressByNameW@40
308GetNameByTypeA@12
309GetNameByTypeW@12
310GetServiceA@28
311GetServiceW@28
312GetTypeByNameA@8
313GetTypeByNameW@8
314MigrateWinsockConfiguration@12
315NPLoadNameSpaces@12
316SetServiceA@24
317SetServiceW@24
318TransmitFile@28
319WSARecvEx@16
320dn_expand@20
321getnetbyname@4
322inet_network@4
323rcmd@24
324rexec@24rresvport@4
325s_perror@8sethostname@8
326EOF
327
328x86_64-w64-mingw32-dlltool -d $winLibDir/mswsock.def \
329 -l $winLibDir/libmswsock.a