Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 59 additions & 69 deletions .evergreen/build_all.sh
Original file line number Diff line number Diff line change
@@ -1,91 +1,90 @@
#!/bin/bash
# Compiles libmongocrypt dependencies and targets.
#
# Set extra cflags for libmongocrypt variables by setting LIBMONGOCRYPT_EXTRA_CFLAGS.
#
# Set extra compilation for libmongocrypt variables by setting CFLAGS and CXXFLAGS.

echo "Begin compile process"

. "$(dirname "${BASH_SOURCE[0]}")/setup-env.sh"

# We may need some more C++ flags
_cxxflags=""
set -eu

: "${CONFIGURE_ONLY:=}"
: "${LIBMONGOCRYPT_BUILD_TYPE:=RelWithDebInfo}"

if [ "$OS_NAME" = "windows" ]; then
# Enable exception handling for MSVC
_cxxflags="-EHsc"
if is_false WINDOWS_32BIT && is_false USE_NINJA; then
# These options are only needed for VS CMake generators to force it to
# generate a 64-bit build. Default is 32-bit. Ninja inherits settings
# from the build environment variables.
ADDITIONAL_CMAKE_FLAGS="-Thost=x64 -A x64"
fi
fi
# Directory where build files will be stored
: "${BINARY_DIR:="$LIBMONGOCRYPT_DIR/cmake-build"}"
# Additional compilation flags that apply only to the libmongocrypt build
: "${LIBMONGOCRYPT_COMPILE_FLAGS:=}"

# Control the build configuration that is generated.
export CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE:-RelWithDebInfo}"
# Sets the default config for --build and CTest
export CMAKE_CONFIG_TYPE="$CMAKE_BUILD_TYPE"
# Control the install prefix
export CMAKE_INSTALL_PREFIX="${MONGOCRYPT_INSTALL_PREFIX-}"

# Have CTest print test failure info to stderr
export CTEST_OUTPUT_ON_FAILURE=1
# Generate a compilation database for use by other tools
export CMAKE_EXPORT_COMPILE_COMMANDS=1

# Accumulate arguments that are passed to CMake
cmake_args=(
--fresh
# Set the build type. CMake 3.22 recognizes this via environment variable
-D CMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}"
# Set the install prefix. CMake 3.29 recognizes this via environment variable
-D CMAKE_INSTALL_PREFIX="$CMAKE_INSTALL_PREFIX"
# Toggle compiling with shared BSON
-D USE_SHARED_LIBBSON="${USE_SHARED_LIBBSON-FALSE}"
# Toggle building of tests
-D BUILD_TESTING="${BUILD_TESTING-TRUE}"
# Enable additional warnings-as-errors
-D ENABLE_MORE_WARNINGS_AS_ERRORS=TRUE
)

: "${CONFIGURE_ONLY:=}"

if [ "$PPA_BUILD_ONLY" ]; then
# Clean-up from previous build iteration
rm -rf -- "$LIBMONGOCRYPT_DIR"/cmake-build* "$MONGOCRYPT_INSTALL_PREFIX"
ADDITIONAL_CMAKE_FLAGS="$ADDITIONAL_CMAKE_FLAGS -DENABLE_BUILD_FOR_PPA=ON"
fi

if [ "$MACOS_UNIVERSAL" = "ON" ]; then
ADDITIONAL_CMAKE_FLAGS="$ADDITIONAL_CMAKE_FLAGS -DCMAKE_OSX_ARCHITECTURES='arm64;x86_64'"
rm -rf -- "$LIBMONGOCRYPT_DIR"/cmake-build* "$CMAKE_INSTALL_PREFIX"
cmake_args+=(-DENABLE_BUILD_FOR_PPA=ON)
fi

for suffix in "dll" "dylib" "so"; do
cand="$(abspath "$LIBMONGOCRYPT_DIR/../mongocrypt_v1.$suffix")"
if test -f "$cand"; then
ADDITIONAL_CMAKE_FLAGS="$ADDITIONAL_CMAKE_FLAGS -DMONGOCRYPT_TESTING_CRYPT_SHARED_FILE=$cand"
cmake_args+=("-DMONGOCRYPT_TESTING_CRYPT_SHARED_FILE=$cand")
fi
done

ADDITIONAL_CMAKE_FLAGS="$ADDITIONAL_CMAKE_FLAGS -DENABLE_MORE_WARNINGS_AS_ERRORS=ON"

