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