Skip to content

Commit e58dfa6

Browse files
authored
Allow ccache to reuse results across build directories (#1087)
1 parent f9f48a1 commit e58dfa6

File tree

4 files changed

+45
-13
lines changed

4 files changed

+45
-13
lines changed

.evergreen/abi-stability-setup.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,14 @@ else
5656
fi
5757

5858
# Use ccache if available.
59-
if command -V ccache; then
60-
export CMAKE_C_COMPILER_LAUNCHER CMAKE_CXX_COMPILER_LAUNCHER
61-
CMAKE_C_COMPILER_LAUNCHER="ccache"
62-
CMAKE_CXX_COMPILER_LAUNCHER="ccache"
59+
if command -V ccache 2>/dev/null; then
60+
export CMAKE_C_COMPILER_LAUNCHER=ccache
61+
export CMAKE_CXX_COMPILER_LAUNCHER=ccache
62+
63+
# Allow reuse of ccache compilation results between different build directories.
64+
export CCACHE_BASEDIR CCACHE_NOHASHDIR
65+
CCACHE_BASEDIR="$(pwd)/mongo-cxx-driver"
66+
CCACHE_NOHASHDIR=1
6367
fi
6468

6569
# Install prefix to use for ABI compatibility scripts.

.evergreen/compile.sh

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,18 @@ CMAKE_BUILD_PARALLEL_LEVEL="$(nproc)"
6767
export CMAKE_BUILD_PARALLEL_LEVEL
6868

6969
# Use ccache if available.
70-
if command -v ccache >/dev/null; then
71-
echo "Enabling ccache as CMake compiler launcher"
72-
export CMAKE_C_COMPILER_LAUNCHER=ccache
70+
if command -V ccache 2>/dev/null; then
7371
export CMAKE_CXX_COMPILER_LAUNCHER=ccache
72+
73+
74+
# Allow reuse of ccache compilation results between different build directories.
75+
export CCACHE_BASEDIR CCACHE_NOHASHDIR
76+
CCACHE_BASEDIR="$(pwd)"
77+
CCACHE_NOHASHDIR=1
78+
# Allow reuse of ccache compilation results between different build directories.
79+
export CCACHE_BASEDIR CCACHE_NOHASHDIR
80+
CCACHE_BASEDIR="$(pwd)"
81+
CCACHE_NOHASHDIR=1
7482
fi
7583

7684
cmake_build_opts=()

.evergreen/install_c_driver.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ if [[ "${OSTYPE}" == darwin* ]]; then
8383
}
8484
fi
8585

86-
8786
# Default CMake generator to use if not already provided.
8887
declare CMAKE_GENERATOR CMAKE_GENERATOR_PLATFORM
8988
if [[ "${OSTYPE:?}" == "cygwin" ]]; then
@@ -131,6 +130,17 @@ else
131130
configure_flags+=("-DENABLE_EXTRA_ALIGNMENT=OFF")
132131
fi
133132

133+
# Use ccache if available.
134+
if command -V ccache 2>/dev/null; then
135+
export CMAKE_C_COMPILER_LAUNCHER=ccache
136+
export CMAKE_CXX_COMPILER_LAUNCHER=ccache
137+
138+
# Allow reuse of ccache compilation results between different build directories.
139+
export CCACHE_BASEDIR CCACHE_NOHASHDIR
140+
CCACHE_BASEDIR="${mongoc_idir}"
141+
CCACHE_NOHASHDIR=1
142+
fi
143+
134144
# Install libmongoc.
135145
{
136146
echo "Installing C Driver into ${mongoc_dir}..." 1>&2

.mci.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -962,11 +962,21 @@ tasks:
962962
rsync -aq --exclude='examples/add_subdirectory' $(readlink -f ../..) .
963963
[ -d build ] || mkdir build
964964
. ./mongo-c-driver/.evergreen/scripts/find-cmake-latest.sh
965-
export CMAKE
966-
CMAKE="$(find_cmake_latest)"
967-
command -v "$CMAKE"
968-
$CMAKE -S . -B build -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF
969-
$CMAKE --build build
965+
export cmake_binary
966+
cmake_binary="$(find_cmake_latest)"
967+
# Use ccache if available.
968+
if command -V ccache 2>/dev/null; then
969+
export CMAKE_C_COMPILER_LAUNCHER=ccache
970+
export CMAKE_CXX_COMPILER_LAUNCHER=ccache
971+
972+
# Allow reuse of ccache compilation results between different build directories.
973+
export CCACHE_BASEDIR CCACHE_NOHASHDIR
974+
CCACHE_BASEDIR="$(pwd)"
975+
CCACHE_NOHASHDIR=1
976+
fi
977+
command -v "$cmake_binary"
978+
"$cmake_binary" -S . -B build -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF
979+
"$cmake_binary" --build build
970980
./build/hello_mongocxx
971981
972982
- name: debian-package-build

0 commit comments

Comments
 (0)