build_dir="$LIBMONGOCRYPT_DIR/cmake-build"
common_cmake_args=(
$ADDITIONAL_CMAKE_FLAGS
$LIBMONGOCRYPT_EXTRA_CMAKE_FLAGS
-DCMAKE_C_FLAGS="$LIBMONGOCRYPT_EXTRA_CFLAGS"
-DCMAKE_CXX_FLAGS="$LIBMONGOCRYPT_EXTRA_CFLAGS $_cxxflags"
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON
-DCMAKE_BUILD_TYPE="$LIBMONGOCRYPT_BUILD_TYPE"
-H"$LIBMONGOCRYPT_DIR"
-B"$build_dir"
)

if is_true USE_NINJA; then
if test "${CMAKE_GENERATOR-}" = Ninja; then
export NINJA_EXE
: "${NINJA_EXE:="$build_dir/ninja$EXE_SUFFIX"}"
common_cmake_args+=(
-GNinja
-DCMAKE_MAKE_PROGRAM="$NINJA_EXE"
)
: "${NINJA_EXE:="$BINARY_DIR/ninja$EXE_SUFFIX"}"
cmake_args+=(-DCMAKE_MAKE_PROGRAM="$NINJA_EXE")
bash "$EVG_DIR/ensure-ninja.sh"
fi

# A command that prepends our custom compile flags for any CMake execution
_cmake_with_env() {
# Prepend our custom C and CXX flags for any possible CMake builds
CFLAGS="$LIBMONGOCRYPT_COMPILE_FLAGS ${CFLAGS-}" \
CXXFLAGS="$LIBMONGOCRYPT_COMPILE_FLAGS ${CXXFLAGS-}" \
run_cmake "$@"
Comment on lines +68 to +71
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious: why prepend instead of append?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason at all, just how I happened to write it.

}

# Build and install libmongocrypt.
run_cmake \
-DCMAKE_INSTALL_PREFIX="$MONGOCRYPT_INSTALL_PREFIX" \
"${common_cmake_args[@]}"
_cmake_with_env "${cmake_args[@]}" \
-B "$BINARY_DIR" -S "$LIBMONGOCRYPT_DIR"

if [ "$CONFIGURE_ONLY" ]; then
echo "Only running cmake";
exit 0;
fi
echo "Installing libmongocrypt"
run_cmake --build "$build_dir" --target install --config "$LIBMONGOCRYPT_BUILD_TYPE"
run_cmake --build "$build_dir" --target test-mongocrypt --config "$LIBMONGOCRYPT_BUILD_TYPE"
run_cmake --build "$build_dir" --target test_kms_request --config "$LIBMONGOCRYPT_BUILD_TYPE"
run_chdir "$build_dir" run_ctest -C "$LIBMONGOCRYPT_BUILD_TYPE"
_cmake_with_env --build "$BINARY_DIR" --target install test-mongocrypt test_kms_request
run_chdir "$BINARY_DIR" run_ctest

# MONGOCRYPT-372, ensure macOS universal builds contain both x86_64 and arm64 architectures.
if [ "$MACOS_UNIVERSAL" = "ON" ]; then
if test "${CMAKE_OSX_ARCHITECTURES-}" != ''; then
echo "Checking if libmongocrypt.dylib contains both x86_64 and arm64 architectures..."
ARCHS=$(lipo -archs $MONGOCRYPT_INSTALL_PREFIX/lib/libmongocrypt.dylib)
if [[ "$ARCHS" == *"x86_64"* && "$ARCHS" == *"arm64"* ]]; then
Expand All @@ -101,27 +100,18 @@ if [ "$PPA_BUILD_ONLY" ]; then
exit 0;
fi

if "${DEFAULT_BUILD_ONLY:-false}"; then
echo "Skipping nocrypto+sharedbson builds"
exit 0
fi

# Build and install libmongocrypt with no native crypto.
run_cmake \
_cmake_with_env "${cmake_args[@]}" \
-DDISABLE_NATIVE_CRYPTO=ON \
-DCMAKE_INSTALL_PREFIX="$MONGOCRYPT_INSTALL_PREFIX/nocrypto" \
"${common_cmake_args[@]}"

run_cmake --build "$build_dir" --target install --config "$LIBMONGOCRYPT_BUILD_TYPE"
run_cmake --build "$build_dir" --target test-mongocrypt --config "$LIBMONGOCRYPT_BUILD_TYPE"
run_chdir "$build_dir" run_ctest -C "$LIBMONGOCRYPT_BUILD_TYPE"
-B "$BINARY_DIR" -S "$LIBMONGOCRYPT_DIR"
_cmake_with_env --build "$BINARY_DIR" --target install test-mongocrypt
run_chdir "$BINARY_DIR" run_ctest

