Change toolchain for Xcode

Dec 20, 2018 • 预计阅读时间 2 分钟

Change toolchain for Xcode

something about Xcode toolchian:

  • Default toolchain location is /Applications/Xcode.app/Contents/Developer/Toolchains
  • Extension of xcode toolchain bundle is .xctoolchain
  • Display name and identifier of toolchain is defined in .xctoolchain/ToolchainInfo.plist
  • CFBundleIdentifier : toolchain bundle identifier
  • DisplayName : name displayed in Xcode menu
  • All binaries, headers, libs etc in .xctoolchain/usr
  • From menu Xcode - Toolchains to switch toolchians
  • If you want install toolchain out of Xcode, the location is /Library/Developer/Toolchains
  • If your toolchain is installed in /Library/Developer/Toolchains, must add CompatibilityVersion key to ToolchainInfo.plist and set the value is 2 with Number type.
  • More about information of toolchain, you can learn from toolchain of swift

Note: any applications builded with toolchain installed at /Library/Developer/Toolchains can not be uploaded to AppStore.

Use different toolchain version of Xcode

example for Xcode 10 with toolchain of Xcode 9.4.1

  • Rname XcodeDefault.xctoolchain to Xcode9.xctoolchain
  • Edit Xcode9.xctoolchain/ToolchainInfo.plist, change value of Identifier to com.applex.dt.toolchain.Xcode9
  • Add CompatibilityVersion key and set value is 2 with Number type.
  • Add DisplayName key and set value is Xcode 9.4.1 with String type.
  • Move Xcode9.xctoolchain to /Applications/Xcode.app/Contents/Developer/Toolchains

Note: if Xcode9.xctoolchain installed at /Library/Developer/Toolchains, value of CFBundleIdentifier can not has the prefix com.apple.*.

Use toolchain of LLVM for Xcode

example for LLVM 7.0.0

  • Download Pre-Built Binaries from llvm.org
  • Unzip it tar xvJf clang+llvm-7.0.0-x86_64-apple-darwin.tar.xz
  • Create a empty toolchain bundle mkdir LLVM7.xctoolchain
  • Move llvm to bundle mv clang+llvm-7.0.0-x86_64-apple-darwin LLVM7.xctoolchain/usr
  • Copy a ToolchainInfo.plist from Xcode to LLVM7.xctoolchain and change the value of Identifier to org.llvm.release.7.0.0
  • Add CompatibilityVersion key and set value is 2 with Number type.
  • Add DisplayName key and set value is LLVM 7.0.0 with String type.
  • Move LLVM7.xctoolchain to /Applications/Xcode.app/Contents/Developer/Toolchains
  • [Optional] add support ARC static lib ln -s /Path/to/Xcode9.4.1.xctoolchain/usr/lib/arc /Path/to/LLVM7.xctoolchain/usr/lib

Note: need disable COMPILER_INDEX_STORE_ENABLE in Build Settings when build with LLVM Clang

xcodebuild

example xcodebuild with toolchain.

#!/bin/bash
set -e

# Install path of Xcode.app
export DEVELOPER_DIR=/Applications/Xcode.app
# Identifier of toolchain defined in ToolchainInfo.plist
export TOOLCHAINS=com.apple.dt.toolchain.XcodeDefault

time xcodebuild -workspace yourproj.xcworkspace -scheme yourscheme

Enjoy it

版权声明:如果转发请带上本文链接和注明来源。

lvv.me

iOS/macOS Developer

Get free SSL/TLS Certificates from Let's Encrypt

Calc NSAttributedString size correctly with NSLayoutManager