I want Xcode to compile my Swift source files to bitcode (IR) instead of Mach-O objects. I'm aware that you can invoke the swift compiler with the emit-ir
flag, however adding this to the "Other Swift Flags" does not work for me. The flag is set for the initial call to swiftc
but it's not showing up as an argument in the subsequent calls made to swift
. As a result I get Mach-O 64-bit object
files.
For Objective-C I can simply achieve this by either adding the emit-llvm
flag to clang
or enabling LTO. What should I do for Swift?
I'm running the latest Xcode (7.3) with Swift 2.2.
EDIT: I figured out a workaround where I replace the swift compiler with a script that appends -emit-bc
to the argument list and forwards it to swiftc
. However, adding it to the Swift compiler flags in Xcode doesn't work either.
What is commonly known as the LLVM bitcode file format (also, sometimes anachronistically known as bytecode) is actually two things: a bitstream container format and an encoding of LLVM IR into the container format. The bitstream format is an abstract encoding of structured data, very similar to XML in some ways.
Swift frontend and Swift compiler both have a nice option -help-hidden
(clang has this option as well, btw).
Besides other hidden options there is one called -Xfrontend
.
You can use it to pass any parameters directly for the Swift compiler (swiftc
): -Xfrontend -emit-bc
.
It actually works, but it leads to linker errors since there are no object files anymore.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With