# Build and install libmongocrypt without statically linking libbson
run_cmake \
-UDISABLE_NATIVE_CRYPTO \
_cmake_with_env "${cmake_args[@]}" \
-DUSE_SHARED_LIBBSON=ON \
-DCMAKE_INSTALL_PREFIX="$MONGOCRYPT_INSTALL_PREFIX/sharedbson" \
"${common_cmake_args[@]}"

run_cmake --build "$build_dir" --target install --config "$LIBMONGOCRYPT_BUILD_TYPE"
run_chdir "$build_dir" run_ctest -C "$LIBMONGOCRYPT_BUILD_TYPE"
-B "$BINARY_DIR" -S "$LIBMONGOCRYPT_DIR"
_cmake_with_env --build "$BINARY_DIR" --target install test-mongocrypt
run_chdir "$BINARY_DIR" run_ctest
32 changes: 21 additions & 11 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ functions:
export LSAN_OPTIONS="suppressions=$LIBMONGOCRYPT_DIR/.lsan-suppressions"
export VS_VERSION=${vs_version|}
export VS_TARGET_ARCH=${vs_target_arch|amd64}
export USE_NINJA=${use_ninja|ON}
export CMAKE_GENERATOR=${CMAKE_GENERATOR|Ninja}
env ${compile_env|} \
bash "$EVG_DIR/env-run.sh" \
bash "$EVG_DIR/build_all.sh"
Expand Down Expand Up @@ -151,7 +151,7 @@ functions:
- command: "shell.exec"
params:
script: |-
if test "$OS_NAME" != "windows"; then export USE_NINJA=${use_ninja|ON}; fi
if test "$OS_NAME" != "windows"; then export CMAKE_GENERATOR=${CMAKE_GENERATOR|Ninja}; fi
env ${compile_env|} CONFIGURE_ONLY=ON ${clang_env|CC=clang CXX=clang++} \
bash libmongocrypt/.evergreen/build_all.sh
./libmongocrypt/.evergreen/clang-tidy.sh
Expand Down Expand Up @@ -483,7 +483,9 @@ tasks:
- func: "fetch source"
- func: "build and test"
vars:
compile_env: ${compile_env|} LIBMONGOCRYPT_EXTRA_CMAKE_FLAGS="-DUSE_SHARED_LIBBSON=ON"
compile_env: >-
${compile_env|}
USE_SHARED_LIBBSON=true

- name: build-and-test-asan
commands:
Expand All @@ -493,7 +495,7 @@ tasks:
# Add detect_odr_violation=0 to ASAN_OPTIONS to ignore odr-violation in IntelDFP symbol: __dpml_bid_globals_table
compile_env: >-
${compile_env|}
LIBMONGOCRYPT_EXTRA_CFLAGS="-fsanitize=address -pthread"
LIBMONGOCRYPT_COMPILE_FLAGS="-fsanitize=address -pthread"
ASAN_OPTIONS="detect_leaks=1 detect_odr_violation=0"

- name: build-and-test-ubsan
Expand All @@ -503,17 +505,19 @@ tasks:
vars:
compile_env: >-
${compile_env|}
LIBMONGOCRYPT_EXTRA_CFLAGS="-fsanitize=undefined -fno-omit-frame-pointer"
LIBMONGOCRYPT_COMPILE_FLAGS="-fsanitize=undefined -fno-omit-frame-pointer"
UBSAN_OPTIONS="halt_on_error=1,print_stacktrace=1"


- name: build-and-test-asan-mac
commands:
- func: "fetch source"
- func: "build and test"
# Exclude leak detection. clang on macos-11-amd64 reports: "detect_leaks is not supported on this platform"
vars:
compile_env: ${compile_env|} LIBMONGOCRYPT_EXTRA_CFLAGS="-fsanitize=address"
compile_env: >-
${compile_env|}
LIBMONGOCRYPT_COMPILE_FLAGS="-fsanitize=address"

