]> git.proxmox.com Git - ceph.git/blame - ceph/win32_deps_build.sh
import ceph quincy 17.2.4
[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
f67539c2 8num_vcpus=$(nproc)
9f95a23c
TL
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"
f67539c2 18sslTag="OpenSSL_1_1_1c"
9f95a23c 19sslDir="${depsToolsetDir}/openssl"
f67539c2 20sslSrcDir="${depsSrcDir}/openssl"
9f95a23c 21
2a845540 22curlTag="curl-7_84_0"
9f95a23c
TL
23curlSrcDir="${depsSrcDir}/curl"
24curlDir="${depsToolsetDir}/curl"
25
26# For now, we'll keep the version number within the file path when not using git.
b3b6e05e
TL
27boostUrl="https://boostorg.jfrog.io/artifactory/main/release/1.75.0/source/boost_1_75_0.tar.gz"
28boostSrcDir="${depsSrcDir}/boost_1_75_0"
9f95a23c
TL
29boostDir="${depsToolsetDir}/boost"
30zlibDir="${depsToolsetDir}/zlib"
31zlibSrcDir="${depsSrcDir}/zlib"
f67539c2
TL
32backtraceDir="${depsToolsetDir}/libbacktrace"
33backtraceSrcDir="${depsSrcDir}/libbacktrace"
9f95a23c
TL
34snappySrcDir="${depsSrcDir}/snappy"
35snappyDir="${depsToolsetDir}/snappy"
522d829b 36snappyTag="1.1.9"
9f95a23c
TL
37# Additional Windows libraries, which aren't provided by Mingw
38winLibDir="${depsToolsetDir}/windows/lib"
39
f67539c2 40wnbdUrl="https://github.com/cloudbase/wnbd"
2a845540 41wnbdTag="main"
f67539c2
TL
42wnbdSrcDir="${depsSrcDir}/wnbd"
43wnbdLibDir="${depsToolsetDir}/wnbd/lib"
9f95a23c 44
f67539c2
TL
45dokanUrl="https://github.com/dokan-dev/dokany"
46dokanTag="v1.3.1.1000"
47dokanSrcDir="${depsSrcDir}/dokany"
48dokanLibDir="${depsToolsetDir}/dokany/lib"
49
50# Allow for OS specific customizations through the OS flag (normally
51# passed through from win32_build).
52# Valid options are currently "ubuntu" and "suse".
53OS=${OS:-"ubuntu"}
9f95a23c
TL
54
55function _make() {
56 make -j $NUM_WORKERS $@
57}
58
f67539c2
TL
59if [[ -d $DEPS_DIR ]]; then
60 echo "Cleaning up dependency build dir: $DEPS_DIR"
61 rm -rf $DEPS_DIR
62fi
63
9f95a23c
TL
64mkdir -p $DEPS_DIR
65mkdir -p $depsToolsetDir
66mkdir -p $depsSrcDir
67
b3b6e05e 68echo "Installing required packages."
f67539c2
TL
69case "$OS" in
70 ubuntu)
71 sudo apt-get update
20effc67
TL
72 sudo apt-get -y install mingw-w64 cmake pkg-config \
73 python3-dev python3-pip python3-yaml \
f67539c2
TL
74 autoconf libtool ninja-build zip
75 sudo python3 -m pip install cython
76 ;;
77 suse)
78 for PKG in mingw64-cross-gcc-c++ mingw64-libgcc_s_seh1 mingw64-libstdc++6 \
79 cmake pkgconf python3-devel autoconf libtool ninja zip \
20effc67
TL
80 python3-Cython python3-PyYAML \
81 gcc patch wget git; do
f67539c2
TL
82 rpm -q $PKG >/dev/null || zypper -n install $PKG
83 done
84 ;;
85esac
9f95a23c 86
f67539c2
TL
87MINGW_CMAKE_FILE="$DEPS_DIR/mingw.cmake"
88source "$SCRIPT_DIR/mingw_conf.sh"
9f95a23c 89
b3b6e05e 90echo "Building zlib."
9f95a23c 91cd $depsSrcDir
f67539c2 92if [[ ! -d $zlibSrcDir ]]; then
9f95a23c
TL
93 git clone https://github.com/madler/zlib
94fi
f67539c2 95cd $zlibSrcDir
9f95a23c 96# Apparently the configure script is broken...
f67539c2 97sed -e s/"PREFIX = *$"/"PREFIX = ${MINGW_PREFIX}"/ -i win32/Makefile.gcc
9f95a23c
TL
98_make -f win32/Makefile.gcc
99_make BINARY_PATH=$zlibDir \
100 INCLUDE_PATH=$zlibDir/include \
101 LIBRARY_PATH=$zlibDir/lib \
102 SHARED_MODE=1 \
103 -f win32/Makefile.gcc install
104
b3b6e05e 105echo "Building lz4."
9f95a23c
TL
106cd $depsToolsetDir
107if [[ ! -d $lz4Dir ]]; then
522d829b
TL
108 git clone --branch $lz4Tag --depth 1 https://github.com/lz4/lz4
109 cd $lz4Dir
9f95a23c 110fi
f67539c2
TL
111cd $lz4Dir
112_make BUILD_STATIC=no CC=${MINGW_CC%-posix*} \
113 DLLTOOL=${MINGW_DLLTOOL} \
114 WINDRES=${MINGW_WINDRES} \
115 TARGET_OS=Windows_NT
9f95a23c 116
b3b6e05e 117echo "Building OpenSSL."
9f95a23c
TL
118cd $depsSrcDir
119if [[ ! -d $sslSrcDir ]]; then
522d829b
TL
120 git clone --branch $sslTag --depth 1 https://github.com/openssl/openssl
121 cd $sslSrcDir
9f95a23c
TL
122fi
123cd $sslSrcDir
124mkdir -p $sslDir
f67539c2
TL
125CROSS_COMPILE="${MINGW_PREFIX}" ./Configure \
126 mingw64 shared --prefix=$sslDir --libdir="$sslDir/lib"
9f95a23c
TL
127_make depend
128_make
129_make install
130
b3b6e05e 131echo "Building libcurl."
9f95a23c
TL
132cd $depsSrcDir
133if [[ ! -d $curlSrcDir ]]; then
522d829b
TL
134 git clone --branch $curlTag --depth 1 https://github.com/curl/curl
135 cd $curlSrcDir
9f95a23c
TL
136fi
137cd $curlSrcDir
9f95a23c
TL
138./buildconf
139./configure --prefix=$curlDir --with-ssl=$sslDir --with-zlib=$zlibDir \
f67539c2 140 --host=${MINGW_BASE} --libdir="$curlDir/lib"
9f95a23c
TL
141_make
142_make install
143
144
b3b6e05e 145echo "Building boost."
9f95a23c
TL
146cd $depsSrcDir
147if [[ ! -d $boostSrcDir ]]; then
b3b6e05e 148 echo "Downloading boost."
9f95a23c
TL
149 wget -qO- $boostUrl | tar xz
150fi
151
152cd $boostSrcDir
f67539c2 153echo "using gcc : mingw32 : ${MINGW_CXX} ;" > user-config.jam
9f95a23c
TL
154
155# Workaround for https://github.com/boostorg/thread/issues/156
156# Older versions of mingw provided a different pthread lib.
157sed -i 's/lib$(libname)GC2.a/lib$(libname).a/g' ./libs/thread/build/Jamfile.v2
158sed -i 's/mthreads/pthreads/g' ./tools/build/src/tools/gcc.py
159sed -i 's/mthreads/pthreads/g' ./tools/build/src/tools/gcc.jam
160
161sed -i 's/pthreads/mthreads/g' ./tools/build/src/tools/gcc.py
162sed -i 's/pthreads/mthreads/g' ./tools/build/src/tools/gcc.jam
163
f67539c2
TL
164export PTW32_INCLUDE=${PTW32Include}
165export PTW32_LIB=${PTW32Lib}
9f95a23c 166
b3b6e05e 167echo "Patching boost."
9f95a23c
TL
168# Fix getting Windows page size
169# TODO: send this upstream and maybe use a fork until it merges.
170# Meanwhile, we might consider moving those to ceph/cmake/modules/BuildBoost.cmake.
171# This cmake module will first have to be updated to support Mingw though.
f67539c2 172patch -N boost/thread/pthread/thread_data.hpp <<EOL
9f95a23c
TL
173--- boost/thread/pthread/thread_data.hpp 2019-10-11 15:26:15.678703586 +0300
174+++ boost/thread/pthread/thread_data.hpp.new 2019-10-11 15:26:07.321463698 +0300
175@@ -32,6 +32,10 @@
176 # endif
177 #endif
178
179+#if defined(_WIN32)
180+#include <windows.h>
181+#endif
182+
183 #include <pthread.h>
184 #include <unistd.h>
185
186@@ -54,6 +58,10 @@
187 if (size==0) return;
188 #ifdef BOOST_THREAD_USES_GETPAGESIZE
189 std::size_t page_size = getpagesize();
190+#elif _WIN32
191+ SYSTEM_INFO system_info;
192+ ::GetSystemInfo (&system_info);
193+ std::size_t page_size = system_info.dwPageSize;
194 #else
195 std::size_t page_size = ::sysconf( _SC_PAGESIZE);
196 #endif
197EOL
198
9f95a23c
TL
199./bootstrap.sh
200
201./b2 install --user-config=user-config.jam toolset=gcc-mingw32 \
202 target-os=windows release \
f67539c2 203 link=static,shared \
2a845540 204 threadapi=win32 --prefix=$boostDir \
9f95a23c
TL
205 address-model=64 architecture=x86 \
206 binary-format=pe abi=ms -j $NUM_WORKERS \
207 -sZLIB_INCLUDE=$zlibDir/include -sZLIB_LIBRARY_PATH=$zlibDir/lib \
f67539c2 208 --without-python --without-mpi --without-log --without-wave
9f95a23c 209
b3b6e05e 210echo "Building libbacktrace."
9f95a23c
TL
211cd $depsSrcDir
212if [[ ! -d $backtraceSrcDir ]]; then
213 git clone https://github.com/ianlancetaylor/libbacktrace
214fi
f67539c2
TL
215mkdir -p $backtraceSrcDir/build
216cd $backtraceSrcDir/build
9f95a23c 217../configure --prefix=$backtraceDir --exec-prefix=$backtraceDir \
f67539c2
TL
218 --host ${MINGW_BASE} --enable-host-shared \
219 --libdir="$backtraceDir/lib"
9f95a23c
TL
220_make LDFLAGS="-no-undefined"
221_make install
9f95a23c 222
b3b6e05e 223echo "Building snappy."
9f95a23c
TL
224cd $depsSrcDir
225if [[ ! -d $snappySrcDir ]]; then
522d829b
TL
226 git clone --branch $snappyTag --depth 1 https://github.com/google/snappy
227 cd $snappySrcDir
9f95a23c 228fi
f67539c2
TL
229mkdir -p $snappySrcDir/build
230cd $snappySrcDir/build
9f95a23c
TL
231
232cmake -DCMAKE_INSTALL_PREFIX=$snappyDir \
233 -DCMAKE_BUILD_TYPE=Release \
234 -DBUILD_SHARED_LIBS=ON \
235 -DSNAPPY_BUILD_TESTS=OFF \
522d829b 236 -DSNAPPY_BUILD_BENCHMARKS=OFF \
9f95a23c
TL
237 -DCMAKE_TOOLCHAIN_FILE=$MINGW_CMAKE_FILE \
238 ../
239_make
240_make install
241
242cmake -DCMAKE_INSTALL_PREFIX=$snappyDir \
243 -DCMAKE_BUILD_TYPE=Release \
244 -DBUILD_SHARED_LIBS=OFF \
245 -DSNAPPY_BUILD_TESTS=OFF \
246 -DCMAKE_TOOLCHAIN_FILE=$MINGW_CMAKE_FILE \
247 ../
248_make
249_make install
250
b3b6e05e 251echo "Generating mswsock.lib."
9f95a23c
TL
252# mswsock.lib is not provided by mingw, so we'll have to generate
253# it.
254mkdir -p $winLibDir
255cat > $winLibDir/mswsock.def <<EOF
256LIBRARY MSWSOCK.DLL
257EXPORTS
258AcceptEx@32
259EnumProtocolsA@12
260EnumProtocolsW@12
261GetAcceptExSockaddrs@32
262GetAddressByNameA@40
263GetAddressByNameW@40
264GetNameByTypeA@12
265GetNameByTypeW@12
266GetServiceA@28
267GetServiceW@28
268GetTypeByNameA@8
269GetTypeByNameW@8
270MigrateWinsockConfiguration@12
271NPLoadNameSpaces@12
272SetServiceA@24
273SetServiceW@24
274TransmitFile@28
275WSARecvEx@16
276dn_expand@20
277getnetbyname@4
278inet_network@4
279rcmd@24
280rexec@24rresvport@4
281s_perror@8sethostname@8
282EOF
283
f67539c2
TL
284$MINGW_DLLTOOL -d $winLibDir/mswsock.def \
285 -l $winLibDir/libmswsock.a
286
b3b6e05e 287echo "Fetching libwnbd."
f67539c2
TL
288cd $depsSrcDir
289if [[ ! -d $wnbdSrcDir ]]; then
290 git clone $wnbdUrl
291 cd $wnbdSrcDir && git checkout $wnbdTag
292fi
293cd $wnbdSrcDir
294mkdir -p $wnbdLibDir
295$MINGW_DLLTOOL -d $wnbdSrcDir/libwnbd/libwnbd.def \
296 -D libwnbd.dll \
297 -l $wnbdLibDir/libwnbd.a
298
b3b6e05e 299echo "Fetching dokany."
f67539c2
TL
300cd $depsSrcDir
301if [[ ! -d $dokanSrcDir ]]; then
302 git clone $dokanUrl
303fi
304cd $dokanSrcDir
305git checkout $dokanTag
306
307mkdir -p $dokanLibDir
308$MINGW_DLLTOOL -d $dokanSrcDir/dokan/dokan.def \
309 -l $dokanLibDir/libdokan.a
310
311# That's probably the easiest way to deal with the dokan imports.
312# dokan.h is defined in both ./dokan and ./sys while both are using
313# sys/public.h without the "sys" prefix.
314cp $dokanSrcDir/sys/public.h $dokanSrcDir/dokan
315
b3b6e05e 316echo "Finished building Ceph dependencies."
f67539c2 317touch $depsToolsetDir/completed