Skip to content

Commit 9c1514b

Browse files
committed
separate libmongocrypt evg script
1 parent 33edfc8 commit 9c1514b

File tree

3 files changed

+279
-3
lines changed

3 files changed

+279
-3
lines changed

.evergreen/compile.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ cmake_flags=(
102102
-DMONGOCXX_ENABLE_SLOW_TESTS=ON
103103
-DCMAKE_INSTALL_PREFIX=install
104104
-DENABLE_UNINSTALL=ON
105-
-DENABLE_CLIENT_SIDE_ENCRYPTION=ON
106105
)
107106

108107
_RUN_DISTCHECK=""
Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
#!/usr/bin/env bash
2+
3+
# Runs cmake and compiles the standard build targets (all, install, examples). Any arguments passed
4+
# to this script will be forwarded on as flags passed to cmake.
5+
#
6+
# This script should be run from the root of the repository. This script will run the build from
7+
# the default build directory './build'. The following environment variables will change the
8+
# behavior of this script:
9+
# - build_type: must be set to "Release" or "Debug"
10+
11+
set -o errexit
12+
set -o pipefail
13+
14+
: "${branch_name:?}"
15+
: "${build_type:?}"
16+
: "${distro_id:?}" # Required by find-cmake-latest.sh.
17+
18+
: "${COMPILE_MACRO_GUARD_TESTS:-}"
19+
: "${ENABLE_CODE_COVERAGE:-}"
20+
: "${ENABLE_TESTS:-}"
21+
: "${generator:-}"
22+
: "${platform:-}"
23+
: "${REQUIRED_CXX_STANDARD:-}"
24+
: "${RUN_DISTCHECK:-}"
25+
: "${USE_POLYFILL_BOOST:-}"
26+
: "${USE_SANITIZER_ASAN:-}"
27+
: "${USE_SANITIZER_UBSAN:-}"
28+
: "${USE_STATIC_LIBS:-}"
29+
30+
mongoc_prefix="$(pwd)/../mongoc"
31+
echo "mongoc_prefix=${mongoc_prefix:?}"
32+
33+
if [[ "${OSTYPE:?}" =~ cygwin ]]; then
34+
mongoc_prefix=$(cygpath -m "${mongoc_prefix:?}")
35+
fi
36+
37+
# shellcheck source=/dev/null
38+
. "${mongoc_prefix:?}/.evergreen/scripts/find-cmake-latest.sh"
39+
export cmake_binary
40+
cmake_binary="$(find_cmake_latest)"
41+
command -v "$cmake_binary"
42+
43+
if [ ! -d ../drivers-evergreen-tools ]; then
44+
git clone --depth 1 https://github.com/mongodb-labs/drivers-evergreen-tools.git ../drivers-evergreen-tools
45+
fi
46+
# shellcheck source=/dev/null
47+
. ../drivers-evergreen-tools/.evergreen/find-python3.sh
48+
# shellcheck source=/dev/null
49+
. ../drivers-evergreen-tools/.evergreen/venv-utils.sh
50+
51+
venvcreate "$(find_python3)" venv
52+
python -m pip install GitPython
53+
54+
if [[ "${build_type:?}" != "Debug" && "${build_type:?}" != "Release" ]]; then
55+
echo "$0: expected build_type environment variable to be set to 'Debug' or 'Release'" >&2
56+
exit 1
57+
fi
58+
59+
if [[ "${OSTYPE}" == darwin* ]]; then
60+
# MacOS does not have nproc.
61+
nproc() {
62+
sysctl -n hw.logicalcpu
63+
}
64+
fi
65+
CMAKE_BUILD_PARALLEL_LEVEL="$(nproc)"
66+
export CMAKE_BUILD_PARALLEL_LEVEL
67+
68+
# Use ccache if available.
69+
if [[ -f "${mongoc_prefix:?}/.evergreen/scripts/find-ccache.sh" ]]; then
70+
# shellcheck source=/dev/null
71+
. "${mongoc_prefix:?}/.evergreen/scripts/find-ccache.sh"
72+
find_ccache_and_export_vars "$(pwd)" || true
73+
fi
74+
75+
76+
build_targets=()
77+
cmake_build_opts=()
78+
case "${OSTYPE:?}" in
79+
cygwin)
80+
cmake_build_opts+=("/verbosity:minimal")
81+
build_targets+=(--target ALL_BUILD --target examples/examples)
82+
;;
83+
84+
darwin* | linux*)
85+
build_targets+=(--target all --target examples)
86+
;;
87+
88+
*)
89+
echo "unrecognized operating system ${OSTYPE:?}" 1>&2
90+
exit 1
91+
;;
92+
esac
93+
94+
# Create a VERSION_CURRENT file in the build directory to include in the dist tarball.
95+
python ./etc/calc_release_version.py >./build/VERSION_CURRENT
96+
cd build
97+
98+
cmake_flags=(
99+
"-DCMAKE_BUILD_TYPE=${build_type:?}"
100+
"-DCMAKE_PREFIX_PATH=${mongoc_prefix:?}"
101+
-DBUILD_TESTING=ON
102+
-DMONGOCXX_ENABLE_SLOW_TESTS=ON
103+
-DCMAKE_INSTALL_PREFIX=install
104+
-DENABLE_UNINSTALL=ON
105+
-DENABLE_CLIENT_SIDE_ENCRYPTION=ON
106+
)
107+
108+
_RUN_DISTCHECK=""
109+
case "${OSTYPE:?}" in
110+
cygwin)
111+
case "${generator:-}" in
112+
*2015*) cmake_flags+=("-DBOOST_ROOT=C:/local/boost_1_60_0") ;;
113+
*2017* | *2019*) cmake_flags+=("-DCMAKE_CXX_STANDARD=17") ;;
114+
*)
115+
echo "missing explicit CMake Generator on Windows distro" 1>&2
116+
exit 1
117+
;;
118+
esac
119+
;;
120+
darwin* | linux*)
121+
: "${generator:="Unix Makefiles"}"
122+
123+
# If enabled, limit distcheck to Unix-like systems only.
124+
_RUN_DISTCHECK="${RUN_DISTCHECK:-}"
125+
;;
126+
*)
127+
echo "unrecognized operating system ${OSTYPE:?}" 1>&2
128+
exit 1
129+
;;
130+
esac
131+
export CMAKE_GENERATOR="${generator:?}"
132+
export CMAKE_GENERATOR_PLATFORM="${platform:-}"
133+
134+
if [[ "${USE_POLYFILL_BOOST:-}" == "ON" ]]; then
135+
cmake_flags+=("-DBSONCXX_POLY_USE_BOOST=ON")
136+
fi
137+
138+
cc_flags_init=(-Wall -Wextra -Wno-attributes -Werror -Wno-missing-field-initializers)
139+
cxx_flags_init=(-Wall -Wextra -Wconversion -Wnarrowing -pedantic -Werror)
140+
cc_flags=()
141+
cxx_flags=()
142+
143+
case "${OSTYPE:?}" in
144+
cygwin)
145+
# Most compiler flags are not applicable to builds on Windows distros.
146+
;;
147+
darwin*)
148+
cc_flags+=("${cc_flags_init[@]}")
149+
cxx_flags+=("${cxx_flags_init[@]}" -stdlib=libc++)
150+
;;
151+
linux*)
152+
cc_flags+=("${cc_flags_init[@]}")
153+
cxx_flags+=("${cxx_flags_init[@]}" -Wno-missing-field-initializers)
154+
155+
if [[ "${distro_id:?}" != rhel7* ]]; then
156+
cxx_flags+=("-Wno-expansion-to-defined")
157+
else
158+
cxx_flags+=("-Wno-unused-parameter") # TODO: remove once C driver is upgraded to include fix of CDRIVER-5673.
159+
fi
160+
161+
if [[ "${distro_id:?}" == debian12* ]]; then
162+
cxx_flags+=("-Wno-error=restrict")
163+
fi
164+
;;
165+
*)
166+
echo "unrecognized operating system ${OSTYPE:?}" 1>&2
167+
exit 1
168+
;;
169+
esac
170+
171+
# Most compiler flags are not applicable to builds on Windows distros.
172+
if [[ "${OSTYPE:?}" != cygwin ]]; then
173+
# Sanitizers overwrite the usual compiler flags.
174+
if [[ "${USE_SANITIZER_ASAN:-}" == "ON" ]]; then
175+
cxx_flags=(
176+
"${cxx_flags_init[@]}"
177+
-D_GLIBCXX_USE_CXX11_ABI=0
178+
-fsanitize=address
179+
-O1 -g -fno-omit-frame-pointer
180+
)
181+
fi
182+
183+
# Sanitizers overwrite the usual compiler flags.
184+
if [[ "${USE_SANITIZER_UBSAN:-}" == "ON" ]]; then
185+
cxx_flags=(
186+
"${cxx_flags_init[@]}"
187+
-D_GLIBCXX_USE_CXX11_ABI=0
188+
-fsanitize=undefined
189+
-fsanitize-blacklist="$(pwd)/../etc/ubsan.ignorelist"
190+
-fno-sanitize-recover=undefined
191+
-O1 -g -fno-omit-frame-pointer
192+
)
193+
fi
194+
195+
# Ignore warnings generated by core::optional in mnmlstc/core.
196+
if [[ "${OSTYPE:?}" == linux* && "${HOSTTYPE:?}" == powerpc64le ]]; then
197+
cxx_flags+=(-Wno-error=maybe-uninitialized)
198+
fi
199+
200+
# Ignore deprecation warnings when building on a release branch.
201+
if [[ "$(echo "${branch_name:?}" | cut -f2 -d'/')" != "${branch_name:?}" ]]; then
202+
cc_flags+=(-Wno-deprecated-declarations)
203+
cxx_flags+=(-Wno-deprecated-declarations)
204+
fi
205+
fi
206+
207+
if [[ "${#cc_flags[@]}" -gt 0 ]]; then
208+
cmake_flags+=("-DCMAKE_C_FLAGS=${cc_flags[*]}")
209+
fi
210+
211+
if [[ "${#cxx_flags[@]}" -gt 0 ]]; then
212+
cmake_flags+=("-DCMAKE_CXX_FLAGS=${cxx_flags[*]}")
213+
fi
214+
215+
if [[ "${ENABLE_CODE_COVERAGE:-}" == "ON" ]]; then
216+
cmake_flags+=("-DENABLE_CODE_COVERAGE=ON")
217+
fi
218+
219+
if [ "${USE_STATIC_LIBS:-}" ]; then
220+
cmake_flags+=("-DBUILD_SHARED_LIBS=OFF")
221+
fi
222+
223+
if [ "${ENABLE_TESTS:-}" = "OFF" ]; then
224+
cmake_flags+=("-DENABLE_TESTS=OFF")
225+
fi
226+
227+
if [[ -n "${REQUIRED_CXX_STANDARD:-}" ]]; then
228+
cmake_flags+=("-DCMAKE_CXX_STANDARD=${REQUIRED_CXX_STANDARD:?}")
229+
cmake_flags+=("-DCMAKE_CXX_STANDARD_REQUIRED=ON")
230+
fi
231+
232+
if [[ "${COMPILE_MACRO_GUARD_TESTS:-"OFF"}" == "ON" ]]; then
233+
cmake_flags+=("-DENABLE_MACRO_GUARD_TESTS=ON")
234+
fi
235+
236+
echo "Configuring with CMake flags: ${cmake_flags[*]}"
237+
238+
"${cmake_binary}" "${cmake_flags[@]}" ..
239+
240+
if [[ "${COMPILE_MACRO_GUARD_TESTS:-"OFF"}" == "ON" ]]; then
241+
# We only need to compile the macro guard tests.
242+
"${cmake_binary}" --build . --config "${build_type:?}" --target test_bsoncxx_macro_guards test_mongocxx_macro_guards -- "${cmake_build_opts[@]}"
243+
exit # Nothing else to be done.
244+
fi
245+
246+
# Regular build and install routine.
247+
"${cmake_binary}" --build . --config "${build_type:?}" "${build_targets[@]:?}" -- "${cmake_build_opts[@]}"
248+
"${cmake_binary}" --install . --config "${build_type:?}"
249+
250+
if [[ "${_RUN_DISTCHECK:-}" ]]; then
251+
"${cmake_binary}" --build . --config "${build_type:?}" --target distcheck
252+
fi

