Swift Xcode Toolchain can not recognize custom -Xllvm option

xcode

(Tong Leiming) #1

I build Swift Xcode 10 toolchain, add a new pass with option, but Xcode report such message when archive:

swift (LLVM option parsing): Unknown command line argument '-xxxxxxx-combines'. Try: 'swift (LLVM option parsing) -help'
swift (LLVM option parsing): Did you mean '-expensive-combines'?

But I add an new option within the already existed pass in llvm/lib/transforms, such as:

static cl::opt
EnableExpensiveCombines("expensive-combines",
cl::desc("Enable expensive instruction combines"));

static cl::opt
EnableHehehe("hehehe-combines",
cl::desc("Enable hehehe combines"));

the upper option "expensive-combines" is already existed, the option "hehehe-combines" is my custom option. But when archiving, Xcode could recognize "-Xllvm -expensive-combines" but "-Xllvm -hehehe-combines".

I even modify option "expensive-combines" directly to another string "expensive-combines-xxx",but Xcode still could not recognize "-Xllvm -expensive-combines-xxx".

I can use swiftc from my built toolchain to compile with custom -Xllvm option successfully, but it fails when choosing the toolchain from Xcode.

So I want to know if Xcode 10 restrict the -Xllvm option to some specifie ones, if not, how to archive with custom -Xllvm option within Xcode 10?


(Jordan Rose) #2

I'm pretty sure Xcode won't let you Archive with a custom toolchain, so that people don't accidentally ship a binary built with a development snapshot version of Swift that might still have bugs in it.* I can't remember if Archive actions show up in the build log, but if they do, you can check to verify that it's still using the built-in toolchain.

* Yes, I know I set myself up for jokes here.


(Tong Leiming) #3

Thank you for your reply.

I have two toolchains, one for Swift and one for Objective-C. They are in the same directory path.
Here is the Objective-C project built log:

CompileC /Users/tom555cat/Library/Developer/Xcode/DerivedData/SimCheck1-bgsplhlrgcdogpbeyxsfcebzlisp/Build/Intermediates.noindex/ArchiveIntermediates/SimCheck1/IntermediateBuildFilesPath/SimCheck1.build/Release-iphoneos/SimCheck1.build/Objects-normal/arm64/main.o /Users/tom555cat/develop/SimCheck1/SimCheck1/main.m normal arm64 objective-c com.apple.compilers.llvm.clang.1_0.compiler (in target: SimCheck1)
cd /Users/tom555cat/develop/SimCheck1
export LANG=en_US.US-ASCII
/Library/Developer/Toolchains/Hikari.xctoolchain/usr/bin/clang -x ...

“/Library/Developer/Toolchains/Hikari.xctoolchain” is my Objective-C toolchain, and the custom llvm pass could run successfully.

Here is Swift Project built log:

CompileSwift normal armv7 (in target: SwfitTest123)
cd /Users/tom555cat/develop/SwfitTest123
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c ...

It uses the XcodeDefault.xctoolchain but not our swift toolchain although I specified it from Xcode-Toolchains as I specify the Objective-C toolchain.

It seems that Objective-C could use the custom toolchains but Swift could not.


(Jordan Rose) #4

I suspect this is a deliberate decision from the Xcode and App Store folks, since the Swift toolchain includes not just the compiler but also the standard library and overlays, which have executable code in them. Perhaps @eskimo knows if the policy on alternate toolchains is published somewhere public?


(Quinn “The Eskimo!”) #5

It’s definitely the case the App Store will only let you submit with final tools. Whether Xcode explicitly blocks Archive for pre-release toolchains, I don’t know )-:

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple