Skip to content

Commit 35f3880

Browse files
authored
Add find-ccache.sh with find_ccache_and_export_vars (#1524)
* Remove ccache 3.4.3 detection * Remove CCache.cmake * Add find-ccache.sh * Use find-ccache.sh in EVG config * Fix typo in documentation * Update NEWS files with removal of CCache.cmake * Include build configuration notes in libbson as well * Use find-ccache.sh in install-uninstall-check.sh * Remove exclusion of Windows in comment
1 parent 50761e8 commit 35f3880

File tree

16 files changed

+127
-92
lines changed

16 files changed

+127
-92
lines changed

.evergreen/generated_configs/legacy-config.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,10 +1861,9 @@ tasks:
18611861
export distro_id='${distro_id}' # Required by find_cmake_latest.
18621862
. .evergreen/scripts/find-cmake-latest.sh
18631863
cmake_binary="$(find_cmake_latest)"
1864-
# Allow reuse of ccache compilation results between different build directories.
1865-
export CCACHE_BASEDIR CCACHE_NOHASHDIR
1866-
CCACHE_BASEDIR="$(pwd)"
1867-
CCACHE_NOHASHDIR=1
1864+
# Use ccache if able.
1865+
. .evergreen/scripts/find-ccache.sh
1866+
find_ccache_and_export_vars "$(pwd)" || true
18681867
# 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.
18691868
export CC='${CC}'
18701869
"$cmake_binary" -DENABLE_TRACING=ON -DENABLE_SASL=OFF -DENABLE_SNAPPY=OFF -DENABLE_ZSTD=OFF -DENABLE_CLIENT_SIDE_ENCRYPTION=OFF .

.evergreen/legacy_config_generator/evergreen_config_lib/tasks.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -930,10 +930,9 @@ def do_is_valid_combination(self) -> bool:
930930
. .evergreen/scripts/find-cmake-latest.sh
931931
cmake_binary="$(find_cmake_latest)"
932932
933-
# Allow reuse of ccache compilation results between different build directories.
934-
export CCACHE_BASEDIR CCACHE_NOHASHDIR
935-
CCACHE_BASEDIR="$(pwd)"
936-
CCACHE_NOHASHDIR=1
933+
# Use ccache if able.
934+
. .evergreen/scripts/find-ccache.sh
935+
find_ccache_and_export_vars "$(pwd)" || true
937936
938937
# 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.
939938
export CC='${CC}'

.evergreen/scripts/compile-openssl-static.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,9 @@ if [[ "${OSTYPE}" == darwin* ]]; then
109109
}
110110
fi
111111

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

117116
"${CMAKE}" "${configure_flags[@]}" .
118117
"${CMAKE}" --build . -- -j "$(nproc)"

.evergreen/scripts/compile-scan-build.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,9 @@ for dir in "${scan_build_directories[@]}"; do
148148
done
149149
: "${scan_build_binary:?"could not find a scan-build binary!"}"
150150

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

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

.evergreen/scripts/compile-std.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,9 @@ echo "Installing libmongocrypt... done."
134134
echo "CFLAGS: ${CFLAGS}"
135135
echo "configure_flags: ${configure_flags[*]}"
136136

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

142141
"${cmake_binary}" "${configure_flags[@]}" .
143142
"${cmake_binary}" --build .

.evergreen/scripts/compile-test-azurekms.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ echo "Installing libmongocrypt ... begin"
1616
}
1717
echo "Installing libmongocrypt ... end"
1818

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

2423
echo "Compile test-azurekms ... begin"
2524
# Disable unnecessary dependencies. test-azurekms is copied to a remote host for testing, which may not have all dependent libraries.

.evergreen/scripts/compile-test-gcpkms.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ echo "Installing libmongocrypt ... begin"
1616
}
1717
echo "Installing libmongocrypt ... end"
1818

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

2423
echo "Compile test-gcpkms ... begin"
2524
# Disable unnecessary dependencies. test-gcpkms is copied to a remote host for testing, which may not have all dependent libraries.

.evergreen/scripts/compile-unix.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,9 @@ else
204204
configure_flags_append "-DENABLE_CLIENT_SIDE_ENCRYPTION=OFF"
205205
fi
206206

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

212211
"${cmake_binary}" "${configure_flags[@]}" ${extra_configure_flags[@]+"${extra_configure_flags[@]}"} .
213212
"${cmake_binary}" --build .

