Skip to content

Commit 72db1a4

Browse files
committed
Use ccache with more packages
1 parent 095b3f3 commit 72db1a4

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ RUN ./pkgman.py \
4444
--c_compiler=/usr/bin/clang \
4545
--cxx_compiler=/usr/bin/clang++ \
4646
--verbose \
47+
--use_ccache \
4748
--repository_path="${BOOTSTRAP}" \
4849
--packages=cmake
4950

@@ -68,6 +69,7 @@ RUN mkdir -p /cache && ./pkgman.py \
6869
--cxx_compiler="${LIBRARIES}/llvm/bin/clang++" \
6970
--c_compiler="${LIBRARIES}/llvm/bin/clang" \
7071
--verbose \
72+
--use_ccache \
7173
"--additional_paths=${BOOTSTRAP}/cmake/bin:${LIBRARIES}/llvm/bin" \
7274
"--repository_path=${LIBRARIES}" \
7375
"--packages=cmake,google,xed"

pkgman/installers/common.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ def google_installer_glog(properties):
100100
print(" x Failed to create the build folder")
101101
return False
102102

103+
if properties["ccache"]:
104+
set_ccache_compiler()
105+
103106
cmake_command = ["cmake"] + get_env_compiler_settings() + get_cmake_build_type(debug) + get_cmake_generator()
104107
cmake_command += ["-DCMAKE_CXX_STANDARD=11",
105108
"-DBUILD_TESTING=OFF",
@@ -141,6 +144,9 @@ def common_installer_capstone(properties):
141144
print(" x Failed to create the build folder")
142145
return False
143146

147+
if properties["ccache"]:
148+
set_ccache_compiler()
149+
144150
cmake_command = ["cmake"] + get_env_compiler_settings() + get_cmake_build_type(debug) + get_cmake_generator()
145151
cmake_command += ["-DCMAKE_EXE_LINKER_FLAGS=-g",
146152
"-DCMAKE_C_FLAGS=-g",
@@ -247,6 +253,8 @@ def google_installer_gflags(properties):
247253
print(" x Failed to create the build folder")
248254
return False
249255

256+
if properties["ccache"]:
257+
set_ccache_compiler()
250258

251259
cmake_command = ["cmake"] + get_env_compiler_settings() + get_cmake_build_type(debug) + get_cmake_generator()
252260
cmake_command += ["-DCMAKE_INSTALL_PREFIX=" + os.path.join(repository_path, "gflags"),
@@ -289,6 +297,9 @@ def google_installer_googletest(properties):
289297
print(" x Failed to create the build folder")
290298
return False
291299

300+
if properties["ccache"]:
301+
set_ccache_compiler()
302+
292303
cmake_command = ["cmake"] + get_env_compiler_settings() + get_cmake_build_type(debug) + get_cmake_generator(False)
293304
cmake_command += ["-DCMAKE_CXX_STANDARD=11",
294305
"-DCMAKE_POSITION_INDEPENDENT_CODE=ON",
@@ -363,6 +374,9 @@ def google_installer_protobuf(properties):
363374
print(" x Failed to create the build folder")
364375
return False
365376

377+
if properties["ccache"]:
378+
set_ccache_compiler()
379+
366380
cmake_command = ["cmake"] + get_env_compiler_settings() + get_cmake_build_type(debug) + get_cmake_generator(False)
367381
cmake_command += ["-DPROTOBUF_ROOT=" + source_folder,
368382
"-DBUILD_SHARED_LIBS=OFF",
@@ -433,6 +447,9 @@ def common_installer_capnproto(properties):
433447
print(" x Failed to create the build folder")
434448
return False
435449

450+
if properties["ccache"]:
451+
set_ccache_compiler()
452+
436453
cmake_command = ["cmake"] + get_env_compiler_settings() + get_cmake_build_type(debug) + get_cmake_generator()
437454
cmake_command += ["-DCMAKE_CXX_STANDARD=11",
438455
"-DCMAKE_CXX_EXTENSIONS=ON",
@@ -590,6 +607,13 @@ def common_installer_llvm(properties):
590607
arch_list += ";AArch64;Sparc;NVPTX;ARM"
591608
arch_list += "'"
592609

610+
if properties["ccache"]:
611+
# Remove this so we don't clash with LLVM's built-in ccache config
612+
if "CMAKE_CXX_COMPILER_LAUNCHER" in os.environ:
613+
del(os.environ["CMAKE_CXX_COMPILER_LAUNCHER"])
614+
if "CMAKE_C_COMPILER_LAUNCHER" in os.environ:
615+
del(os.environ["CMAKE_C_COMPILER_LAUNCHER"])
616+
593617
cppstd = "11"
594618
if int(properties["llvm_version"]) > 900:
595619
cppstd = "14"
@@ -662,6 +686,9 @@ def common_installer_z3(properties):
662686
print(" x Failed to create the build folder")
663687
return False
664688

689+
if properties["ccache"]:
690+
set_ccache_compiler()
691+
665692
cmake_command = ["cmake"] + get_env_compiler_settings() + get_cmake_build_type(debug) + get_cmake_generator()
666693
cmake_command += ["-DZ3_BUILD_LIBZ3_SHARED=False",
667694
"-DZ3_ENABLE_EXAMPLE_TARGETS=False",

pkgman/installers/unix.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ def unix_installer_boost(properties, default_toolset):
5353
if "CMAKE_CXX_COMPILER" in os.environ:
5454
os.environ["CXX"] = os.environ["CMAKE_CXX_COMPILER"]
5555

56+
if properties["ccache"]:
57+
set_ccache_compiler()
58+
os.environ["CXX"] = f"ccache {os.environ['CXX']}"
59+
os.environ["CC"] = f"ccache {os.environ['CC']}"
60+
5661
configure_command = [source_folder + "/bootstrap.sh", "--prefix=" + os.path.join(repository_path, "boost"), "--with-toolset=" + toolset_name]
5762
if not run_program("Running the bootstrap script...", configure_command, source_folder, verbose=verbose_output):
5863
return False
@@ -118,7 +123,12 @@ def unix_installer_cmake(properties):
118123
if os.environ.get("CMAKE_CXX_COMPILER") is not None:
119124
os.environ["CXX"] = os.environ["CMAKE_CXX_COMPILER"]
120125

121-
if not run_program("Running the bootstrap script...", ["./bootstrap", "--verbose", "--parallel=" + str(multiprocessing.cpu_count()), "--prefix=" + destination_path], source_folder, verbose=verbose_output):
126+
enable_ccache = ""
127+
if properties["ccache"]:
128+
set_ccache_compiler()
129+
enable_ccache = "--enable-ccache"
130+
131+
if not run_program("Running the bootstrap script...", ["./bootstrap", "--verbose", enable_ccache, "--parallel=" + str(multiprocessing.cpu_count()), "--prefix=" + destination_path], source_folder, verbose=verbose_output):
122132
return False
123133

124134
if not run_program("Building the source code...", ["make", "-j" + str(multiprocessing.cpu_count())], source_folder, verbose=verbose_output):

pkgman/installers/utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,26 @@ def get_env_compiler_settings():
3232
if os.environ.get("CMAKE_C_COMPILER") is not None:
3333
cmake_compiler_settings.append("-DCMAKE_C_COMPILER=" + os.environ["CMAKE_C_COMPILER"])
3434

35+
if os.environ.get("CMAKE_CXX_COMPILER_LAUNCHER") is not None:
36+
cmake_compiler_settings.append("-DCMAKE_CXX_COMPILER_LAUNCHER=" + os.environ["CMAKE_CXX_COMPILER_LAUNCHER"])
37+
38+
if os.environ.get("CMAKE_C_COMPILER_LAUNCHER") is not None:
39+
cmake_compiler_settings.append("-DCMAKE_C_COMPILER_LAUNCHER=" + os.environ["CMAKE_C_COMPILER_LAUNCHER"])
40+
3541
return cmake_compiler_settings
3642

43+
44+
def set_ccache_compiler():
45+
"""
46+
Set the compiler environment variables to use ccache.
47+
48+
NOTE: LLVM uses its own ccache settings. Make sure these are synchronized
49+
"""
50+
os.environ["CMAKE_CXX_COMPILER_LAUNCHER"] = "ccache"
51+
os.environ["CMAKE_C_COMPILER_LAUNCHER"] = "ccache"
52+
os.environ["CCACHE_DIR"] = "/cache/ccache"
53+
54+
3755
def get_parallel_build_options():
3856
processor_count = str(multiprocessing.cpu_count())
3957

0 commit comments

Comments
 (0)