This is my personal memo to summarise a way to use self-build clang
tool chain with Xcode for Objective-C project. Probably we can take same approach for Swift project.
In this way, we can take many extra approaches like analyse source code, apply modifications on the source code (source-to-source translation,) and so on.
The tool chain, clang
for Apple platform is open sourced for Swift. First step is to have an environment that can build Apple’s clang
from its source code, coming with swift
.
Basically this is following the instruction on Swift.
First, install cmake
and ninja
.
$ brew install cmake ninja
Then create a working directory, like ~/apple
and shallow clone swift
.
$ mkdir ~/apple
$ cd ~/apple
$ git clone --depht 1 https://github.com/apple/swift.git
Run next command to shallow clone all dependencies that includes clang
.
$ ./swift/utils/update-checkout --clone --skip-history
Then, build it.
$ ./swift/utils/build-script --release-debuginfo
This is taking at least 1 hour on MacBook Pro (2017.)
Then, the binary will be placed in ~/apple/build
.
Download plugin and place it in /Applications/Xcode.app/Contents/PlugIns/Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-ins
.
Now we can build Objective-C project using our own tool chain. This means, we can inject our own clang
plugin, or use own static-analyser or modified version of clang
or anything.
Enjoy!