- name: test-python
depends_on:
Expand Down Expand Up @@ -1354,7 +1358,9 @@ buildvariants:
display_name: "RHEL 6.2 64-bit"
run_on: rhel62-small
expansions:
compile_env: CFLAGS="-D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS" ADDITIONAL_CMAKE_FLAGS="-DENABLE_TESTS=OFF -DBUILD_TESTING=OFF"
compile_env: >-
LIBMONGOCRYPT_COMPILE_FLAGS="-D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS"
BUILD_TESTING=OFF
tasks:
- build-and-test-and-upload
- build-and-test-shared-bson
Expand Down Expand Up @@ -1524,7 +1530,9 @@ buildvariants:
display_name: "Ubuntu 18.04 64-bit clang7"
run_on: ubuntu1804-test
expansions:
compile_env: LIBMONGOCRYPT_EXTRA_CMAKE_FLAGS="-DCMAKE_C_COMPILER=/opt/mongodbtoolchain/v3/bin/clang -DCMAKE_CXX_COMPILER=/opt/mongodbtoolchain/v3/bin/clang++"
compile_env: >-
CC=/opt/mongodbtoolchain/v3/bin/clang
CXX=/opt/mongodbtoolchain/v3/bin/clang++
tasks:
- build-and-test-and-upload
- name: ubuntu1804-arm64
Expand Down Expand Up @@ -1642,9 +1650,11 @@ buildvariants:
display_name: macOS m1 (Apple LLVM)
run_on: macos-1100-arm64
expansions:
compile_env: MACOS_UNIVERSAL=ON CMAKE=/opt/homebrew/bin/cmake
compile_env: >-
CMAKE_OSX_ARCHITECTURES="arm64;x86_64"
CMAKE=/opt/homebrew/bin/cmake
# Disable Ninja to work around error "Bad CPU type in executable"
use_ninja: OFF
CMAKE_GENERATOR: ''
tasks:
- build-and-test-and-upload
- name: test-python
Expand Down
4 changes: 3 additions & 1 deletion .evergreen/ensure-ninja.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ _build_ninja() {
tar -x -f "$src_tgz" -C "$extract_dir" --strip-components=1

log "Building Ninja from source"
run_chdir "$build_out_dir" run_python "$extract_dir/configure.py" --bootstrap
# Clear any CFLAGS or CXXFLAGS values from the parent environment, as Ninja doesn't handle them
# correctly.
CFLAGS="" CXXFLAGS="" run_chdir "$build_out_dir" run_python "$extract_dir/configure.py" --bootstrap
test -f "$expect_exe" || fail "Bootstrap did not generate the expected executable [$expect_exe]"

# Recursive invocation will find our build and copy it
Expand Down
27 changes: 5 additions & 22 deletions .evergreen/linker-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,19 @@ echo "Make libbson1 ..."
run_chdir "$linker_tests_root" bash "$EVG_DIR/prep_c_driver_source.sh"
MONGOC_DIR="$linker_tests_root/mongo-c-driver"

if test "$OS_NAME" = "windows" && is_false WINDOWS_32BIT && is_false USE_NINJA; then
# These options are only needed for VS CMake generators to force it to
# generate a 64-bit build. Default is 32-bit. Ninja inherits settings
# from the build environment variables.
ADDITIONAL_CMAKE_FLAGS="-Thost=x64 -A x64"
fi

if [ "${MACOS_UNIVERSAL-}" = "ON" ]; then
ADDITIONAL_CMAKE_FLAGS="$ADDITIONAL_CMAKE_FLAGS -DCMAKE_OSX_ARCHITECTURES='arm64;x86_64'"
fi

# Disable extra alignment in libbson and libmongocrypt to ensure agreement.
# libmongocrypt disables by default, but may enable if a system install of libbson is detected with extra alignment.
common_cmake_args=(
$ADDITIONAL_CMAKE_FLAGS
-DENABLE_EXTRA_ALIGNMENT=OFF
-DCMAKE_BUILD_TYPE=RelWithDebInfo
# Toggle building of tests
-D BUILD_TESTING="${BUILD_TESTING-TRUE}"
)

if is_true USE_NINJA; then
if test "${CMAKE_GENERATOR-}" = Ninja; then
export NINJA_EXE
: "${NINJA_EXE:="$linker_tests_root/ninja$EXE_SUFFIX"}"
common_cmake_args+=(
-GNinja
-DCMAKE_MAKE_PROGRAM="$NINJA_EXE"
)
common_cmake_args+=(-DCMAKE_MAKE_PROGRAM="$NINJA_EXE")
bash "$EVG_DIR/ensure-ninja.sh"
fi

Expand Down Expand Up @@ -111,11 +98,7 @@ run_cmake \
run_cmake --build "$BUILD_DIR" --target app --config RelWithDebInfo

export PATH="$PATH:$BSON1_INSTALL_PATH/bin:$LMC_INSTALL_PATH/bin"
if is_true IS_MULTICONF; then
APP_CMD="$BUILD_DIR/RelWithDebInfo/app.exe"
else
APP_CMD="$BUILD_DIR/app"
fi
APP_CMD="$BUILD_DIR/app"

check_output () {
output="$($APP_CMD)"
Expand Down
Loading