]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | #!/usr/bin/env bash |
2 | ||
3 | set -e | |
f67539c2 | 4 | set -o pipefail |
9f95a23c TL |
5 | |
6 | SCRIPT_DIR="$(dirname "$BASH_SOURCE")" | |
7 | SCRIPT_DIR="$(realpath "$SCRIPT_DIR")" | |
8 | ||
f67539c2 | 9 | num_vcpus=$(nproc) |
9f95a23c TL |
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}" | |
f67539c2 | 14 | ZIP_DEST="${ZIP_DEST:-$BUILD_DIR/ceph.zip}" |
9f95a23c TL |
15 | |
16 | CLEAN_BUILD=${CLEAN_BUILD:-} | |
17 | SKIP_BUILD=${SKIP_BUILD:-} | |
f67539c2 TL |
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} | |
9f95a23c | 26 | DEV_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. | |
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" | |
9f95a23c TL |
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. | |
f67539c2 TL |
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 | |
9f95a23c | 69 | |
f67539c2 TL |
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}" | |
9f95a23c TL |
79 | depsSrcDir="$DEPS_DIR/src" |
80 | depsToolsetDir="$DEPS_DIR/mingw" | |
81 | ||
f67539c2 | 82 | cmakeGenerator="Ninja" |
9f95a23c TL |
83 | lz4Dir="${depsToolsetDir}/lz4" |
84 | sslDir="${depsToolsetDir}/openssl" | |
85 | curlDir="${depsToolsetDir}/curl" | |
86 | boostDir="${depsToolsetDir}/boost" | |
87 | zlibDir="${depsToolsetDir}/zlib" | |
f67539c2 | 88 | backtraceDir="${depsToolsetDir}/libbacktrace" |
9f95a23c TL |
89 | snappyDir="${depsToolsetDir}/snappy" |
90 | winLibDir="${depsToolsetDir}/windows/lib" | |
f67539c2 TL |
91 | wnbdSrcDir="${depsSrcDir}/wnbd" |
92 | wnbdLibDir="${depsToolsetDir}/wnbd/lib" | |
93 | dokanSrcDir="${depsSrcDir}/dokany" | |
94 | dokanLibDir="${depsToolsetDir}/dokany/lib" | |
9f95a23c TL |
95 | |
96 | depsDirs="$lz4Dir;$curlDir;$sslDir;$boostDir;$zlibDir;$backtraceDir;$snappyDir" | |
97 | depsDirs+=";$winLibDir" | |
98 | ||
f67539c2 | 99 | lz4Lib="${lz4Dir}/lib/dll/liblz4-1.dll" |
9f95a23c TL |
100 | lz4Include="${lz4Dir}/lib" |
101 | curlLib="${curlDir}/lib/libcurl.dll.a" | |
102 | curlInclude="${curlDir}/include" | |
103 | ||
104 | if [[ -n $CLEAN_BUILD ]]; then | |
105 | echo "Cleaning up build dir: $BUILD_DIR" | |
106 | rm -rf $BUILD_DIR | |
f67539c2 TL |
107 | rm -rf $DEPS_DIR |
108 | fi | |
109 | if [[ -z $SKIP_BINDIR_CLEAN ]]; then | |
110 | echo "Cleaning up bin dir: $binDir" | |
111 | rm -rf $binDir | |
9f95a23c TL |
112 | fi |
113 | ||
f67539c2 | 114 | if [[ ! -f ${depsToolsetDir}/completed ]]; then |
9f95a23c | 115 | echo "Preparing dependencies: $DEPS_DIR" |
f67539c2 | 116 | NUM_WORKERS=$NUM_WORKERS DEPS_DIR=$DEPS_DIR OS="$OS"\ |
9f95a23c TL |
117 | "$SCRIPT_DIR/win32_deps_build.sh" |
118 | fi | |
119 | ||
120 | mkdir -p $BUILD_DIR | |
121 | cd $BUILD_DIR | |
122 | ||
f67539c2 TL |
123 | # Due to distribution specific mingw settings, the mingw.cmake file |
124 | # must be built prior to running cmake. | |
125 | MINGW_CMAKE_FILE="$BUILD_DIR/mingw32.cmake" | |
126 | MINGW_POSIX_FLAGS=1 | |
127 | source "$SCRIPT_DIR/mingw_conf.sh" | |
128 | ||
129 | if [[ -z $SKIP_CMAKE ]]; then | |
9f95a23c TL |
130 | # We'll need to cross compile Boost.Python before enabling |
131 | # "WITH_MGR". | |
132 | echo "Generating solution. Log: ${BUILD_DIR}/cmake.log" | |
133 | ||
134 | # This isn't propagated to some of the subprojects, we'll use an env variable | |
135 | # for now. | |
136 | export CMAKE_PREFIX_PATH=$depsDirs | |
137 | ||
138 | if [[ -n $DEV_BUILD ]]; then | |
139 | echo "Dev build enabled." | |
140 | echo "Git versioning will be disabled." | |
141 | ENABLE_GIT_VERSION="OFF" | |
f67539c2 | 142 | WITH_CEPH_DEBUG_MUTEX="ON" |
9f95a23c TL |
143 | else |
144 | ENABLE_GIT_VERSION="ON" | |
f67539c2 | 145 | WITH_CEPH_DEBUG_MUTEX="OFF" |
9f95a23c TL |
146 | fi |
147 | ||
148 | # As opposed to Linux, Windows shared libraries can't have unresolved | |
149 | # symbols. Until we fix the dependencies (which are either unspecified | |
150 | # or circular), we'll have to stick to static linking. | |
151 | cmake -D CMAKE_PREFIX_PATH=$depsDirs \ | |
f67539c2 | 152 | -D CMAKE_TOOLCHAIN_FILE="$MINGW_CMAKE_FILE" \ |
9f95a23c | 153 | -D WITH_RDMA=OFF -D WITH_OPENLDAP=OFF \ |
f67539c2 TL |
154 | -D WITH_GSSAPI=OFF -D WITH_XFS=OFF \ |
155 | -D WITH_FUSE=OFF -D WITH_DOKAN=ON \ | |
9f95a23c TL |
156 | -D WITH_BLUESTORE=OFF -D WITH_LEVELDB=OFF \ |
157 | -D WITH_LTTNG=OFF -D WITH_BABELTRACE=OFF \ | |
f67539c2 TL |
158 | -D WITH_SYSTEM_BOOST=ON -D WITH_MGR=OFF -D WITH_KVS=OFF \ |
159 | -D WITH_LIBCEPHFS=ON -D WITH_KRBD=OFF -D WITH_RADOSGW=OFF \ | |
160 | -D ENABLE_SHARED=$ENABLE_SHARED -D WITH_RBD=ON -D BUILD_GMOCK=ON \ | |
9f95a23c | 161 | -D WITH_CEPHFS=OFF -D WITH_MANPAGE=OFF \ |
f67539c2 | 162 | -D WITH_MGR_DASHBOARD_FRONTEND=OFF -D WITH_SYSTEMD=OFF -D WITH_TESTS=ON \ |
9f95a23c | 163 | -D LZ4_INCLUDE_DIR=$lz4Include -D LZ4_LIBRARY=$lz4Lib \ |
9f95a23c | 164 | -D Backtrace_INCLUDE_DIR="$backtraceDir/include" \ |
f67539c2 | 165 | -D Backtrace_LIBRARY="$backtraceDir/lib/libbacktrace.a" \ |
9f95a23c TL |
166 | -D ENABLE_GIT_VERSION=$ENABLE_GIT_VERSION \ |
167 | -D ALLOCATOR="$ALLOCATOR" -D CMAKE_BUILD_TYPE=$CMAKE_BUILD_TYPE \ | |
f67539c2 TL |
168 | -D WNBD_INCLUDE_DIRS="$wnbdSrcDir/include" \ |
169 | -D WNBD_LIBRARIES="$wnbdLibDir/libwnbd.a" \ | |
170 | -D WITH_CEPH_DEBUG_MUTEX=$WITH_CEPH_DEBUG_MUTEX \ | |
171 | -D DOKAN_INCLUDE_DIRS="$dokanSrcDir/dokan" \ | |
172 | -D DOKAN_LIBRARIES="$dokanLibDir/libdokan.a" \ | |
173 | -G "$cmakeGenerator" \ | |
9f95a23c | 174 | $CEPH_DIR 2>&1 | tee "${BUILD_DIR}/cmake.log" |
f67539c2 | 175 | fi # [[ -z $SKIP_CMAKE ]] |
9f95a23c TL |
176 | |
177 | if [[ -z $SKIP_BUILD ]]; then | |
178 | echo "Building using $NUM_WORKERS workers. Log: ${BUILD_DIR}/build.log" | |
f67539c2 TL |
179 | echo "" > "${BUILD_DIR}/build.log" |
180 | ||
181 | cd $BUILD_DIR | |
182 | ninja_targets="rados rbd rbd-wnbd " | |
183 | ninja_targets+=" ceph-conf ceph-immutable-object-cache" | |
184 | ninja_targets+=" cephfs ceph-dokan" | |
185 | # TODO: do we actually need the ceph compression libs? | |
186 | ninja_targets+=" compressor ceph_lz4 ceph_snappy ceph_zlib ceph_zstd" | |
187 | if [[ -z $SKIP_TESTS ]]; then | |
188 | ninja_targets+=" tests ceph_radosacl ceph_scratchtool" | |
189 | fi | |
9f95a23c | 190 | |
f67539c2 TL |
191 | ninja -v $ninja_targets 2>&1 | tee "${BUILD_DIR}/build.log" |
192 | fi | |
193 | ||
194 | if [[ -z $SKIP_DLL_COPY ]]; then | |
195 | # To adjust mingw paths, see 'mingw_conf.sh'. | |
196 | required_dlls=( | |
197 | $zlibDir/zlib1.dll | |
198 | $lz4Dir/lib/dll/liblz4-1.dll | |
199 | $sslDir/bin/libcrypto-1_1-x64.dll | |
200 | $sslDir/bin/libssl-1_1-x64.dll | |
201 | $mingwTargetLibDir/libstdc++-6.dll | |
202 | $mingwTargetLibDir/libgcc_s_seh-1.dll | |
203 | $mingwLibpthreadDir/libwinpthread-1.dll | |
204 | $boostDir/lib/*.dll) | |
205 | echo "Copying required dlls to $binDir." | |
206 | cp ${required_dlls[@]} $binDir | |
207 | fi | |
9f95a23c | 208 | |
f67539c2 TL |
209 | if [[ -z $SKIP_ZIP ]]; then |
210 | # Use a temp directory, in order to create a clean zip file | |
211 | ZIP_TMPDIR=$(mktemp -d win_binaries.XXXXX) | |
212 | if [[ -z $EMBEDDED_DBG_SYM ]]; then | |
213 | echo "Extracting debug symbols from binaries." | |
214 | rm -rf $strippedBinDir; mkdir $strippedBinDir | |
215 | rm -rf $dbgSymbolDir; mkdir $dbgSymbolDir | |
216 | # Strip files individually, to save time and space | |
217 | for file in $binDir/*.exe $binDir/*.dll; do | |
218 | dbgFilename=$(basename $file).debug | |
219 | dbgFile="$dbgSymbolDir/$dbgFilename" | |
220 | strippedFile="$strippedBinDir/$(basename $file)" | |
221 | ||
222 | echo "Copying debug symbols: $dbgFile" | |
223 | $MINGW_OBJCOPY --only-keep-debug $file $dbgFile | |
224 | $MINGW_STRIP --strip-debug --strip-unneeded -o $strippedFile $file | |
225 | $MINGW_OBJCOPY --remove-section .gnu_debuglink $strippedFile | |
226 | $MINGW_OBJCOPY --add-gnu-debuglink=$dbgFile $strippedFile | |
227 | done | |
228 | # Copy any remaining files to the stripped directory | |
229 | for file in $binDir/*; do | |
230 | [[ ! -f $strippedBinDir/$(basename $file) ]] && \ | |
231 | cp $file $strippedBinDir | |
232 | done | |
233 | ln -s $strippedBinDir $ZIP_TMPDIR/ceph | |
234 | else | |
235 | ln -s $binDir $ZIP_TMPDIR/ceph | |
9f95a23c | 236 | fi |
f67539c2 TL |
237 | echo "Building zip archive $ZIP_DEST." |
238 | # Include the README file in the archive | |
239 | ln -s $CEPH_DIR/README.windows.rst $ZIP_TMPDIR/ceph/README.windows.rst | |
240 | cd $ZIP_TMPDIR | |
241 | [[ -f $ZIP_DEST ]] && rm $ZIP_DEST | |
242 | zip -r $ZIP_DEST ceph | |
243 | cd - | |
244 | rm -rf $ZIP_TMPDIR/ceph/README.windows.rst $ZIP_TMPDIR | |
245 | echo -e '\n WIN32 files zipped to: '$ZIP_DEST'\n' | |
9f95a23c | 246 | fi |