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 identifierDisplayName
: 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 addCompatibilityVersion
key toToolchainInfo.plist
and set the value is2
withNumber
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 tocom.applex.dt.toolchain.Xcode9
- Add
CompatibilityVersion
key and set value is 2 withNumber
type. - Add
DisplayName
key and set value isXcode 9.4.1
withString
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 toLLVM7.xctoolchain
and change the value of Identifier toorg.llvm.release.7.0.0
- Add
CompatibilityVersion
key and set value is 2 withNumber
type. - Add
DisplayName
key and set value isLLVM 7.0.0
withString
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