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