Skip to content

Commit 7be1c65

Browse files
authored
Improve ccache instructions Fixes facebook#4215 (facebook#4218)
1 parent 18f0c80 commit 7be1c65

File tree

3 files changed

+36
-216
lines changed

3 files changed

+36
-216
lines changed

docs/build-speed.md

Lines changed: 12 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -72,47 +72,8 @@ We suggest to use [**ccache**](https://ccache.dev/) to cache the compilation of
7272
Ccache works by wrapping the C++ compilers, storing the compilation results, and skipping the compilation
7373
if an intermediate compilation result was originally stored.
7474

75-
To install it, you can follow the [official installation instructions](https://github.com/ccache/ccache/blob/master/doc/INSTALL.md).
76-
77-
On macOS, we can install ccache with `brew install ccache`.
78-
Once installed you can configure it as follows to cache NDK compile results:
79-
80-
```
81-
ln -s $(which ccache) /usr/local/bin/gcc
82-
ln -s $(which ccache) /usr/local/bin/g++
83-
ln -s $(which ccache) /usr/local/bin/cc
84-
ln -s $(which ccache) /usr/local/bin/c++
85-
ln -s $(which ccache) /usr/local/bin/clang
86-
ln -s $(which ccache) /usr/local/bin/clang++
87-
```
88-
89-
This will create symbolic links to `ccache` inside the `/usr/local/bin/` which are called `gcc`, `g++`, and so on.
90-
91-
This works as long as `/usr/local/bin/` comes first than `/usr/bin/` inside your `$PATH` variable, which is the default.
92-
93-
You can verify that it works using the `which` command:
94-
95-
```
96-
$ which gcc
97-
/usr/local/bin/gcc
98-
```
99-
100-
If the results is `/usr/local/bin/gcc`, then you're effectively calling `ccache` which will wrap the `gcc` calls.
101-
102-
:::caution
103-
Please note that this setup of `ccache` will affect all the compilations that you're running on your machine, not only those related to React Native. Use it at your own risk. If you're failing to install/compile other software, this might be the reason. If that is the case, you can remove the symlink you created with:
104-
105-
```
106-
unlink /usr/local/bin/gcc
107-
unlink /usr/local/bin/g++
108-
unlink /usr/local/bin/cc
109-
unlink /usr/local/bin/c++
110-
unlink /usr/local/bin/clang
111-
unlink /usr/local/bin/clang++
112-
```
113-
114-
to revert your machine to the original status and use the default compilers.
115-
:::
75+
Ccache is available in the package manager for most operating systems. On macOS, we can install ccache with `brew install ccache`.
76+
Or you can follow the [official installation instructions](https://github.com/ccache/ccache/blob/master/doc/INSTALL.md) to install from source.
11677

11778
You can then do two clean builds (e.g. on Android you can first run `yarn react-native run-android`, delete the `android/app/build` folder and run the first command once more). You will notice that the second build was way faster than the first one (it should take seconds rather than minutes).
11879
While building, you can verify that `ccache` works correctly and check the cache hits/miss rate `ccache -s`
@@ -139,44 +100,23 @@ Should you need to wipe your cache, you can do so with `ccache --clear`
139100

140101
#### XCode Specific Setup
141102

142-
To make sure `ccache` works correctly with iOS and XCode, you need to follow a couple of extra steps:
143-
144-
1. You must alter the way Xcode and `xcodebuild` call for the compiler command. By default they use _fully specified paths_ to the compiler binaries, so the symbolic links installed in `/usr/local/bin` will not be used. You may configure Xcode to use _relative_ names for the compilers using either of these two options:
103+
To make sure `ccache` works correctly with iOS and XCode, you need to enable React Native support for ccache in `ios/Podfile`.
145104

146-
- environment variables prefixed on the command line if you use a direct command line: `CLANG=clang CLANGPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ xcodebuild <rest of xcodebuild command line>`
147-
- A `post_install` section in your `ios/Podfile` that alters the compiler in your Xcode workspace during the `pod install` step:
105+
Open `ios/Podfile` in your editor and uncomment the `ccache_enabled` line.
148106

149107
```ruby
150108
post_install do |installer|
151-
react_native_post_install(installer)
152-
153-
# ...possibly other post_install items here
154-
155-
installer.pods_project.targets.each do |target|
156-
target.build_configurations.each do |config|
157-
# Using the un-qualified names means you can swap in different implementations, for example ccache
158-
config.build_settings["CC"] = "clang"
159-
config.build_settings["LD"] = "clang"
160-
config.build_settings["CXX"] = "clang++"
161-
config.build_settings["LDPLUSPLUS"] = "clang++"
162-
end
163-
end
164-
165-
__apply_Xcode_12_5_M1_post_install_workaround(installer)
109+
# https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
110+
react_native_post_install(
111+
installer,
112+
config[:reactNativePath],
113+
:mac_catalyst_enabled => false,
114+
# TODO: Uncomment the line below
115+
:ccache_enabled => true
116+
)
166117
end
167118
```
168119

169-
2. You need a ccache configuration that allows for a certain level of sloppiness and cache behavior such that ccache registers cache hits during Xcode compiles. The ccache configuration variables that are different from standard are as follows if configured by environment variable:
170-
171-
```bash
172-
export CCACHE_SLOPPINESS=clang_index_store,file_stat_matches,include_file_ctime,include_file_mtime,ivfsoverlay,pch_defines,modules,system_headers,time_macros
173-
export CCACHE_FILECLONE=true
174-
export CCACHE_DEPEND=true
175-
export CCACHE_INODECACHE=true
176-
```
177-
178-
The same may be configured in a `ccache.conf` file or any other mechanism ccache provides. More on this can be found in the [official ccache manual](https://ccache.dev/manual/4.3.html).
179-
180120
#### Using this approach on a CI
181121

182122
Ccache uses the `/Users/$USER/Library/Caches/ccache` folder on macOS to store the cache.

website/versioned_docs/version-0.74/build-speed.md

Lines changed: 12 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -72,47 +72,8 @@ We suggest to use [**ccache**](https://ccache.dev/) to cache the compilation of
7272
Ccache works by wrapping the C++ compilers, storing the compilation results, and skipping the compilation
7373
if an intermediate compilation result was originally stored.
7474

75-
To install it, you can follow the [official installation instructions](https://github.com/ccache/ccache/blob/master/doc/INSTALL.md).
76-
77-
On macOS, we can install ccache with `brew install ccache`.
78-
Once installed you can configure it as follows to cache NDK compile results:
79-
80-
```
81-
ln -s $(which ccache) /usr/local/bin/gcc
82-
ln -s $(which ccache) /usr/local/bin/g++
83-
ln -s $(which ccache) /usr/local/bin/cc
84-
ln -s $(which ccache) /usr/local/bin/c++
85-
ln -s $(which ccache) /usr/local/bin/clang
86-
ln -s $(which ccache) /usr/local/bin/clang++
87-
```
88-
89-
This will create symbolic links to `ccache` inside the `/usr/local/bin/` which are called `gcc`, `g++`, and so on.
90-
91-
This works as long as `/usr/local/bin/` comes first than `/usr/bin/` inside your `$PATH` variable, which is the default.
92-
93-
You can verify that it works using the `which` command:
94-
95-
```
96-
$ which gcc
97-
/usr/local/bin/gcc
98-
```
99-
100-
If the results is `/usr/local/bin/gcc`, then you're effectively calling `ccache` which will wrap the `gcc` calls.
101-
102-
:::caution
103-
Please note that this setup of `ccache` will affect all the compilations that you're running on your machine, not only those related to React Native. Use it at your own risk. If you're failing to install/compile other software, this might be the reason. If that is the case, you can remove the symlink you created with:
104-
105-
```
106-
unlink /usr/local/bin/gcc
107-
unlink /usr/local/bin/g++
108-
unlink /usr/local/bin/cc
109-
unlink /usr/local/bin/c++
110-
unlink /usr/local/bin/clang
111-
unlink /usr/local/bin/clang++
112-
```
113-
114-
to revert your machine to the original status and use the default compilers.
115-
:::
75+
Ccache is available in the package manager for most operating systems. On macOS, we can install ccache with `brew install ccache`.
76+
Or you can follow the [official installation instructions](https://github.com/ccache/ccache/blob/master/doc/INSTALL.md) to install from source.
11677

11778
You can then do two clean builds (e.g. on Android you can first run `yarn react-native run-android`, delete the `android/app/build` folder and run the first command once more). You will notice that the second build was way faster than the first one (it should take seconds rather than minutes).
11879
While building, you can verify that `ccache` works correctly and check the cache hits/miss rate `ccache -s`
@@ -139,44 +100,23 @@ Should you need to wipe your cache, you can do so with `ccache --clear`
139100

140101
#### XCode Specific Setup
141102

142-
To make sure `ccache` works correctly with iOS and XCode, you need to follow a couple of extra steps:
143-
144-
1. You must alter the way Xcode and `xcodebuild` call for the compiler command. By default they use _fully specified paths_ to the compiler binaries, so the symbolic links installed in `/usr/local/bin` will not be used. You may configure Xcode to use _relative_ names for the compilers using either of these two options:
103+
To make sure `ccache` works correctly with iOS and XCode, you need to enable React Native support for ccache in `ios/Podfile`.
145104

146-
- environment variables prefixed on the command line if you use a direct command line: `CLANG=clang CLANGPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ xcodebuild <rest of xcodebuild command line>`
147-
- A `post_install` section in your `ios/Podfile` that alters the compiler in your Xcode workspace during the `pod install` step:
105+
Open `ios/Podfile` in your editor and uncomment the `ccache_enabled` line.
148106

149107
```ruby
150108
post_install do |installer|
151-
react_native_post_install(installer)
152-
153-
# ...possibly other post_install items here
154-
155-
installer.pods_project.targets.each do |target|
156-
target.build_configurations.each do |config|
157-
# Using the un-qualified names means you can swap in different implementations, for example ccache
158-
config.build_settings["CC"] = "clang"
159-
config.build_settings["LD"] = "clang"
160-
config.build_settings["CXX"] = "clang++"
161-
config.build_settings["LDPLUSPLUS"] = "clang++"
162-
end
163-
end
164-
165-
__apply_Xcode_12_5_M1_post_install_workaround(installer)
109+
# https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
110+
react_native_post_install(
111+
installer,
112+
config[:reactNativePath],
113+
:mac_catalyst_enabled => false,
114+
# TODO: Uncomment the line below
115+
:ccache_enabled => true
116+
)
166117
end
167118
```
168119

169-
2. You need a ccache configuration that allows for a certain level of sloppiness and cache behavior such that ccache registers cache hits during Xcode compiles. The ccache configuration variables that are different from standard are as follows if configured by environment variable:
170-
171-
```bash
172-
export CCACHE_SLOPPINESS=clang_index_store,file_stat_matches,include_file_ctime,include_file_mtime,ivfsoverlay,pch_defines,modules,system_headers,time_macros
173-
export CCACHE_FILECLONE=true
174-
export CCACHE_DEPEND=true
175-
export CCACHE_INODECACHE=true
176-
```
177-
178-
The same may be configured in a `ccache.conf` file or any other mechanism ccache provides. More on this can be found in the [official ccache manual](https://ccache.dev/manual/4.3.html).
179-
180120
#### Using this approach on a CI
181121

182122
Ccache uses the `/Users/$USER/Library/Caches/ccache` folder on macOS to store the cache.

website/versioned_docs/version-0.75/build-speed.md

Lines changed: 12 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -72,47 +72,8 @@ We suggest to use [**ccache**](https://ccache.dev/) to cache the compilation of
7272
Ccache works by wrapping the C++ compilers, storing the compilation results, and skipping the compilation
7373
if an intermediate compilation result was originally stored.
7474

75-
To install it, you can follow the [official installation instructions](https://github.com/ccache/ccache/blob/master/doc/INSTALL.md).
76-
77-
On macOS, we can install ccache with `brew install ccache`.
78-
Once installed you can configure it as follows to cache NDK compile results:
79-
80-
```
81-
ln -s $(which ccache) /usr/local/bin/gcc
82-
ln -s $(which ccache) /usr/local/bin/g++
83-
ln -s $(which ccache) /usr/local/bin/cc
84-
ln -s $(which ccache) /usr/local/bin/c++
85-
ln -s $(which ccache) /usr/local/bin/clang
86-
ln -s $(which ccache) /usr/local/bin/clang++
87-
```
88-
89-
This will create symbolic links to `ccache` inside the `/usr/local/bin/` which are called `gcc`, `g++`, and so on.
90-
91-
This works as long as `/usr/local/bin/` comes first than `/usr/bin/` inside your `$PATH` variable, which is the default.
92-
93-
You can verify that it works using the `which` command:
94-
95-
```
96-
$ which gcc
97-
/usr/local/bin/gcc
98-
```
99-
100-
If the results is `/usr/local/bin/gcc`, then you're effectively calling `ccache` which will wrap the `gcc` calls.
101-
102-
:::caution
103-
Please note that this setup of `ccache` will affect all the compilations that you're running on your machine, not only those related to React Native. Use it at your own risk. If you're failing to install/compile other software, this might be the reason. If that is the case, you can remove the symlink you created with:
104-
105-
```
106-
unlink /usr/local/bin/gcc
107-
unlink /usr/local/bin/g++
108-
unlink /usr/local/bin/cc
109-
unlink /usr/local/bin/c++
110-
unlink /usr/local/bin/clang
111-
unlink /usr/local/bin/clang++
112-
```
113-
114-
to revert your machine to the original status and use the default compilers.
115-
:::
75+
Ccache is available in the package manager for most operating systems. On macOS, we can install ccache with `brew install ccache`.
76+
Or you can follow the [official installation instructions](https://github.com/ccache/ccache/blob/master/doc/INSTALL.md) to install from source.
11677

11778
You can then do two clean builds (e.g. on Android you can first run `yarn react-native run-android`, delete the `android/app/build` folder and run the first command once more). You will notice that the second build was way faster than the first one (it should take seconds rather than minutes).
11879
While building, you can verify that `ccache` works correctly and check the cache hits/miss rate `ccache -s`
@@ -139,44 +100,23 @@ Should you need to wipe your cache, you can do so with `ccache --clear`
139100

140101
#### XCode Specific Setup
141102

142-
To make sure `ccache` works correctly with iOS and XCode, you need to follow a couple of extra steps:
143-
144-
1. You must alter the way Xcode and `xcodebuild` call for the compiler command. By default they use _fully specified paths_ to the compiler binaries, so the symbolic links installed in `/usr/local/bin` will not be used. You may configure Xcode to use _relative_ names for the compilers using either of these two options:
103+
To make sure `ccache` works correctly with iOS and XCode, you need to enable React Native support for ccache in `ios/Podfile`.
145104

146-
- environment variables prefixed on the command line if you use a direct command line: `CLANG=clang CLANGPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ xcodebuild <rest of xcodebuild command line>`
147-
- A `post_install` section in your `ios/Podfile` that alters the compiler in your Xcode workspace during the `pod install` step:
105+
Open `ios/Podfile` in your editor and uncomment the `ccache_enabled` line.
148106

149107
```ruby
150108
post_install do |installer|
151-
react_native_post_install(installer)
152-
153-
# ...possibly other post_install items here
154-
155-
installer.pods_project.targets.each do |target|
156-
target.build_configurations.each do |config|
157-
# Using the un-qualified names means you can swap in different implementations, for example ccache
158-
config.build_settings["CC"] = "clang"
159-
config.build_settings["LD"] = "clang"
160-
config.build_settings["CXX"] = "clang++"
161-
config.build_settings["LDPLUSPLUS"] = "clang++"
162-
end
163-
end
164-
165-
__apply_Xcode_12_5_M1_post_install_workaround(installer)
109+
# https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
110+
react_native_post_install(
111+
installer,
112+
config[:reactNativePath],
113+
:mac_catalyst_enabled => false,
114+
# TODO: Uncomment the line below
115+
:ccache_enabled => true
116+
)
166117
end
167118
```
168119

169-
2. You need a ccache configuration that allows for a certain level of sloppiness and cache behavior such that ccache registers cache hits during Xcode compiles. The ccache configuration variables that are different from standard are as follows if configured by environment variable:
170-
171-
```bash
172-
export CCACHE_SLOPPINESS=clang_index_store,file_stat_matches,include_file_ctime,include_file_mtime,ivfsoverlay,pch_defines,modules,system_headers,time_macros
173-
export CCACHE_FILECLONE=true
174-
export CCACHE_DEPEND=true
175-
export CCACHE_INODECACHE=true
176-
```
177-
178-
The same may be configured in a `ccache.conf` file or any other mechanism ccache provides. More on this can be found in the [official ccache manual](https://ccache.dev/manual/4.3.html).
179-
180120
#### Using this approach on a CI
181121

182122
Ccache uses the `/Users/$USER/Library/Caches/ccache` folder on macOS to store the cache.

0 commit comments

Comments
 (0)