-
Notifications
You must be signed in to change notification settings - Fork 99
[MONGOCRYPT-874] Refactor build scripts to use more standard environment variable controls for CMake #1110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
vector-of-bool
merged 17 commits into
mongodb:master
from
vector-of-bool:feature/env-refactor.2
Jan 23, 2026
Merged
[MONGOCRYPT-874] Refactor build scripts to use more standard environment variable controls for CMake #1110
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
14682f5
Drop irrelevant complications since we use Ninja on Windows
vector-of-bool fb16f91
Drop EXTRA_CFLAGS in favor of CFLAGS
vector-of-bool b0ae833
Use OSX architectures env var instead
vector-of-bool 9238191
Set OSX architectures env var in EVG config
vector-of-bool 4c1bd8f
Set the CMake generator by using an environment variable
vector-of-bool b3b3fef
More robust env handling in build_all.sh
vector-of-bool d009ba5
Use CC and CXX to set compilers
vector-of-bool 8927fc0
Drop LIBMONGOCRYPT_EXTRA_CMAKE_FLAGS
vector-of-bool 208c8f1
Drop ADDITIONAL_CMAKE_FLAGS
vector-of-bool 83deb0b
Misc cleanup, remove DEFAULT_BUILD_ONLY
vector-of-bool 98f47e1
[fixup] Subproject patch respects BUILD_TESTING
vector-of-bool 3bd5e7a
Start fresh with build_all.sh
vector-of-bool 8df7cc7
Don't set exception handling flags on Windows
vector-of-bool d0743af
Set CMake env for controlling parallelism, not Makeflags
vector-of-bool 500ec74
Fix incorrect var usage in build_all.sh
vector-of-bool bb7f577
Tweak our usage of CFLAGS to not interfere with incident builds
vector-of-bool 560c464
Pass -S and -B separately for each CMake invoke
vector-of-bool File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious: why prepend instead of append?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.