.evergreen/scripts/find-ccache.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env bash
2+
3+
find_ccache_check() {
4+
: "${1:?}"
5+
6+
if command -v "${1:?}" >/dev/null; then
7+
declare version
8+
version="$("${1:?}" --version | head -n 1)"
9+
echo "Found ${1:?}: ${version:-}" 1>&2
10+
echo "${1:?}"
11+
return 0
12+
fi
13+
14+
return 1
15+
}
16+
17+
# find_ccache
18+
#
19+
# Usage:
20+
# find_ccache
21+
# ccache_binary="$(find_ccache)"
22+
# ccache_binary="$(find_ccache 2>/dev/null)"
23+
#
24+
# Return 0 (true) if a ccache binary is found.
25+
# Return a non-zero (false) value otherwise.
26+
#
27+
# If successful, print the name of the ccache binary to stdout (pipe 1).
28+
# Otherwise, no output is printed to stdout.
29+
#
30+
# Diagnostic messages may be printed to stderr (pipe 2). Redirect to /dev/null
31+
# with `2>/dev/null` to silence these messages.
32+
find_ccache() {
33+
# Most distros provide ccache via system paths.
34+
{
35+
find_ccache_check ccache && return
36+
} || true
37+
38+
# Some distros provide ccache via mongodbtoolchain.
39+
{
40+
find_ccache_check /opt/mongodbtoolchain/v4/bin/ccache && return
41+
} || {
42+
find_ccache_check /opt/mongodbtoolchain/v3/bin/ccache && return
43+
} || true
44+
45+
# Could not find ccache.
46+
echo "Could not find a ccache binary." 1>&2
47+
return 1
48+
}
49+
50+
# Find, export, and set ccache env vars in one command for convenience.
51+
# Requires base_dir as first argument.
52+
# Returns a non-zero (false) value if a ccache binary is not found.
53+
# Redirects find_ccache's stderr to stdout to avoid output sync issues on EVG.
54+
find_ccache_and_export_vars() {
55+
declare base_dir
56+
base_dir="${1:?"missing base_dir"}"
57+
58+
declare ccache_binary
59+
ccache_binary="$(find_ccache)" 2>&1 || return
60+
61+
export CMAKE_C_COMPILER_LAUNCHER="${ccache_binary:?}"
62+
export CMAKE_CXX_COMPILER_LAUNCHER="${ccache_binary:?}"
63+
64+
# Allow reuse of ccache compilation results between different build directories.
65+
export CCACHE_BASEDIR="${base_dir:?}"
66+
export CCACHE_NOHASHDIR=1
67+
}

.evergreen/scripts/install-uninstall-check.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ CMAKE=$(find_cmake_latest)
1313
. $DIR/check-symlink.sh
1414
SRCROOT=$(pwd)
1515

16+
# Use ccache if able.
17+
. $DIR/find-ccache.sh
18+
find_ccache_and_export_vars "$(pwd)" || true
19+
1620
SCRATCH_DIR=$(pwd)/.scratch
1721
rm -rf "$SCRATCH_DIR"
1822
mkdir -p "$SCRATCH_DIR"
@@ -48,10 +52,11 @@ else
4852
BSON_ONLY_OPTION="-DENABLE_MONGOC=ON"
4953
fi
5054

51-
# Allow reuse of ccache compilation results between different build directories.
52-
export CCACHE_BASEDIR CCACHE_NOHASHDIR
53-
CCACHE_BASEDIR="$SCRATCH_DIR"
54-
CCACHE_NOHASHDIR=1
55+
# Use ccache if able.
56+
if [[ -f $DIR/find-ccache.sh ]]; then
57+
. $DIR/find-ccache.sh
58+
find_ccache_and_export_vars "$SCRATCH_DIR" || true
59+
fi
5560

5661
$CMAKE -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX -DCMAKE_PREFIX_PATH=$INSTALL_DIR/lib/cmake $BSON_ONLY_OPTION "$SCRATCH_DIR"
5762
$CMAKE --build .

.evergreen/scripts/link-sample-program-bson.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ mkdir -p $INSTALL_DIR
4444

4545
cd $BUILD_DIR
4646

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

5253
if [ "$LINK_STATIC" ]; then
5354
# Our CMake system builds shared and static by default.

.evergreen/scripts/link-sample-program.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,11 @@ fi
7272

7373
ZSTD="AUTO"
7474

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

8081
$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"
8182
$CMAKE --build . --parallel

CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,6 @@ if(ENABLE_MAINTAINER_FLAGS)
315315
)
316316
endif()
317317

318-
# Enable CCache, if possible
319-
include (CCache)
320-
321318
# Link with LLD, if possible
322319
if (NOT MSVC)
323320
include (LLDLinker)

NEWS

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
libmongoc 1.28.0 (unreleased)
1+
libmongoc 1.28.0 (Unreleased)
22
=============================
33

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

13+
Build Configuration:
14+
15+
* Remove automatic ccache detection and usage (CCache.cmake).
16+
* Set [`CMAKE_<LANG>_COMPILER_LAUNCHER`](https://cmake.org/cmake/help/latest/envvar/CMAKE_LANG_COMPILER_LAUNCHER.html) to build with ccache.
17+
* Remove `MONGO_USE_CCACHE` (no longer applicable; see above).
18+
1319
Changed:
1420

1521
* Test and example targets are excluded from the `ALL` target.

build/cmake/CCache.cmake

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/libbson/NEWS

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
libbson 1.28.0 (Unreleased)
2+
=============================
3+
4+
Build Configuration:
5+
6+
* Remove automatic ccache detection and usage (CCache.cmake).
7+
* Set [`CMAKE_<LANG>_COMPILER_LAUNCHER`](https://cmake.org/cmake/help/latest/envvar/CMAKE_LANG_COMPILER_LAUNCHER.html) to build with ccache.
8+
* Remove `MONGO_USE_CCACHE` (no longer applicable; see above).
9+
10+
111
libbson 1.27.5
212
==============
313

0 commit comments

Comments
 (0)