Skip to content

Add find-ccache.sh with find_ccache_and_export_vars #1524

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
merged 15 commits into from
Aug 16, 2024
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
7 changes: 3 additions & 4 deletions .evergreen/generated_configs/legacy-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1861,10 +1861,9 @@ tasks:
export distro_id='${distro_id}' # Required by find_cmake_latest.
. .evergreen/scripts/find-cmake-latest.sh
cmake_binary="$(find_cmake_latest)"
# Allow reuse of ccache compilation results between different build directories.
export CCACHE_BASEDIR CCACHE_NOHASHDIR
CCACHE_BASEDIR="$(pwd)"
CCACHE_NOHASHDIR=1
# Use ccache if able.
. .evergreen/scripts/find-ccache.sh
find_ccache_and_export_vars "$(pwd)" || true
# Compile test-awsauth. Disable unnecessary dependencies since test-awsauth is copied to a remote Ubuntu 20.04 ECS cluster for testing, which may not have all dependent libraries.
export CC='${CC}'
"$cmake_binary" -DENABLE_TRACING=ON -DENABLE_SASL=OFF -DENABLE_SNAPPY=OFF -DENABLE_ZSTD=OFF -DENABLE_CLIENT_SIDE_ENCRYPTION=OFF .
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -930,10 +930,9 @@ def do_is_valid_combination(self) -> bool:
. .evergreen/scripts/find-cmake-latest.sh
cmake_binary="$(find_cmake_latest)"

# Allow reuse of ccache compilation results between different build directories.
export CCACHE_BASEDIR CCACHE_NOHASHDIR
CCACHE_BASEDIR="$(pwd)"
CCACHE_NOHASHDIR=1
# Use ccache if able.
. .evergreen/scripts/find-ccache.sh
find_ccache_and_export_vars "$(pwd)" || true

# Compile test-awsauth. Disable unnecessary dependencies since test-awsauth is copied to a remote Ubuntu 20.04 ECS cluster for testing, which may not have all dependent libraries.
export CC='${CC}'
Expand Down
7 changes: 3 additions & 4 deletions .evergreen/scripts/compile-openssl-static.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,9 @@ if [[ "${OSTYPE}" == darwin* ]]; then
}
fi

# Allow reuse of ccache compilation results between different build directories.
export CCACHE_BASEDIR CCACHE_NOHASHDIR
CCACHE_BASEDIR="$(pwd)"
CCACHE_NOHASHDIR=1
# Use ccache if able.
. "${script_dir:?}/find-ccache.sh"
find_ccache_and_export_vars "$(pwd)" || true

"${CMAKE}" "${configure_flags[@]}" .
"${CMAKE}" --build . -- -j "$(nproc)"
7 changes: 3 additions & 4 deletions .evergreen/scripts/compile-scan-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,9 @@ for dir in "${scan_build_directories[@]}"; do
done
: "${scan_build_binary:?"could not find a scan-build binary!"}"

# Allow reuse of ccache compilation results between different build directories.
export CCACHE_BASEDIR CCACHE_NOHASHDIR
CCACHE_BASEDIR="$(pwd)"
CCACHE_NOHASHDIR=1
# Use ccache if able.
. "${script_dir:?}/find-ccache.sh"
find_ccache_and_export_vars "$(pwd)" || true

"${scan_build_binary}" --use-cc="${CC}" --use-c++="${CXX}" "${cmake_binary}" "${configure_flags[@]}" .

Expand Down
7 changes: 3 additions & 4 deletions .evergreen/scripts/compile-std.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,9 @@ echo "Installing libmongocrypt... done."
echo "CFLAGS: ${CFLAGS}"
echo "configure_flags: ${configure_flags[*]}"

# Allow reuse of ccache compilation results between different build directories.
export CCACHE_BASEDIR CCACHE_NOHASHDIR
CCACHE_BASEDIR="$(pwd)"
CCACHE_NOHASHDIR=1
# Use ccache if able.
. "${script_dir:?}/find-ccache.sh"
find_ccache_and_export_vars "$(pwd)" || true

"${cmake_binary}" "${configure_flags[@]}" .
"${cmake_binary}" --build .
7 changes: 3 additions & 4 deletions .evergreen/scripts/compile-test-azurekms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ echo "Installing libmongocrypt ... begin"
}
echo "Installing libmongocrypt ... end"

