Skip to content

Instantly share code, notes, and snippets.

@niw
Last active December 5, 2019 13:39
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niw/1a7bc1e179686ad09ae35bf0d94a0b22 to your computer and use it in GitHub Desktop.
Save niw/1a7bc1e179686ad09ae35bf0d94a0b22 to your computer and use it in GitHub Desktop.
Using self-build toolchain with Xcode

Using self-build toolchain with Xcode

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.

Prepare a toolchain

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.

Prepare to build 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

Build Swift

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.

Install a plugin to Xcode

Download plugin and place it in /Applications/Xcode.app/Contents/PlugIns/Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-ins.

Next step

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment