简体   繁体   中英

Enable Bitcode Output in Cargo Build for iOS Targets?

I'm building an iOS framework that uses some Rust libraries. Right now, the libraries are compiled to a static library. In order for me to enable bitcode (this is needed for Apple app thinning), the Rust libraries need to be built with bitcode enabled. I believe this would require the llvm flag: -fembed-bitcode . Is there any way to do this in Cargo?

You can tell cargo to pass any argument you wish to the Rust compiler by setting the RUSTFLAGS environment variable . The Rustc compiler has a flag -C llvm-args=val that you can use to pass additional arguments to llvm.

Thus, in your situation you would call:

RUSTFLAGS="-C llvm-args=\"-fembed-bitcode\"" cargo build

I suspect that this matter of creating a binary that is compatible with Apple's bitcode format for iOS will require direct modifications to the Rust compiler. Here's a recent link I found discussing the issue. The author of that repo would be a good resource to contact on iOS issues.

There are going to be multiple technical problems but the most fundamental is generating bitcode that is the same format as iOS expects. That problem can potentially be solved on a temporary basis by building a custom rustc using the same LLVM that Apple is using in clang.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM