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