-
Notifications
You must be signed in to change notification settings - Fork 552
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
Implement features required by Xcode #2257
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0520e79
Mark `-index-store-path` as Hard
scoopr 157db95
Mark serialize-diagnostics and deps as artifacts
scoopr b59823c
Update tests for the dep changes
scoopr 662bd4d
Add test for `-index-store-path`
scoopr dfe8c5b
Add documentation for Xcode use
scoopr 9325b87
Xcode integration test
scoopr 0c8a7e2
Add comment about wrapper script use
scoopr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# 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` | ||
When you override the `CC` variable for `xcodebuild`, it seems to always escape the spaces, so its not enough to just set it, but we need a wrapper script, something like | ||
|
||
```sh | ||
echo "#\!/bin/sh\nsccache $(xcrun -f cc) \$@" > wrapper.sh | ||
chmod +x wrapper.sh | ||
``` | ||
(YMMV if you need to select another sdk or toolchain for the xcrun) | ||
|
||
Then you can invoke `xcodebuild` like so | ||
```sh | ||
xcodebuild CC="$(pwd)/wrapper.sh" | ||
CLANG_ENABLE_MODULES=NO | ||
COMPILER_INDEX_STORE_ENABLE=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` | ||
``` | ||
CC=$(SRCROOT)/wrapper.sh | ||
CLANG_ENABLE_MODULES=NO | ||
COMPILER_INDEX_STORE_ENABLE=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. | ||
|
||
It can be then integrated with having a template file for the wrapper script, `launcher.sh.in`: | ||
```sh | ||
#!/bin/sh | ||
exec "${CCACHE_EXE}" "${LAUNCHER_COMPILER}" "$@" | ||
``` | ||
|
||
And then configuring it 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}") | ||
endif() | ||
endif() | ||
|
||
# .. your project stuff .. | ||
|
||
# This bit needs to be after the first `project()` call, to have valid `CMAKE_C_COMPILER` variable. | ||
# Alternatively in a file included with CMAKE_PROJECT_INCLUDE | ||
if(DEFINED CCACHE) | ||
if(CMAKE_GENERATOR STREQUAL "Xcode") | ||
set(LAUNCHER_COMPILER ${CMAKE_C_COMPILER}) | ||
configure_file(${CMAKE_CURRENT_LIST_DIR}/launcher.sh.in launcher-cc.sh) | ||
execute_process(COMMAND chmod a+rx | ||
"${CMAKE_CURRENT_BINARY_DIR}/launcher-cc.sh") | ||
set(CMAKE_XCODE_ATTRIBUTE_CC "${CMAKE_CURRENT_BINARY_DIR}/launcher-cc.sh") | ||
set(CMAKE_XCODE_ATTRIBUTE_CLANG_ENABLE_MODULES "NO") | ||
set(CMAKE_XCODE_ATTRIBUTE_COMPILER_INDEX_STORE_ENABLE "NO") | ||
endif() | ||
endif() | ||
``` | ||
Then configuring with `-DCCACHE=sccache` should work on all generators. | ||
|
||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
could you please add a comment explaining why a wrapper script is needed
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.
Its actually explained in the docs (dfe8c5b#diff-8f7ae669918b1de5a217f0f28f8becd7d0f92625c4b8334b733315b8199dd102R47), but I guess I could add a comment here.
The issue is that I can't just set
CC="sccache clang++"
, because it interprets the wholeCC
variable as a command, so its searching for a file calledsccache clang++
(so space is part of the command name). If you have other ideas for a workaround, I'm all ears.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.
yeah but i would prefer to have it next to the code :)