]> git.proxmox.com Git - ceph.git/blob - ceph/win32_build.sh
import ceph pacific 16.2.5
[ceph.git] / ceph / win32_build.sh
1 #!/usr/bin/env bash
2
3 set -e
4 set -o pipefail
5
6 SCRIPT_DIR="$(dirname "$BASH_SOURCE")"
7 SCRIPT_DIR="$(realpath "$SCRIPT_DIR")"
8
9 num_vcpus=$(nproc)
10
11 CEPH_DIR="${CEPH_DIR:-$SCRIPT_DIR}"
12 BUILD_DIR="${BUILD_DIR:-${CEPH_DIR}/build}"
13 DEPS_DIR="${DEPS_DIR:-$CEPH_DIR/build.deps}"
14 ZIP_DEST="${ZIP_DEST:-$BUILD_DIR/ceph.zip}"
15
16 CLEAN_BUILD=${CLEAN_BUILD:-}
17 SKIP_BUILD=${SKIP_BUILD:-}
18 # Usefull when packaging existing binaries.
19 SKIP_CMAKE=${SKIP_CMAKE:-}
20 SKIP_DLL_COPY=${SKIP_DLL_COPY:-}
21 SKIP_TESTS=${SKIP_TESTS:-}
22 SKIP_BINDIR_CLEAN=${SKIP_BINDIR_CLEAN:-}
23 # Use Ninja's default, it might be useful when having few cores.
24 NUM_WORKERS_DEFAULT=$(( $num_vcpus + 2 ))
25 NUM_WORKERS=${NUM_WORKERS:-$NUM_WORKERS_DEFAULT}
26 DEV_BUILD=${DEV_BUILD:-}
27 # Unless SKIP_ZIP is set, we're preparing an archive that contains the Ceph
28 # binaries, debug symbols as well as the required DLLs.
29 SKIP_ZIP=${SKIP_ZIP:-}
30 # By default, we'll move the debug symbols to separate files located in the
31 # ".debug" directory. If "EMBEDDED_DBG_SYM" is set, the debug symbols will
32 # remain embedded in the binaries.
33 #
34 # Unfortunately we cannot use pdb symbols when cross compiling. cv2pdb
35 # well as llvm rely on mspdb*.dll in order to support this proprietary format.
36 EMBEDDED_DBG_SYM=${EMBEDDED_DBG_SYM:-}
37 # Allow for OS specific customizations through the OS flag.
38 # Valid options are currently "ubuntu" and "suse".
39
40 OS=${OS}
41 if [[ -z $OS ]]; then
42 if [[ -f /etc/os-release ]] && \
43 $(grep -q "^NAME=\".*SUSE.*\"" /etc/os-release); then
44 OS="suse"
45 elif [[ -f /etc/lsb-release ]] && \
46 $(grep -q "^DISTRIB_ID=Ubuntu" /etc/lsb-release); then
47 OS="ubuntu"
48 else
49 echo "Unsupported Linux distro, only SUSE and Ubuntu are currently \
50 supported. Set the OS variable to override"
51 exit 1
52 fi
53 fi
54 export OS="$OS"
55
56 # We'll have to be explicit here since auto-detecting doesn't work
57 # properly when cross compiling.
58 ALLOCATOR=${ALLOCATOR:-libc}
59 # Debug builds don't work with MINGW for the time being, failing with
60 # can't close <file>: File too big
61 # -Wa,-mbig-obj does not help.
62 CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-}
63 if [[ -z $CMAKE_BUILD_TYPE ]]; then
64 # By default, we're building release binaries with minimal debug information.
65 export CFLAGS="$CFLAGS -g1"
66 export CXXFLAGS="$CXXFLAGS -g1"
67 CMAKE_BUILD_TYPE=Release
68 fi
69
70 # Some tests can't use shared libraries yet due to unspecified dependencies.
71 # We'll do a static build by default for now.
72 ENABLE_SHARED=${ENABLE_SHARED:-OFF}
73
74 binDir="$BUILD_DIR/bin"
75 strippedBinDir="$BUILD_DIR/bin_stripped"
76 # GDB will look for this directory by default.
77 dbgDirname=".debug"
78 dbgSymbolDir="$strippedBinDir/${dbgDirname}"
79 depsSrcDir="$DEPS_DIR/src"
80 depsToolsetDir="$DEPS_DIR/mingw"
81
82 cmakeGenerator="Ninja"
83 lz4Dir="${depsToolsetDir}/lz4"
84 sslDir="${depsToolsetDir}/openssl"
85 curlDir="${depsToolsetDir}/curl"
86 boostDir="${depsToolsetDir}/boost"
87 zlibDir="${depsToolsetDir}/zlib"
88 backtraceDir="${depsToolsetDir}/libbacktrace"
89 snappyDir="${depsToolsetDir}/snappy"
90 winLibDir="${depsToolsetDir}/windows/lib"
91 wnbdSrcDir="${depsSrcDir}/wnbd"
92 wnbdLibDir="${depsToolsetDir}/wnbd/lib"
93 dokanSrcDir="${depsSrcDir}/dokany"
94 dokanLibDir="${depsToolsetDir}/dokany/lib"
95
96 depsDirs="$lz4Dir;$curlDir;$sslDir;$boostDir;$zlibDir;$backtraceDir;$snappyDir"
97 depsDirs+=";$winLibDir"
98
99 # Cmake recommends using CMAKE_PREFIX_PATH instead of link_directories.
100 # Still, some library dependencies may not include the full path (e.g. Boost
101 # sets the "-lz" flag through INTERFACE_LINK_LIBRARIES), which is why
102 # we have to ensure that the linker will be able to locate them.
103 linkDirs="$zlibDir/lib"
104
105 lz4Lib="${lz4Dir}/lib/dll/liblz4-1.dll"
106 lz4Include="${lz4Dir}/lib"
107 curlLib="${curlDir}/lib/libcurl.dll.a"
108 curlInclude="${curlDir}/include"
109
110 if [[ -n $CLEAN_BUILD ]]; then
111 echo "Cleaning up build dir: $BUILD_DIR"
112 rm -rf $BUILD_DIR
113 rm -rf $DEPS_DIR
114 fi
115 if [[ -z $SKIP_BINDIR_CLEAN ]]; then
116 echo "Cleaning up bin dir: $binDir"
117 rm -rf $binDir
118 fi
119
120 mkdir -p $BUILD_DIR
121 cd $BUILD_DIR
122
123 if [[ ! -f ${depsToolsetDir}/completed ]]; then
124 echo "Preparing dependencies: $DEPS_DIR. Log: ${BUILD_DIR}/build_deps.log"
125 NUM_WORKERS=$NUM_WORKERS DEPS_DIR=$DEPS_DIR OS="$OS"\
126 "$SCRIPT_DIR/win32_deps_build.sh" | tee "${BUILD_DIR}/build_deps.log"
127 fi
128
129 # Due to distribution specific mingw settings, the mingw.cmake file
130 # must be built prior to running cmake.
131 MINGW_CMAKE_FILE="$BUILD_DIR/mingw32.cmake"
132 MINGW_POSIX_FLAGS=1
133 source "$SCRIPT_DIR/mingw_conf.sh"
134
135 if [[ -z $SKIP_CMAKE ]]; then
136 # We'll need to cross compile Boost.Python before enabling
137 # "WITH_MGR".
138 echo "Generating solution. Log: ${BUILD_DIR}/cmake.log"
139
140 # This isn't propagated to some of the subprojects, we'll use an env variable
141 # for now.
142 export CMAKE_PREFIX_PATH=$depsDirs
143
144 if [[ -n $DEV_BUILD ]]; then
145 echo "Dev build enabled."
146 echo "Git versioning will be disabled."
147 ENABLE_GIT_VERSION="OFF"
148 WITH_CEPH_DEBUG_MUTEX="ON"
149 else
150 ENABLE_GIT_VERSION="ON"
151 WITH_CEPH_DEBUG_MUTEX="OFF"
152 fi
153
154 # As opposed to Linux, Windows shared libraries can't have unresolved
155 # symbols. Until we fix the dependencies (which are either unspecified
156 # or circular), we'll have to stick to static linking.
157 cmake -D CMAKE_PREFIX_PATH=$depsDirs \
158 -D MINGW_LINK_DIRECTORIES="$linkDirs" \
159 -D CMAKE_TOOLCHAIN_FILE="$MINGW_CMAKE_FILE" \
160 -D WITH_LIBCEPHSQLITE=OFF \
161 -D WITH_RDMA=OFF -D WITH_OPENLDAP=OFF \
162 -D WITH_GSSAPI=OFF -D WITH_XFS=OFF \
163 -D WITH_FUSE=OFF -D WITH_DOKAN=ON \
164 -D WITH_BLUESTORE=OFF -D WITH_LEVELDB=OFF \
165 -D WITH_LTTNG=OFF -D WITH_BABELTRACE=OFF \
166 -D WITH_SYSTEM_BOOST=ON -D WITH_MGR=OFF -D WITH_KVS=OFF \
167 -D WITH_LIBCEPHFS=ON -D WITH_KRBD=OFF -D WITH_RADOSGW=OFF \
168 -D ENABLE_SHARED=$ENABLE_SHARED -D WITH_RBD=ON -D BUILD_GMOCK=ON \
169 -D WITH_CEPHFS=OFF -D WITH_MANPAGE=OFF \
170 -D WITH_MGR_DASHBOARD_FRONTEND=OFF -D WITH_SYSTEMD=OFF -D WITH_TESTS=ON \
171 -D LZ4_INCLUDE_DIR=$lz4Include -D LZ4_LIBRARY=$lz4Lib \
172 -D Backtrace_INCLUDE_DIR="$backtraceDir/include" \
173 -D Backtrace_LIBRARY="$backtraceDir/lib/libbacktrace.a" \
174 -D ENABLE_GIT_VERSION=$ENABLE_GIT_VERSION \
175 -D ALLOCATOR="$ALLOCATOR" -D CMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE \
176 -D WNBD_INCLUDE_DIRS="$wnbdSrcDir/include" \
177 -D WNBD_LIBRARIES="$wnbdLibDir/libwnbd.a" \
178 -D WITH_CEPH_DEBUG_MUTEX=$WITH_CEPH_DEBUG_MUTEX \
179 -D DOKAN_INCLUDE_DIRS="$dokanSrcDir/dokan" \
180 -D DOKAN_LIBRARIES="$dokanLibDir/libdokan.a" \
181 -G "$cmakeGenerator" \
182 $CEPH_DIR 2>&1 | tee "${BUILD_DIR}/cmake.log"
183 fi # [[ -z $SKIP_CMAKE ]]
184
185 if [[ -z $SKIP_BUILD ]]; then
186 echo "Building using $NUM_WORKERS workers. Log: ${BUILD_DIR}/build.log"
187 echo "" > "${BUILD_DIR}/build.log"
188
189 cd $BUILD_DIR
190 ninja_targets="rados rbd rbd-wnbd "
191 ninja_targets+=" ceph-conf ceph-immutable-object-cache"
192 ninja_targets+=" cephfs ceph-dokan"
193 # TODO: do we actually need the ceph compression libs?
194 ninja_targets+=" compressor ceph_lz4 ceph_snappy ceph_zlib ceph_zstd"
195 if [[ -z $SKIP_TESTS ]]; then
196 ninja_targets+=" tests ceph_radosacl ceph_scratchtool"
197 fi
198
199 ninja -v $ninja_targets 2>&1 | tee "${BUILD_DIR}/build.log"
200 fi
201
202 if [[ -z $SKIP_DLL_COPY ]]; then
203 # To adjust mingw paths, see 'mingw_conf.sh'.
204 required_dlls=(
205 $zlibDir/zlib1.dll
206 $lz4Dir/lib/dll/liblz4-1.dll
207 $sslDir/bin/libcrypto-1_1-x64.dll
208 $sslDir/bin/libssl-1_1-x64.dll
209 $mingwTargetLibDir/libstdc++-6.dll
210 $mingwTargetLibDir/libgcc_s_seh-1.dll
211 $mingwLibpthreadDir/libwinpthread-1.dll
212 $boostDir/lib/*.dll)
213 echo "Copying required dlls to $binDir."
214 cp ${required_dlls[@]} $binDir
215 fi
216
217 if [[ -z $SKIP_ZIP ]]; then
218 # Use a temp directory, in order to create a clean zip file
219 ZIP_TMPDIR=$(mktemp -d win_binaries.XXXXX)
220 if [[ -z $EMBEDDED_DBG_SYM ]]; then
221 echo "Extracting debug symbols from binaries."
222 rm -rf $strippedBinDir; mkdir $strippedBinDir
223 rm -rf $dbgSymbolDir; mkdir $dbgSymbolDir
224 # Strip files individually, to save time and space
225 for file in $binDir/*.exe $binDir/*.dll; do
226 dbgFilename=$(basename $file).debug
227 dbgFile="$dbgSymbolDir/$dbgFilename"
228 strippedFile="$strippedBinDir/$(basename $file)"
229
230 echo "Copying debug symbols: $dbgFile"
231 $MINGW_OBJCOPY --only-keep-debug $file $dbgFile
232 $MINGW_STRIP --strip-debug --strip-unneeded -o $strippedFile $file
233 $MINGW_OBJCOPY --remove-section .gnu_debuglink $strippedFile
234 $MINGW_OBJCOPY --add-gnu-debuglink=$dbgFile $strippedFile
235 done
236 # Copy any remaining files to the stripped directory
237 for file in $binDir/*; do
238 [[ ! -f $strippedBinDir/$(basename $file) ]] && \
239 cp $file $strippedBinDir
240 done
241 ln -s $strippedBinDir $ZIP_TMPDIR/ceph
242 else
243 ln -s $binDir $ZIP_TMPDIR/ceph
244 fi
245 echo "Building zip archive $ZIP_DEST."
246 # Include the README file in the archive
247 ln -s $CEPH_DIR/README.windows.rst $ZIP_TMPDIR/ceph/README.windows.rst
248 cd $ZIP_TMPDIR
249 [[ -f $ZIP_DEST ]] && rm $ZIP_DEST
250 zip -r $ZIP_DEST ceph
251 cd -
252 rm -rf $ZIP_TMPDIR/ceph/README.windows.rst $ZIP_TMPDIR
253 echo -e '\n WIN32 files zipped to: '$ZIP_DEST'\n'
254 fi