# Allow reuse of ccache compilation results between different build directories.
export CCACHE_BASEDIR CCACHE_NOHASHDIR
CCACHE_BASEDIR="$(pwd)"
CCACHE_NOHASHDIR=1
# Use ccache if able.
. .evergreen/scripts/find-ccache.sh
find_ccache_and_export_vars "$(pwd)" || true

echo "Compile test-azurekms ... begin"
# Disable unnecessary dependencies. test-azurekms is copied to a remote host for testing, which may not have all dependent libraries.
Expand Down
7 changes: 3 additions & 4 deletions .evergreen/scripts/compile-test-gcpkms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ echo "Installing libmongocrypt ... begin"
}
echo "Installing libmongocrypt ... end"

# Allow reuse of ccache compilation results between different build directories.
export CCACHE_BASEDIR CCACHE_NOHASHDIR
CCACHE_BASEDIR="$(pwd)"
CCACHE_NOHASHDIR=1
# Use ccache if able.
. .evergreen/scripts/find-ccache.sh
find_ccache_and_export_vars "$(pwd)" || true

echo "Compile test-gcpkms ... begin"
# Disable unnecessary dependencies. test-gcpkms is copied to a remote host for testing, which may not have all dependent libraries.
Expand Down
7 changes: 3 additions & 4 deletions .evergreen/scripts/compile-unix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,9 @@ else
configure_flags_append "-DENABLE_CLIENT_SIDE_ENCRYPTION=OFF"
fi

# Allow reuse of ccache compilation results between different build directories.
export CCACHE_BASEDIR CCACHE_NOHASHDIR
CCACHE_BASEDIR="$(pwd)"
CCACHE_NOHASHDIR=1
# Use ccache if able.
. "${script_dir:?}/find-ccache.sh"
find_ccache_and_export_vars "$(pwd)" || true

"${cmake_binary}" "${configure_flags[@]}" ${extra_configure_flags[@]+"${extra_configure_flags[@]}"} .
"${cmake_binary}" --build .
Expand Down
67 changes: 67 additions & 0 deletions .evergreen/scripts/find-ccache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env bash

find_ccache_check() {
: "${1:?}"

if command -v "${1:?}" >/dev/null; then
declare version
version="$("${1:?}" --version | head -n 1)"
echo "Found ${1:?}: ${version:-}" 1>&2
echo "${1:?}"
return 0
fi

return 1
}

# find_ccache
#
# Usage:
# find_ccache
# ccache_binary="$(find_ccache)"
# ccache_binary="$(find_ccache 2>/dev/null)"
#
# Return 0 (true) if a ccache binary is found.
# Return a non-zero (false) value otherwise.
#
# If successful, print the name of the ccache binary to stdout (pipe 1).
# Otherwise, no output is printed to stdout.
#
# Diagnostic messages may be printed to stderr (pipe 2). Redirect to /dev/null
# with `2>/dev/null` to silence these messages.
find_ccache() {
# Most distros provide ccache via system paths.
{
find_ccache_check ccache && return
} || true

# Some distros provide ccache via mongodbtoolchain.
{
find_ccache_check /opt/mongodbtoolchain/v4/bin/ccache && return
} || {
find_ccache_check /opt/mongodbtoolchain/v3/bin/ccache && return
} || true

# Could not find ccache.
echo "Could not find a ccache binary." 1>&2
return 1
}

# Find, export, and set ccache env vars in one command for convenience.
# Requires base_dir as first argument.
# Returns a non-zero (false) value if a ccache binary is not found.
# Redirects find_ccache's stderr to stdout to avoid output sync issues on EVG.
find_ccache_and_export_vars() {
declare base_dir
base_dir="${1:?"missing base_dir"}"

declare ccache_binary
ccache_binary="$(find_ccache)" 2>&1 || return

export CMAKE_C_COMPILER_LAUNCHER="${ccache_binary:?}"
export CMAKE_CXX_COMPILER_LAUNCHER="${ccache_binary:?}"

# Allow reuse of ccache compilation results between different build directories.
export CCACHE_BASEDIR="${base_dir:?}"
export CCACHE_NOHASHDIR=1
}
13 changes: 9 additions & 4 deletions .evergreen/scripts/install-uninstall-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ CMAKE=$(find_cmake_latest)
. $DIR/check-symlink.sh
SRCROOT=$(pwd)

# Use ccache if able.
. $DIR/find-ccache.sh
find_ccache_and_export_vars "$(pwd)" || true