.mci.yml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,31 @@ functions:
478478
CXX: ${cxx_compiler}
479479
script: .evergreen/compile.sh
480480

481+
"compile_with_libmongocrypt":
482+
- command: shell.exec
483+
params:
484+
shell: bash
485+
working_dir: "mongo-cxx-driver"
486+
include_expansions_in_env:
487+
- branch_name
488+
- build_type
489+
- COMPILE_MACRO_GUARD_TESTS
490+
- distro_id
491+
- ENABLE_CODE_COVERAGE
492+
- ENABLE_TESTS
493+
- generator
494+
- platform
495+
- REQUIRED_CXX_STANDARD
496+
- RUN_DISTCHECK
497+
- USE_POLYFILL_BOOST
498+
- USE_SANITIZER_ASAN
499+
- USE_SANITIZER_UBSAN
500+
- USE_STATIC_LIBS
501+
env:
502+
CC: ${cc_compiler}
503+
CXX: ${cxx_compiler}
504+
script: .evergreen/compile_with_libmongocrypt.sh
505+
481506
"compile_benchmarks":
482507
- command: shell.exec
483508
type: setup
@@ -972,7 +997,7 @@ tasks:
972997
vars:
973998
TOPOLOGY: "replica_set"
974999
- func: "install_c_driver"
975-
- func: "compile"
1000+
- func: "compile_with_libmongocrypt"
9761001
vars:
9771002
RUN_DISTCHECK: 1
9781003
- func: "clone_drivers-evergreen-tools"
@@ -988,7 +1013,7 @@ tasks:
9881013
vars:
9891014
TOPOLOGY: "sharded_cluster"
9901015
- func: "install_c_driver"
991-
- func: "compile"
1016+
- func: "compile_with_libmongocrypt"
9921017
vars:
9931018
RUN_DISTCHECK: 1
9941019
- func: "clone_drivers-evergreen-tools"

0 commit comments

Comments
 (0)