]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | #!/usr/bin/env bash |
2 | ||
3 | set -e | |
4 | ||
5 | SCRIPT_DIR="$(dirname "$BASH_SOURCE")" | |
6 | SCRIPT_DIR="$(realpath "$SCRIPT_DIR")" | |
7 | ||
f67539c2 | 8 | num_vcpus=$(nproc) |
9f95a23c TL |
9 | NUM_WORKERS=${NUM_WORKERS:-$num_vcpus} |
10 | ||
11 | DEPS_DIR="${DEPS_DIR:-$SCRIPT_DIR/build.deps}" | |
12 | depsSrcDir="$DEPS_DIR/src" | |
13 | depsToolsetDir="$DEPS_DIR/mingw" | |
14 | ||
15 | lz4SrcDir="${depsSrcDir}/lz4" | |
16 | lz4Dir="${depsToolsetDir}/lz4" | |
17 | lz4Tag="v1.9.2" | |
f67539c2 | 18 | sslTag="OpenSSL_1_1_1c" |
9f95a23c | 19 | sslDir="${depsToolsetDir}/openssl" |
f67539c2 | 20 | sslSrcDir="${depsSrcDir}/openssl" |
9f95a23c TL |
21 | |
22 | curlTag="curl-7_66_0" | |
23 | curlSrcDir="${depsSrcDir}/curl" | |
24 | curlDir="${depsToolsetDir}/curl" | |
25 | ||
26 | # For now, we'll keep the version number within the file path when not using git. | |
b3b6e05e TL |
27 | boostUrl="https://boostorg.jfrog.io/artifactory/main/release/1.75.0/source/boost_1_75_0.tar.gz" |
28 | boostSrcDir="${depsSrcDir}/boost_1_75_0" | |
9f95a23c TL |
29 | boostDir="${depsToolsetDir}/boost" |
30 | zlibDir="${depsToolsetDir}/zlib" | |
31 | zlibSrcDir="${depsSrcDir}/zlib" | |
f67539c2 TL |
32 | backtraceDir="${depsToolsetDir}/libbacktrace" |
33 | backtraceSrcDir="${depsSrcDir}/libbacktrace" | |
9f95a23c TL |
34 | snappySrcDir="${depsSrcDir}/snappy" |
35 | snappyDir="${depsToolsetDir}/snappy" | |
36 | snappyTag="1.1.7" | |
37 | # Additional Windows libraries, which aren't provided by Mingw | |
38 | winLibDir="${depsToolsetDir}/windows/lib" | |
39 | ||
f67539c2 TL |
40 | wnbdUrl="https://github.com/cloudbase/wnbd" |
41 | wnbdTag="master" | |
42 | wnbdSrcDir="${depsSrcDir}/wnbd" | |
43 | wnbdLibDir="${depsToolsetDir}/wnbd/lib" | |
9f95a23c | 44 | |
f67539c2 TL |
45 | dokanUrl="https://github.com/dokan-dev/dokany" |
46 | dokanTag="v1.3.1.1000" | |
47 | dokanSrcDir="${depsSrcDir}/dokany" | |
48 | dokanLibDir="${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". | |
53 | OS=${OS:-"ubuntu"} | |
9f95a23c TL |
54 | |
55 | function _make() { | |
56 | make -j $NUM_WORKERS $@ | |
57 | } | |
58 | ||
f67539c2 TL |
59 | if [[ -d $DEPS_DIR ]]; then |
60 | echo "Cleaning up dependency build dir: $DEPS_DIR" | |
61 | rm -rf $DEPS_DIR | |
62 | fi | |
63 | ||
9f95a23c TL |
64 | mkdir -p $DEPS_DIR |
65 | mkdir -p $depsToolsetDir | |
66 | mkdir -p $depsSrcDir | |
67 | ||
b3b6e05e | 68 | echo "Installing required packages." |
f67539c2 TL |
69 | case "$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 | ;; | |
83 | esac | |
9f95a23c | 84 | |
f67539c2 TL |
85 | MINGW_CMAKE_FILE="$DEPS_DIR/mingw.cmake" |
86 | source "$SCRIPT_DIR/mingw_conf.sh" | |
9f95a23c | 87 | |
b3b6e05e | 88 | echo "Building zlib." |
9f95a23c | 89 | cd $depsSrcDir |
f67539c2 | 90 | if [[ ! -d $zlibSrcDir ]]; then |
9f95a23c TL |
91 | git clone https://github.com/madler/zlib |
92 | fi | |
f67539c2 | 93 | cd $zlibSrcDir |
9f95a23c | 94 | # Apparently the configure script is broken... |
f67539c2 | 95 | sed -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 | 103 | echo "Building lz4." |
9f95a23c TL |
104 | cd $depsToolsetDir |
105 | if [[ ! -d $lz4Dir ]]; then | |
106 | git clone https://github.com/lz4/lz4 | |
f67539c2 | 107 | cd $lz4Dir; git checkout $lz4Tag |
9f95a23c | 108 | fi |
f67539c2 TL |
109 | cd $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 | 115 | echo "Building OpenSSL." |
9f95a23c TL |
116 | cd $depsSrcDir |
117 | if [[ ! -d $sslSrcDir ]]; then | |
f67539c2 TL |
118 | git clone https://github.com/openssl/openssl |
119 | cd $sslSrcDir; git checkout $sslTag | |
9f95a23c TL |
120 | fi |
121 | cd $sslSrcDir | |
122 | mkdir -p $sslDir | |
f67539c2 TL |
123 | CROSS_COMPILE="${MINGW_PREFIX}" ./Configure \ |
124 | mingw64 shared --prefix=$sslDir --libdir="$sslDir/lib" | |
9f95a23c TL |
125 | _make depend |
126 | _make | |
127 | _make install | |
128 | ||
b3b6e05e | 129 | echo "Building libcurl." |
9f95a23c TL |
130 | cd $depsSrcDir |
131 | if [[ ! -d $curlSrcDir ]]; then | |
132 | git clone https://github.com/curl/curl | |
f67539c2 | 133 | cd $curlSrcDir && git checkout $curlTag |
9f95a23c TL |
134 | fi |
135 | cd $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 | 143 | echo "Building boost." |
9f95a23c TL |
144 | cd $depsSrcDir |
145 | if [[ ! -d $boostSrcDir ]]; then | |
b3b6e05e | 146 | echo "Downloading boost." |
9f95a23c TL |
147 | wget -qO- $boostUrl | tar xz |
148 | fi | |
149 | ||
150 | cd $boostSrcDir | |
f67539c2 | 151 | echo "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. | |
155 | sed -i 's/lib$(libname)GC2.a/lib$(libname).a/g' ./libs/thread/build/Jamfile.v2 | |
156 | sed -i 's/mthreads/pthreads/g' ./tools/build/src/tools/gcc.py | |
157 | sed -i 's/mthreads/pthreads/g' ./tools/build/src/tools/gcc.jam | |
158 | ||
159 | sed -i 's/pthreads/mthreads/g' ./tools/build/src/tools/gcc.py | |
160 | sed -i 's/pthreads/mthreads/g' ./tools/build/src/tools/gcc.jam | |
161 | ||
f67539c2 TL |
162 | export PTW32_INCLUDE=${PTW32Include} |
163 | export PTW32_LIB=${PTW32Lib} | |
9f95a23c | 164 | |
b3b6e05e | 165 | echo "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 | 170 | patch -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 | |
195 | EOL | |
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 | 208 | echo "Building libbacktrace." |
9f95a23c TL |
209 | cd $depsSrcDir |
210 | if [[ ! -d $backtraceSrcDir ]]; then | |
211 | git clone https://github.com/ianlancetaylor/libbacktrace | |
212 | fi | |
f67539c2 TL |
213 | mkdir -p $backtraceSrcDir/build |
214 | cd $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 | 221 | echo "Building snappy." |
9f95a23c TL |
222 | cd $depsSrcDir |
223 | if [[ ! -d $snappySrcDir ]]; then | |
224 | git clone https://github.com/google/snappy | |
f67539c2 | 225 | cd $snappySrcDir && git checkout $snappyTag |
9f95a23c | 226 | fi |
f67539c2 TL |
227 | mkdir -p $snappySrcDir/build |
228 | cd $snappySrcDir/build | |
9f95a23c TL |
229 | |
230 | cmake -DCMAKE_INSTALL_PREFIX=$snappyDir \ | |
231 | -DCMAKE_BUILD_TYPE=Release \ | |
232 | -DBUILD_SHARED_LIBS=ON \ | |
233 | -DSNAPPY_BUILD_TESTS=OFF \ | |
234 | -DCMAKE_TOOLCHAIN_FILE=$MINGW_CMAKE_FILE \ | |
235 | ../ | |
236 | _make | |
237 | _make install | |
238 | ||
239 | cmake -DCMAKE_INSTALL_PREFIX=$snappyDir \ | |
240 | -DCMAKE_BUILD_TYPE=Release \ | |
241 | -DBUILD_SHARED_LIBS=OFF \ | |
242 | -DSNAPPY_BUILD_TESTS=OFF \ | |
243 | -DCMAKE_TOOLCHAIN_FILE=$MINGW_CMAKE_FILE \ | |
244 | ../ | |
245 | _make | |
246 | _make install | |
247 | ||
b3b6e05e | 248 | echo "Generating mswsock.lib." |
9f95a23c TL |
249 | # mswsock.lib is not provided by mingw, so we'll have to generate |
250 | # it. | |
251 | mkdir -p $winLibDir | |
252 | cat > $winLibDir/mswsock.def <<EOF | |
253 | LIBRARY MSWSOCK.DLL | |
254 | EXPORTS | |
255 | AcceptEx@32 | |
256 | EnumProtocolsA@12 | |
257 | EnumProtocolsW@12 | |
258 | GetAcceptExSockaddrs@32 | |
259 | GetAddressByNameA@40 | |
260 | GetAddressByNameW@40 | |
261 | GetNameByTypeA@12 | |
262 | GetNameByTypeW@12 | |
263 | GetServiceA@28 | |
264 | GetServiceW@28 | |
265 | GetTypeByNameA@8 | |
266 | GetTypeByNameW@8 | |
267 | MigrateWinsockConfiguration@12 | |
268 | NPLoadNameSpaces@12 | |
269 | SetServiceA@24 | |
270 | SetServiceW@24 | |
271 | TransmitFile@28 | |
272 | WSARecvEx@16 | |
273 | dn_expand@20 | |
274 | getnetbyname@4 | |
275 | inet_network@4 | |
276 | rcmd@24 | |
277 | rexec@24rresvport@4 | |
278 | s_perror@8sethostname@8 | |
279 | EOF | |
280 | ||
f67539c2 TL |
281 | $MINGW_DLLTOOL -d $winLibDir/mswsock.def \ |
282 | -l $winLibDir/libmswsock.a | |
283 | ||
b3b6e05e | 284 | echo "Fetching libwnbd." |
f67539c2 TL |
285 | cd $depsSrcDir |
286 | if [[ ! -d $wnbdSrcDir ]]; then | |
287 | git clone $wnbdUrl | |
288 | cd $wnbdSrcDir && git checkout $wnbdTag | |
289 | fi | |
290 | cd $wnbdSrcDir | |
291 | mkdir -p $wnbdLibDir | |
292 | $MINGW_DLLTOOL -d $wnbdSrcDir/libwnbd/libwnbd.def \ | |
293 | -D libwnbd.dll \ | |
294 | -l $wnbdLibDir/libwnbd.a | |
295 | ||
b3b6e05e | 296 | echo "Fetching dokany." |
f67539c2 TL |
297 | cd $depsSrcDir |
298 | if [[ ! -d $dokanSrcDir ]]; then | |
299 | git clone $dokanUrl | |
300 | fi | |
301 | cd $dokanSrcDir | |
302 | git checkout $dokanTag | |
303 | ||
304 | mkdir -p $dokanLibDir | |
305 | $MINGW_DLLTOOL -d $dokanSrcDir/dokan/dokan.def \ | |
306 | -l $dokanLibDir/libdokan.a | |
307 | ||
308 | # That's probably the easiest way to deal with the dokan imports. | |
309 | # dokan.h is defined in both ./dokan and ./sys while both are using | |
310 | # sys/public.h without the "sys" prefix. | |
311 | cp $dokanSrcDir/sys/public.h $dokanSrcDir/dokan | |
312 | ||
b3b6e05e | 313 | echo "Finished building Ceph dependencies." |
f67539c2 | 314 | touch $depsToolsetDir/completed |