Replies: 11 comments 42 replies
-
Please help each other here! If you have gotten this working but only after fixing "this one thing..." posting that one thing may save someone else. So far these items were mentioned in the issue I pulled this out of:
Cheers |
Beta Was this translation helpful? Give feedback.
-
Thanks for your sharing, I am using Codemagic for my project, I already tried to setup my CI with
My
|
Beta Was this translation helpful? Give feedback.
-
How would using ccache work on a CI provider, such as CodeMagic? I currently use (well, used to) the Pod version - which "just worked" there. I don't have the option of overriding gcc etc. on such hosts. |
Beta Was this translation helpful? Give feedback.
-
@mikehardy is the 🐐 I followed the directions and the only thing that looked different was in the symbolic link step (although everything worked anyway once I ran In your directions it said to link to It still worked though. Build times don't make my eyes bleed anymore, the original
|
Beta Was this translation helpful? Give feedback.
-
Thank you for this instruction. It worked very well for me.
|
Beta Was this translation helpful? Give feedback.
-
It seems like mine is not using ccache, its missing due to not being able to load the modules, what might be the reason?
Here's my config
|
Beta Was this translation helpful? Give feedback.
-
I appreciate the assistance here but I'm not going to setup ccache just to get a firebase dependency to build in a reasonable amount of time. I really think we should rethink suggesting this is an acceptable path forward here. All these layers of complexity to achieve a baseline developer experience are getting too expensive compared to pure dart alternatives from other BaaS offerings |
Beta Was this translation helpful? Give feedback.
-
Thanks for sharing, this one same life :) |
Beta Was this translation helpful? Give feedback.
-
My output of
Not sure what am I doing wrong. I am using an M1 mac, installed ccache through homebrew
My ~/.zshrc
pod file includes
But my build time has decreased almost 10X nonetheless, from 214s to 21s. Probably some caching done by XCode itself since I don't see ccache working. Any help would be appreciated! |
Beta Was this translation helpful? Give feedback.
-
@mikehardy I do have one more comment on this. using ccache did reduce the compilation time, but whenever we switch branch and do pod install, that time has increased. Did anyone else experience the same? |
Beta Was this translation helpful? Give feedback.
-
Thank you for these instructions they work wonders ! I was wondering if the same ccache could be shared across different applications. In my specific case I have a white label app with many different ios schemes and they seem to be using different caches (building a new scheme nevers hits anything in cache but building a previously cached scheme hits). Is there a way to configure ccache so that it uses the same cache for all the different schemes ? In case it is useful:
|
Beta Was this translation helpful? Give feedback.
-
Hello! This is a discussion to introduce the idea of ccache and help people integrate it in place of using this pod
Basic knowledge to start:
Okay, so with the basic knowledge out of the way. If you want to try ccache, here's what you need:
install ccache
brew install ccache
should be sufficientTest: at this point if you run
which ccache
, it should point to the ccache install andccache --version
orccache -s
should work.link ccache to compiler names
ccache works by transparently pretending to be xcodebuild's binaries. So when you call "ld" or "cc", you get ccache first - where it has an opportunity to supply a previously-compiled object. It will then delegate to the underlying xcodebuild tools if that doesn't work, cache the object, then return it.
This is done by making symbolic links in a location in your PATH to the ccache binary. If we assume
/usr/local/bin
is in your PATH, then this should work:In github CI, the ccache-action will do this for you if you use it.
If you used
brew
to installccache
, then as @grundid mentions below, there are already symbolic links in a directory ready for you - you just need to prepend(brew --prefix)/opt/ccache/libexec
to your PATHTest: At this point if you
which ld
it should point to your symbolic link (for example,/usr/local/bin/ld
). Success! But, if you run a build, and then runccache -s
to look at cache statistics you should see that ccache has 0 hits and 0 misses though - nothing is using it yet.Instruct Xcode to use the symbolic links
Xcode, by default, uses "fully-specified paths" to it's tools (clang, clang++ etc) meaning that your new symbolic links that use ccache are not used.
To get Xcode to use ccache first instead of it's own tools, you use a Podfile
post_install
hook that tells Xcode to use relative (not fully-specified) names for it's compiler and linker. Now for people building your app that have ccache installed and in their PATH, Xcode will use ccache. For people that do not have ccache installed, the build will still work, just without any compilation speedup.The modification should look like this:
You will need to run
pod install
after making this change, as post_install only happens during a pod installation run.It is also possible to use environment variables defined on the same command line that runs the build, instructing Xcode to use non-fully-specified names for clang etc, which should then resolve to your ccache symbolic links assuming your PATH is configured correctly as verified by the
which
tests above. Here is an example using environment variables.Test: at this point if you run a build, then run
ccache -s
you should see lots of calls to ccache, but there should be 0 hits, and all misses.If you see 0 hits and 0 misses, you need to figure out why ccache is not even called - re-examine your ccache installation + link + PATH steps, and your Xcode build configuration to make sure ccache is where you think it is, the build tool names are in your PATH first, and Xcode is configured to use non-fully-qualified names.
Configure ccache for iOS builds
ccache by default does not cache objects built the way react-native and Flutter call the compiler, so you have to toggle a few things to make ccache accept that you want to cache the objects.
If you turn on ccache debugging or run
ccache -s
to see statistics, you will note that even with ccache installed, in your PATH, and Xcode using relative paths, ccache is only registering misses.The specific ccache configuration that should work for these iOS builds is:
You may set these in Github Actions workflows in the same step that does the compile or you may set them in your local shell environment.
Alternatively you may wish to configure them in
~/.ccache/ccache.conf
like so:Test: if you run
ccache -p
it should show these new values for the various things we configure, and if you run a build then runccache -s
you should see misses the first run and hits the second run. Congratulations! ccache is now able to optimize your builds.Preserve the cache
This is primarily for users in CI.
The first build in any environment with ccache will always be "cold", and not give you any performance benefit as the cache is empty.
The only way to have a "warm" build that is fast and uses a populated cache is to make sure you use the same cache directory between runs.
In CI environments where you have a different virtual machine every time, you need to make use of your CI provider's specific caching mechanism to save the
~/.ccache
after the compile and restore it before the compile between runs.In Github Workflows, the ccache-action handles this for you, but you will need to handle it yourself in other environments, using whatever caching facilities they provide
Example
Here is an example using ccache for firebase iOS builds in Github Actions:
Other guides
Others have written of ccache before (in fact, the react-native guide was originally written by me 👋 😆 )
These other guides may be useful:
Troubleshoot
If you have any difficulties and are unsure why there are misses, carefully check each step above running the "test" for each step to make sure ccache is set up correctly at each step of the way.
If ccache is definitely executing but still 100% misses, you may try turning on ccache logging and examining why or why not ccache decides to cache things. The ccache manual is instructive, as is this article https://interrupt.memfault.com/blog/ccache-debugging
Beta Was this translation helpful? Give feedback.
All reactions