Skip to content

Commit bd30285

Browse files
committed
auto merge of #6813 : pnkfelix/rust/fsk-issue-6805-ccache-support, r=catamorphism
Fix #6805: add --enable-ccache configure option to prefix compiler invocations with `ccache` to attempt to reuse common results, e.g. for LLVM (re)builds. The information at developer [Note-ccache](../../wiki/Note-ccache) and at [ccache and clang concerns](http://petereisentraut.blogspot.fr/2011/09/ccache-and-clang-part-2.html) were what drove my introduction of the `-Qunused-arguments` and `CCACHE_CPP2` options. (Though I did confirm first-hand that at least the first really is necessary.) Yes, one certainly can re-route how `gcc` and `clang` are resolved in one's PATH and use that as a way to invoke `ccache`. But I personally do not want to introduce that change to my own PATH, and this seems like a small enough change that it does not hurt to add it, at least for now. (I don't know what form it would take when we move over to `rustpkg`.)
2 parents 35655a0 + 2b08337 commit bd30285

File tree

2 files changed

+68
-4
lines changed

2 files changed

+68
-4
lines changed

configure

+39-4
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ opt fast-make 0 "use .gitmodules as timestamp for submodule deps"
376376
opt manage-submodules 1 "let the build manage the git submodules"
377377
opt mingw-cross 0 "cross-compile for win32 using mingw"
378378
opt clang 0 "prefer clang to gcc for building the runtime"
379+
opt ccache 0 "invoke gcc/clang via ccache to reuse object files between builds"
379380
opt local-rust 0 "use an installed rustc rather than downloading a snapshot"
380381
opt pax-flags 0 "apply PaX flags to rustc binaries (required for GRSecurity/PaX-patched kernels)"
381382
valopt prefix "/usr/local" "set installation prefix"
@@ -421,6 +422,7 @@ else
421422
fi
422423

423424
probe CFG_CLANG clang++
425+
probe CFG_CCACHE ccache
424426
probe CFG_GCC gcc
425427
probe CFG_LD ld
426428
probe CFG_VALGRIND valgrind
@@ -571,6 +573,16 @@ else
571573
CFG_C_COMPILER="gcc"
572574
fi
573575

576+
if [ ! -z "$CFG_ENABLE_CCACHE" ]
577+
then
578+
if [ -z "$CFG_CCACHE" ]
579+
then
580+
err "ccache requested but not found"
581+
fi
582+
583+
CFG_C_COMPILER="ccache $CFG_C_COMPILER"
584+
fi
585+
574586
# a little post-processing of various config values
575587

576588
CFG_PREFIX=${CFG_PREFIX%/}
@@ -825,20 +837,35 @@ do
825837
--enable-bindings=none --disable-threads \
826838
--disable-pthreads"
827839

828-
if [ "$CFG_C_COMPILER" = "clang" ]
829-
then
840+
case "$CFG_C_COMPILER" in
841+
("ccache clang")
842+
LLVM_CXX_32="ccache clang++ -m32 -Qunused-arguments"
843+
LLVM_CC_32="ccache clang -m32 -Qunused-arguments"
844+
845+
LLVM_CXX_64="ccache clang++ -Qunused-arguments"
846+
LLVM_CC_64="ccache clang -Qunused-arguments"
847+
;;
848+
("clang")
830849
LLVM_CXX_32="clang++ -m32"
831850
LLVM_CC_32="clang -m32"
832851

833852
LLVM_CXX_64="clang++"
834853
LLVM_CC_64="clang"
835-
else
854+
;;
855+
("ccache gcc")
856+
LLVM_CXX_32="ccache g++ -m32"
857+
LLVM_CC_32="ccache gcc -m32"
858+
859+
LLVM_CXX_64="ccache g++"
860+
LLVM_CC_64="ccache gcc"
861+
;;
862+
("gcc")
836863
LLVM_CXX_32="g++ -m32"
837864
LLVM_CC_32="gcc -m32"
838865

839866
LLVM_CXX_64="g++"
840867
LLVM_CC_64="gcc"
841-
fi
868+
esac
842869

843870
LLVM_CFLAGS_32="-m32"
844871
LLVM_CXXFLAGS_32="-m32"
@@ -935,6 +962,14 @@ then
935962
putvar CFG_PAXCTL
936963
fi
937964

965+
# Avoid spurious warnings from clang by feeding it original source on
966+
# ccache-miss rather than preprocessed input.
967+
if [ ! -z "$CFG_ENABLE_CCACHE" ] && [ ! -z "$CFG_ENABLE_CLANG" ]
968+
then
969+
CFG_CCACHE_CPP2=1
970+
putvar CFG_CCACHE_CPP2
971+
fi
972+
938973
if [ ! -z $BAD_PANDOC ]
939974
then
940975
CFG_PANDOC=

mk/platform.mk

+29
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,35 @@ ifeq ($(CFG_C_COMPILER),gcc)
105105
ifeq ($(origin CPP),default)
106106
CPP=gcc
107107
endif
108+
else
109+
ifeq ($(CFG_C_COMPILER),ccache clang)
110+
# The -Qunused-arguments sidesteps spurious warnings from clang
111+
ifeq ($(origin CC),default)
112+
CC=ccache clang -Qunused-arguments
113+
endif
114+
ifeq ($(origin CXX),default)
115+
CXX=ccache clang++ -Qunused-arguments
116+
endif
117+
ifeq ($(origin CPP),default)
118+
CPP=ccache clang -Qunused-arguments
119+
endif
120+
else
121+
ifeq ($(CFG_C_COMPILER),ccache gcc)
122+
ifeq ($(origin CC),default)
123+
CC=ccache gcc
124+
endif
125+
ifeq ($(origin CXX),default)
126+
CXX=ccache g++
127+
endif
128+
ifeq ($(origin CPP),default)
129+
CPP=ccache gcc
130+
endif
108131
else
109132
CFG_ERR := $(error please try on a system with gcc or clang)
110133
endif
111134
endif
135+
endif
136+
endif
112137

113138

114139
# x86_64-unknown-linux-gnu configuration
@@ -366,6 +391,10 @@ CFG_LDPATH_x86_64-unknown-freebsd :=
366391
CFG_RUN_x86_64-unknown-freebsd=$(2)
367392
CFG_RUN_TARG_x86_64-unknown-freebsd=$(call CFG_RUN_x86_64-unknown-freebsd,,$(2))
368393

394+
ifeq ($(CFG_CCACHE_CPP2),1)
395+
CCACHE_CPP2=1
396+
export CCACHE_CPP
397+
endif
369398

370399
define CFG_MAKE_TOOLCHAIN
371400
CFG_COMPILE_C_$(1) = $$(CC_$(1)) \

0 commit comments

Comments
 (0)