Skip to content

Commit 8c2d66f

Browse files
authored
Re-introduce ccache support (#863)
Recent change 9a4ba81 removed ccache support from the build process. This commit re-introduces ccache support and updates GN files accordingly. Since ccache only supports compilation, updates have been made to the compiler prefixes. Additionally, assertions have been added to ensure ccache is not used on Windows or in conjunction with RBE. Fixes flutter/flutter#149100 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read the [Flutter Style Guide] _recently_, and have followed its advice. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
1 parent 9517c81 commit 8c2d66f

File tree

6 files changed

+39
-5
lines changed

6 files changed

+39
-5
lines changed

build/toolchain/android/BUILD.gn

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# found in the LICENSE file.
44

55
import("//build/config/sysroot.gni") # Imports android/config.gni.
6+
import("//build/toolchain/ccache.gni")
67
import("//build/toolchain/clang.gni")
78
import("//build/toolchain/gcc_toolchain.gni")
89
import("//build/toolchain/rbe.gni")
@@ -56,6 +57,11 @@ template("android_toolchain") {
5657
assembler_prefix = ""
5758
compiler_prefix = string_join(" ", compiler_args)
5859
link_prefix = ""
60+
} else if (use_ccache) {
61+
# ccache only supports compilation, not linking.
62+
assembler_prefix = "ccache "
63+
compiler_prefix = ""
64+
link_prefix = ""
5965
} else {
6066
compiler_prefix = ""
6167
link_prefix = ""

build/toolchain/ccache.gni

+5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
# speed, you can do:
2020
# export CCACHE_CPP2=yes
2121

22+
import("//build/toolchain/rbe.gni") # for use_rbe
23+
2224
declare_args() {
2325
# Set to true to enable ccache. Probably doesn't work on windows.
2426
use_ccache = false
2527
}
28+
29+
assert(!is_win || !use_ccache, "ccache is not supported on Windows")
30+
assert(!use_ccache || !use_rbe, "ccache is not supported with RBE")

build/toolchain/fuchsia/BUILD.gn

+5
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@
44

55
import("//build/toolchain/clang.gni")
66
import("//build/toolchain/rbe.gni")
7+
import("//build/toolchain/ccache.gni")
78
import("//build/toolchain/toolchain.gni")
89

910
if (use_rbe) {
1011
compiler_args =
1112
rewrapper_command + [ "--labels=type=compile,compiler=clang,lang=cpp " ]
1213
compiler_prefix = string_join(" ", compiler_args)
1314
link_prefix = ""
15+
} else if (use_ccache) {
16+
# ccache only supports compilation, not linking.
17+
compiler_prefix = "ccache"
18+
link_prefix = ""
1419
} else {
1520
compiler_prefix = ""
1621
link_prefix = ""

build/toolchain/linux/BUILD.gn

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# found in the LICENSE file.
44

55
import("//build/config/sysroot.gni")
6+
import("//build/toolchain/ccache.gni")
67
import("//build/toolchain/gcc_toolchain.gni")
78
import("//build/toolchain/rbe.gni")
89
import("//build/toolchain/toolchain.gni")
@@ -23,6 +24,10 @@ if (use_rbe) {
2324
]
2425
compiler_prefix = string_join(" ", compiler_args)
2526
link_prefix = ""
27+
} else if (use_ccache) {
28+
# ccache only supports compilation, not linking.
29+
compiler_prefix = "ccache "
30+
link_prefix = ""
2631
} else {
2732
compiler_prefix = ""
2833
link_prefix = ""

build/toolchain/mac/BUILD.gn

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import("//build/config/sysroot.gni")
1010
import("//build/toolchain/clang.gni")
1111
import("//build/toolchain/clang_static_analyzer.gni")
1212
import("//build/toolchain/rbe.gni")
13+
import("//build/toolchain/ccache.gni")
1314
import("//build/toolchain/toolchain.gni")
1415

1516
if (host_cpu == "arm64") {
@@ -20,7 +21,12 @@ if (host_cpu == "arm64") {
2021
rebase_path("$buildtools_path/mac-x64/clang/bin", root_build_dir)
2122
}
2223

23-
if (use_rbe) {
24+
if (use_ccache) {
25+
# ccache only supports compilation, not linking.
26+
cxx_prefix = "ccache "
27+
objc_prefix = "ccache "
28+
link_prefix = ""
29+
} else if (use_rbe) {
2430
remote_wrapper =
2531
rebase_path("//flutter/build/rbe/remote_wrapper.sh", root_build_dir)
2632
local_wrapper =

build/toolchain/wasm.gni

+11-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ declare_args() {
1717

1818
em_config_path = "$emsdk_dir/.emscripten"
1919

20+
if (use_ccache) {
21+
# ccache only supports compilation, not linking.
22+
compiler_prefix = "ccache "
23+
} else {
24+
compiler_prefix = ""
25+
}
26+
2027
template("wasm_toolchain") {
2128
gcc_toolchain(target_name) {
2229
extra_toolchain_args = {
@@ -27,9 +34,9 @@ template("wasm_toolchain") {
2734

2835
# emsdk_dir and em_config are defined in wasm.gni.
2936
ar = "$emsdk_dir/upstream/emscripten/emar --em-config $em_config_path"
30-
cc = "$emsdk_dir/upstream/emscripten/emcc --em-config $em_config_path"
31-
cxx = "$emsdk_dir/upstream/emscripten/em++ --em-config $em_config_path"
32-
asm = cc
37+
cc = "$compiler_prefix$emsdk_dir/upstream/emscripten/emcc --em-config $em_config_path"
38+
cxx = "$compiler_prefix$emsdk_dir/upstream/emscripten/em++ --em-config $em_config_path"
39+
asm = "$emsdk_dir/upstream/emscripten/emcc --em-config $em_config_path"
3340

3441
# emscripten emits this .worker.js file conditionally depending on whether
3542
# pthreads are on or not. Unfortunately, there is no way to conditionally
@@ -39,7 +46,7 @@ template("wasm_toolchain") {
3946
# dummy file. If the target does use pthreads, this dummy file will be
4047
# overwritten. If the target does not, the dummy file will satisfy the
4148
# toolchain's requirement that it has this as an output.
42-
ld = "$cxx"
49+
ld = "$emsdk_dir/upstream/emscripten/em++ --em-config $em_config_path"
4350
readelf = "readelf"
4451
nm = "nm"
4552

0 commit comments

Comments
 (0)