File: Xcode.md

package info (click to toggle)
sccache 0.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,028 kB
  • sloc: sh: 358; cpp: 112; perl: 68; makefile: 35; ansic: 31
file content (98 lines) | stat: -rw-r--r-- 3,257 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Using `sccache` with Xcode

It is possible to use `sccache` with Xcode with some setup.

### Running the daemon
Before building, you need to run the daemon outside of Xcode. This needs to be done because if `sccache` invocation happens to implicitly start the server daemon, the Xcode build will hang on the `sccache` invocation, waiting for the process to idle timeout.

You can do this in another terminal windows by calling
```sh
SCCACHE_LOG=info SCCACHE_START_SERVER=1 SCCACHE_NO_DAEMON=1 sccache
```

Or by setting it up in a `launchd` configuration, perhaps as `~/Library/LaunchAgents/sccache.plist` (note the paths in the plist):
```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>sccache.server</string>
    <key>ProgramArguments</key>
    <array>
      <string>/path/to/sccache</string>
    </array>
    <key>EnvironmentVariables</key>
    <dict>
        <key>SCCACHE_START_SERVER</key>
        <string>1</string>
        <key>SCCACHE_NO_DAEMON</key>
        <string>1</string>
        <key>SCCACHE_IDLE_TIMEOUT</key>
        <string>0</string>
        <key>SCCACHE_LOG</key>
        <string>info</string>
    </dict>

    <key>StandardOutPath</key>
    <string>/tmp/sccache.log</string>
    <key>StandardErrorPath</key>
    <string>/tmp/sccache.log</string>

  </dict>
</plist>
```

### Setting it up for `xcodebuild`

Xcode seems to support barely documented `C_COMPILER_LAUNCHER` attribute, for 
having a custom launcher program.

Then you can invoke `xcodebuild` like so
```sh
xcodebuild C_COMPILER_LAUNCHER=sccache
           CLANG_ENABLE_MODULES=NO
           COMPILER_INDEX_STORE_ENABLE=NO
           CLANG_USE_RESPONSE_FILE=NO
```
Where the additional arguments are for disabling some features that `sccache` can't cache currently.

These build settings can also be put in a xcconfig file, like `sccache.xcconfig`
```
C_COMPILER_LAUNCHER=sccache
CLANG_ENABLE_MODULES=NO
COMPILER_INDEX_STORE_ENABLE=NO
CLANG_USE_RESPONSE_FILE=NO
```
Which can then be invoked with
```sh
xcodebuild -xcconfig sccache.xcconfig
```


### Setting it up for `cmake` Xcode generator
While `cmake` has the convenient `CMAKE_<LANG>_COMPILER_LAUNCHER` for prepending tools like `sccache`, it is not supported for the Xcode generator.

But you can configuring it directly with something like
```cmake

# This bit before the first `project()`, as the COMPILER_LAUNCHER variables are read in then
if(DEFINED CCACHE)
    find_program(CCACHE_EXE ${CCACHE} REQUIRED)
    if(NOT CMAKE_GENERATOR STREQUAL "Xcode")
        # Support for other generators should work with these
        set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_EXE}")
        set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_EXE}")
    else()
        # And this should work for Xcode generator
        set(CMAKE_XCODE_ATTRIBUTE_C_COMPILER_LAUNCHER ${CCACHE_EXE})
        set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_MODULES "NO")
        set(CMAKE_XCODE_ATTRIBUTE_COMPILER_INDEX_STORE_ENABLE "NO")
        set(CMAKE_XCODE_ATTRIBUTE_CLANG_USE_RESPONSE_FILE "NO")
    endif()
endif()
```
Then configuring with `-DCCACHE=sccache` should work on all generators.