-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Detect ccache
and provide a default configuration
#42051
Conversation
cc @tido64 but he might be out till after new years |
sloppiness = clang_index_store,file_stat_matches,include_file_ctime,include_file_mtime,ivfsoverlay,pch_defines,modules,system_headers,time_macros | ||
file_clone = true | ||
depend_mode = true | ||
inode_cache = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been contemplating adding the compiler_check = content
mentioned in the guide: https://reactnative.dev/docs/build-speed#using-this-approach-on-a-ci .. I believe it'll make compilations marginally slower, but it would make this even more useful on CI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you checked how cacheable this config is? We've been using this on CI and have typically seen cache hits above 95% when bumping patch releases: https://github.com/microsoft/react-native-test-app/blob/449fe0254d9a8aebe89322fc182ddf7643e07c23/.ccache/ccache.conf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This config is the one suggested on our "Speeding up your Build phase" guide, just converted from env variables to the ccache conf format. I've seen 100% hit rates on a newly instantiated template while deleting the ios/build
directory in between builds.
Base commit: c75abef |
|
||
ccache_path = `command -v ccache`.strip | ||
|
||
if !ccache_path.empty? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add an env variable here to disable this behavior, in case the developer has ccache but wants the default build settings. It could be DISABLE_CCHACE=true
or ENABLE_CCHACHE=false
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be opt-in. We cannot break existing setups. For example, it is possible to use remote caching. A hybrid app would also require a custom setup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that these can be overwritten by the end-users Podfile, but I agree, it's probably safest to have users opt into this. I wonder if it would be polite enough to prompt (a simple log message) a developer that already has ccache installed to supply the opt in environment variable? Making this feature easier to discover.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the description with the additional output printed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A part of a couple of very nit styling thing with ruby, I like this very much.
It is completely optionals and has a great potential!
I'm looking forward to see if it can also improve our CircleCI buids.
ccache_path = `command -v ccache`.strip | ||
ccache_available = !ccache_path.empty? | ||
|
||
message_prefix = ccache_available ? "⚡️".yellow + "Ccache detected (found at %s): " % [ccache_path.italic] : "Unable to locate ccache: " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this prefix can become quite long, as it depends on the path found at line 92.
What about just have [CCACHE]
as a general prefix and have a first line of log that is
Pod::UI.puts("#{message_prefix}: Ccache found at #{ccache_path}")
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I prefer using string interpolation rather than formatting. It feels more Swift/iOS and it is easier to read as the symbols are already replaced by their variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense 👍 I've updated the code to use string interpolation, a [Ccache]
prefix, simplified the formatting used and updated the PR description with the output printed.
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
e79ead9
to
3cc7550
Compare
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
This pull request was successfully merged by @kraenhansen in e85d51c. When will my fix make it into a release? | Upcoming Releases |
@cipolleschi merged this pull request in e85d51c. |
Summary: Building native modules from source, may take a long time. Xcode already helps bring this down, by providing incremental builds, as long as the user doesn't delete their `ios/build` directory. But in some situations, i.e. when iterating the native code of an app or library or when the developer need to delete that `ios/build` directory, it's advantageous to use a compiler cache, such as ccache. This is already outlined in our ["Speeding up your Build phase"](https://reactnative.dev/docs/build-speed#xcode-specific-setup) guide. But setting up an Xcode project to use Ccache with the correct configuration, isn't trivial in a way that doesn't require symlinking `clang` and `clang++` or passing configuration via environment variables on every `npm run ios` invokation. This PR takes its inspiration from the existing guide on [setting up Ccache for Xcode](https://reactnative.dev/docs/build-speed#xcode-specific-setup), but applies the build settings only if an installation of `ccache` is detected and the feature is explicitly opted into via an argument to the `react_native_post_install` function or a `USE_CCACHE` environment variable. It uses two shell scripts to wrap the call to `ccache`, which both injects a default `CCACHE_CONFIGPATH` environment variable (i.e. it won't override this if already provided, to allow for customisations on CI), pointing to a `ccache.config` which works well with React Native projects (it has the same values as the guide mentions). For context, I posted about this change in the ios channel of the contributors Discord server, where I discussed it with cipolleschi and saadnajmi ### Additional output printed when running `pod install` #### When `ccache_available and ccache_enabled` ``` [Ccache]: Ccache found at /opt/homebrew/bin/ccache [Ccache]: Setting CC, LD, CXX & LDPLUSPLUS build settings ``` #### When `ccache_available and !ccache_enabled` ``` [Ccache]: Ccache found at /opt/homebrew/bin/ccache [Ccache]: Pass ':ccache_enabled => true' to 'react_native_post_install' in your Podfile or set environment variable 'USE_CCACHE=1' to increase the speed of subsequent builds ``` #### When `!ccache_available and ccache_enabled` ``` [!] [Ccache]: Install ccache or ensure your neither passing ':ccache_enabled => true' nor setting environment variable 'USE_CCACHE=1' ``` #### Otherwise If the user doesn't have ccache installed and doesn't explicitly opt into this feature, nothing will be printed. bypass-github-export-checks ## Changelog: [IOS] [ADDED] - Added better support for `ccache`, to speed up subsequent builds of native code. After installing `ccache` and running `pod install`, the Xcode project is injected with compiler and linker build settings pointing scripts that loads a default Ccache configuration and invokes the `ccache` executable. Pull Request resolved: facebook#42051 Test Plan: I've tested this manually - would love some inspiration on how to automate this, if the reviewer deem it needed. To test this locally: 1. Install Ccache and make sure the `ccache` executable is in your `PATH` (verify by running `ccache --version`) 2. Create a new template app instance and apply the changes of this PR to the `node_modules/react-native` package. 3. Set the `USE_CCACHE` environment variable using `export USE_CCACHE=1`. 4. Run `pod install` in the `ios` directory. 5. Check the stats of Ccache (running `ccache -s`). 6. Run `npm run ios` or build the project from Xcode. 7. Check the Ccache stats again to verify ccache is intercepting compilation ("Cacheable calls" should ideally be 100%). 8. To check the speed gain: a. Delete the `ios/builds` directory b. Zero out the ccache stats (by running `ccache -z`) c. Run `pod install` again (only needed if you ran the initial `pod install` with new architecture enabled `RCT_NEW_ARCH_ENABLED=1`). d. Run `npm run ios` or build the project from Xcode. e. This last step should be significantly faster and you should see "Hits" under "Local storage" in the ccache stats approach 100%. Reviewed By: huntie Differential Revision: D52431507 Pulled By: cipolleschi fbshipit-source-id: 6cfe39acd6250fae03959f0ee74d1f2fc46b0827
Summary: Building native modules from source, may take a long time. Xcode already helps bring this down, by providing incremental builds, as long as the user doesn't delete their `ios/build` directory. But in some situations, i.e. when iterating the native code of an app or library or when the developer need to delete that `ios/build` directory, it's advantageous to use a compiler cache, such as ccache. This is already outlined in our ["Speeding up your Build phase"](https://reactnative.dev/docs/build-speed#xcode-specific-setup) guide. But setting up an Xcode project to use Ccache with the correct configuration, isn't trivial in a way that doesn't require symlinking `clang` and `clang++` or passing configuration via environment variables on every `npm run ios` invokation. This PR takes its inspiration from the existing guide on [setting up Ccache for Xcode](https://reactnative.dev/docs/build-speed#xcode-specific-setup), but applies the build settings only if an installation of `ccache` is detected and the feature is explicitly opted into via an argument to the `react_native_post_install` function or a `USE_CCACHE` environment variable. It uses two shell scripts to wrap the call to `ccache`, which both injects a default `CCACHE_CONFIGPATH` environment variable (i.e. it won't override this if already provided, to allow for customisations on CI), pointing to a `ccache.config` which works well with React Native projects (it has the same values as the guide mentions). For context, I posted about this change in the ios channel of the contributors Discord server, where I discussed it with cipolleschi and saadnajmi ### Additional output printed when running `pod install` #### When `ccache_available and ccache_enabled` ``` [Ccache]: Ccache found at /opt/homebrew/bin/ccache [Ccache]: Setting CC, LD, CXX & LDPLUSPLUS build settings ``` #### When `ccache_available and !ccache_enabled` ``` [Ccache]: Ccache found at /opt/homebrew/bin/ccache [Ccache]: Pass ':ccache_enabled => true' to 'react_native_post_install' in your Podfile or set environment variable 'USE_CCACHE=1' to increase the speed of subsequent builds ``` #### When `!ccache_available and ccache_enabled` ``` [!] [Ccache]: Install ccache or ensure your neither passing ':ccache_enabled => true' nor setting environment variable 'USE_CCACHE=1' ``` #### Otherwise If the user doesn't have ccache installed and doesn't explicitly opt into this feature, nothing will be printed. bypass-github-export-checks ## Changelog: [IOS] [ADDED] - Added better support for `ccache`, to speed up subsequent builds of native code. After installing `ccache` and running `pod install`, the Xcode project is injected with compiler and linker build settings pointing scripts that loads a default Ccache configuration and invokes the `ccache` executable. Pull Request resolved: facebook/react-native#42051 Test Plan: I've tested this manually - would love some inspiration on how to automate this, if the reviewer deem it needed. To test this locally: 1. Install Ccache and make sure the `ccache` executable is in your `PATH` (verify by running `ccache --version`) 2. Create a new template app instance and apply the changes of this PR to the `node_modules/react-native` package. 3. Set the `USE_CCACHE` environment variable using `export USE_CCACHE=1`. 4. Run `pod install` in the `ios` directory. 5. Check the stats of Ccache (running `ccache -s`). 6. Run `npm run ios` or build the project from Xcode. 7. Check the Ccache stats again to verify ccache is intercepting compilation ("Cacheable calls" should ideally be 100%). 8. To check the speed gain: a. Delete the `ios/builds` directory b. Zero out the ccache stats (by running `ccache -z`) c. Run `pod install` again (only needed if you ran the initial `pod install` with new architecture enabled `RCT_NEW_ARCH_ENABLED=1`). d. Run `npm run ios` or build the project from Xcode. e. This last step should be significantly faster and you should see "Hits" under "Local storage" in the ccache stats approach 100%. Reviewed By: huntie Differential Revision: D52431507 Pulled By: cipolleschi fbshipit-source-id: 6cfe39acd6250fae03959f0ee74d1f2fc46b0827 Original: facebook/react-native@e85d51c
Summary: Building native modules from source, may take a long time. Xcode already helps bring this down, by providing incremental builds, as long as the user doesn't delete their `ios/build` directory. But in some situations, i.e. when iterating the native code of an app or library or when the developer need to delete that `ios/build` directory, it's advantageous to use a compiler cache, such as ccache. This is already outlined in our ["Speeding up your Build phase"](https://reactnative.dev/docs/build-speed#xcode-specific-setup) guide. But setting up an Xcode project to use Ccache with the correct configuration, isn't trivial in a way that doesn't require symlinking `clang` and `clang++` or passing configuration via environment variables on every `npm run ios` invokation. This PR takes its inspiration from the existing guide on [setting up Ccache for Xcode](https://reactnative.dev/docs/build-speed#xcode-specific-setup), but applies the build settings only if an installation of `ccache` is detected and the feature is explicitly opted into via an argument to the `react_native_post_install` function or a `USE_CCACHE` environment variable. It uses two shell scripts to wrap the call to `ccache`, which both injects a default `CCACHE_CONFIGPATH` environment variable (i.e. it won't override this if already provided, to allow for customisations on CI), pointing to a `ccache.config` which works well with React Native projects (it has the same values as the guide mentions). For context, I posted about this change in the ios channel of the contributors Discord server, where I discussed it with cipolleschi and saadnajmi ### Additional output printed when running `pod install` #### When `ccache_available and ccache_enabled` ``` [Ccache]: Ccache found at /opt/homebrew/bin/ccache [Ccache]: Setting CC, LD, CXX & LDPLUSPLUS build settings ``` #### When `ccache_available and !ccache_enabled` ``` [Ccache]: Ccache found at /opt/homebrew/bin/ccache [Ccache]: Pass ':ccache_enabled => true' to 'react_native_post_install' in your Podfile or set environment variable 'USE_CCACHE=1' to increase the speed of subsequent builds ``` #### When `!ccache_available and ccache_enabled` ``` [!] [Ccache]: Install ccache or ensure your neither passing ':ccache_enabled => true' nor setting environment variable 'USE_CCACHE=1' ``` #### Otherwise If the user doesn't have ccache installed and doesn't explicitly opt into this feature, nothing will be printed. bypass-github-export-checks ## Changelog: [IOS] [ADDED] - Added better support for `ccache`, to speed up subsequent builds of native code. After installing `ccache` and running `pod install`, the Xcode project is injected with compiler and linker build settings pointing scripts that loads a default Ccache configuration and invokes the `ccache` executable. Pull Request resolved: facebook/react-native#42051 Test Plan: I've tested this manually - would love some inspiration on how to automate this, if the reviewer deem it needed. To test this locally: 1. Install Ccache and make sure the `ccache` executable is in your `PATH` (verify by running `ccache --version`) 2. Create a new template app instance and apply the changes of this PR to the `node_modules/react-native` package. 3. Set the `USE_CCACHE` environment variable using `export USE_CCACHE=1`. 4. Run `pod install` in the `ios` directory. 5. Check the stats of Ccache (running `ccache -s`). 6. Run `npm run ios` or build the project from Xcode. 7. Check the Ccache stats again to verify ccache is intercepting compilation ("Cacheable calls" should ideally be 100%). 8. To check the speed gain: a. Delete the `ios/builds` directory b. Zero out the ccache stats (by running `ccache -z`) c. Run `pod install` again (only needed if you ran the initial `pod install` with new architecture enabled `RCT_NEW_ARCH_ENABLED=1`). d. Run `npm run ios` or build the project from Xcode. e. This last step should be significantly faster and you should see "Hits" under "Local storage" in the ccache stats approach 100%. Reviewed By: huntie Differential Revision: D52431507 Pulled By: cipolleschi fbshipit-source-id: 6cfe39acd6250fae03959f0ee74d1f2fc46b0827 Original-Commit: facebook/react-native@e85d51c
Summary: Building native modules from source, may take a long time. Xcode already helps bring this down, by providing incremental builds, as long as the user doesn't delete their `ios/build` directory. But in some situations, i.e. when iterating the native code of an app or library or when the developer need to delete that `ios/build` directory, it's advantageous to use a compiler cache, such as ccache. This is already outlined in our ["Speeding up your Build phase"](https://reactnative.dev/docs/build-speed#xcode-specific-setup) guide. But setting up an Xcode project to use Ccache with the correct configuration, isn't trivial in a way that doesn't require symlinking `clang` and `clang++` or passing configuration via environment variables on every `npm run ios` invokation. This PR takes its inspiration from the existing guide on [setting up Ccache for Xcode](https://reactnative.dev/docs/build-speed#xcode-specific-setup), but applies the build settings only if an installation of `ccache` is detected and the feature is explicitly opted into via an argument to the `react_native_post_install` function or a `USE_CCACHE` environment variable. It uses two shell scripts to wrap the call to `ccache`, which both injects a default `CCACHE_CONFIGPATH` environment variable (i.e. it won't override this if already provided, to allow for customisations on CI), pointing to a `ccache.config` which works well with React Native projects (it has the same values as the guide mentions). For context, I posted about this change in the ios channel of the contributors Discord server, where I discussed it with cipolleschi and saadnajmi ### Additional output printed when running `pod install` #### When `ccache_available and ccache_enabled` ``` [Ccache]: Ccache found at /opt/homebrew/bin/ccache [Ccache]: Setting CC, LD, CXX & LDPLUSPLUS build settings ``` #### When `ccache_available and !ccache_enabled` ``` [Ccache]: Ccache found at /opt/homebrew/bin/ccache [Ccache]: Pass ':ccache_enabled => true' to 'react_native_post_install' in your Podfile or set environment variable 'USE_CCACHE=1' to increase the speed of subsequent builds ``` #### When `!ccache_available and ccache_enabled` ``` [!] [Ccache]: Install ccache or ensure your neither passing ':ccache_enabled => true' nor setting environment variable 'USE_CCACHE=1' ``` #### Otherwise If the user doesn't have ccache installed and doesn't explicitly opt into this feature, nothing will be printed. bypass-github-export-checks ## Changelog: [IOS] [ADDED] - Added better support for `ccache`, to speed up subsequent builds of native code. After installing `ccache` and running `pod install`, the Xcode project is injected with compiler and linker build settings pointing scripts that loads a default Ccache configuration and invokes the `ccache` executable. Pull Request resolved: facebook/react-native#42051 Test Plan: I've tested this manually - would love some inspiration on how to automate this, if the reviewer deem it needed. To test this locally: 1. Install Ccache and make sure the `ccache` executable is in your `PATH` (verify by running `ccache --version`) 2. Create a new template app instance and apply the changes of this PR to the `node_modules/react-native` package. 3. Set the `USE_CCACHE` environment variable using `export USE_CCACHE=1`. 4. Run `pod install` in the `ios` directory. 5. Check the stats of Ccache (running `ccache -s`). 6. Run `npm run ios` or build the project from Xcode. 7. Check the Ccache stats again to verify ccache is intercepting compilation ("Cacheable calls" should ideally be 100%). 8. To check the speed gain: a. Delete the `ios/builds` directory b. Zero out the ccache stats (by running `ccache -z`) c. Run `pod install` again (only needed if you ran the initial `pod install` with new architecture enabled `RCT_NEW_ARCH_ENABLED=1`). d. Run `npm run ios` or build the project from Xcode. e. This last step should be significantly faster and you should see "Hits" under "Local storage" in the ccache stats approach 100%. Reviewed By: huntie Differential Revision: D52431507 Pulled By: cipolleschi fbshipit-source-id: 6cfe39acd6250fae03959f0ee74d1f2fc46b0827 Original-Commit: facebook/react-native@e85d51c
Summary:
Building native modules from source, may take a long time. Xcode already helps bring this down, by providing incremental builds, as long as the user doesn't delete their
ios/build
directory. But in some situations, i.e. when iterating the native code of an app or library or when the developer need to delete thatios/build
directory, it's advantageous to use a compiler cache, such as ccache. This is already outlined in our "Speeding up your Build phase" guide.But setting up an Xcode project to use Ccache with the correct configuration, isn't trivial in a way that doesn't require symlinking
clang
andclang++
or passing configuration via environment variables on everynpm run ios
invokation.This PR takes its inspiration from the existing guide on setting up Ccache for Xcode, but applies the build settings only if an installation of
ccache
is detected and the feature is explicitly opted into via an argument to thereact_native_post_install
function or aUSE_CCACHE
environment variable. It uses two shell scripts to wrap the call toccache
, which both injects a defaultCCACHE_CONFIGPATH
environment variable (i.e. it won't override this if already provided, to allow for customisations on CI), pointing to accache.config
which works well with React Native projects (it has the same values as the guide mentions).For context, I posted about this change in the ios channel of the contributors Discord server, where I discussed it with @cipolleschi and @Saadnajmi
Additional output printed when running
pod install
When
ccache_available and ccache_enabled
When
ccache_available and !ccache_enabled
When
!ccache_available and ccache_enabled
Otherwise
If the user doesn't have ccache installed and doesn't explicitly opt into this feature, nothing will be printed.
Changelog:
[IOS] [ADDED] - Added better support for
ccache
, to speed up subsequent builds of native code. After installingccache
and runningpod install
, the Xcode project is injected with compiler and linker build settings pointing scripts that loads a default Ccache configuration and invokes theccache
executable.Test Plan:
I've tested this manually - would love some inspiration on how to automate this, if the reviewer deem it needed.
To test this locally:
ccache
executable is in yourPATH
(verify by runningccache --version
)node_modules/react-native
package.USE_CCACHE
environment variable usingexport USE_CCACHE=1
.pod install
in theios
directory.ccache -s
).npm run ios
or build the project from Xcode.a. Delete the
ios/builds
directoryb. Zero out the ccache stats (by running
ccache -z
)c. Run
pod install
again (only needed if you ran the initialpod install
with new architecture enabledRCT_NEW_ARCH_ENABLED=1
).d. Run
npm run ios
or build the project from Xcode.e. This last step should be significantly faster and you should see "Hits" under "Local storage" in the ccache stats approach 100%.