SCRATCH_DIR=$(pwd)/.scratch
rm -rf "$SCRATCH_DIR"
mkdir -p "$SCRATCH_DIR"
Expand Down Expand Up @@ -48,10 +52,11 @@ else
BSON_ONLY_OPTION="-DENABLE_MONGOC=ON"
fi

# Allow reuse of ccache compilation results between different build directories.
export CCACHE_BASEDIR CCACHE_NOHASHDIR
CCACHE_BASEDIR="$SCRATCH_DIR"
CCACHE_NOHASHDIR=1
# Use ccache if able.
if [[ -f $DIR/find-ccache.sh ]]; then
. $DIR/find-ccache.sh
find_ccache_and_export_vars "$SCRATCH_DIR" || true
fi

$CMAKE -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX -DCMAKE_PREFIX_PATH=$INSTALL_DIR/lib/cmake $BSON_ONLY_OPTION "$SCRATCH_DIR"
$CMAKE --build .
Expand Down
9 changes: 5 additions & 4 deletions .evergreen/scripts/link-sample-program-bson.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ mkdir -p $INSTALL_DIR

cd $BUILD_DIR

# Allow reuse of ccache compilation results between different build directories.
export CCACHE_BASEDIR CCACHE_NOHASHDIR
CCACHE_BASEDIR="$SCRATCH_DIR"
CCACHE_NOHASHDIR=1
# Use ccache if able.
if [[ -f $DIR/find-ccache.sh ]]; then
. $DIR/find-ccache.sh
find_ccache_and_export_vars "$SCRATCH_DIR" || true
fi

if [ "$LINK_STATIC" ]; then
# Our CMake system builds shared and static by default.
Expand Down
9 changes: 5 additions & 4 deletions .evergreen/scripts/link-sample-program.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ fi

ZSTD="AUTO"

# Allow reuse of ccache compilation results between different build directories.
export CCACHE_BASEDIR CCACHE_NOHASHDIR
CCACHE_BASEDIR="$SCRATCH_DIR"
CCACHE_NOHASHDIR=1
# Use ccache if able.
if [[ -f $DIR/find-ccache.sh ]]; then
. $DIR/find-ccache.sh
find_ccache_and_export_vars "$SCRATCH_DIR" || true
fi

$CMAKE -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DCMAKE_PREFIX_PATH=$INSTALL_DIR/lib/cmake $SSL_CMAKE_OPTION $SNAPPY_CMAKE_OPTION $STATIC_CMAKE_OPTION -DENABLE_ZSTD=$ZSTD "$SCRATCH_DIR"
$CMAKE --build . --parallel
Expand Down
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,6 @@ if(ENABLE_MAINTAINER_FLAGS)
)
endif()

# Enable CCache, if possible
include (CCache)

# Link with LLD, if possible
if (NOT MSVC)
include (LLDLinker)
Expand Down
8 changes: 7 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
libmongoc 1.28.0 (unreleased)
libmongoc 1.28.0 (Unreleased)
=============================

New features:
Expand All @@ -10,6 +10,12 @@ Notes:
* Bump minimum wire protocol version from 6 (MongoDB 3.6) to 7 (MongoDB 4.0).
* Raise required version of libmongocrypt to 1.11.0 to support In-Use Encryption (corresponds to the CMake option: `ENABLE_CLIENT_SIDE_ENCRYPTION`).

Build Configuration:

* Remove automatic ccache detection and usage (CCache.cmake).
* Set [`CMAKE_<LANG>_COMPILER_LAUNCHER`](https://cmake.org/cmake/help/latest/envvar/CMAKE_LANG_COMPILER_LAUNCHER.html) to build with ccache.
* Remove `MONGO_USE_CCACHE` (no longer applicable; see above).

Changed:

* Test and example targets are excluded from the `ALL` target.
Expand Down
44 changes: 0 additions & 44 deletions build/cmake/CCache.cmake

This file was deleted.

10 changes: 10 additions & 0 deletions src/libbson/NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
libbson 1.28.0 (Unreleased)
=============================

Build Configuration:

* Remove automatic ccache detection and usage (CCache.cmake).
* Set [`CMAKE_<LANG>_COMPILER_LAUNCHER`](https://cmake.org/cmake/help/latest/envvar/CMAKE_LANG_COMPILER_LAUNCHER.html) to build with ccache.
* Remove `MONGO_USE_CCACHE` (no longer applicable; see above).


libbson 1.27.5
==============

Expand Down