Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell Xcode to emit IR (LLVM Bitcode) for Swift?

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.

like image 857
Jonas Avatar asked May 31 '16 09:05

Jonas


People also ask

What is bitcode LLVM?

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.


1 Answers

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.

like image 82
AlexDenisov Avatar answered Nov 01 '22 15:11

AlexDenisov