Skip to content

Commit d135d34

Browse files
committed
Problem: App Store rejects app containing Rust with bitcode error
There is a python program used by Apple (included inside the Xcode.app bundle) which verifies a program's bitcode as part of rebuilding it. It includes a check that each bitcode object has valid clang parameters included as part of its XML xar header. The Rust compiler sensibly chooses not to emit any clang parameters, since it is not clang. Unfortunately this means any Rust-emitted bitcode will not pass app store verification. Locally, it produces an error like this one: ``` error: Clang option verification failed for bitcode 0038 (argument -emit-obj is required) ``` Through App Connect, it produces an error like this one: ``` ITMS-90562: Invalid Bundle - The app cannot be processed because options not allowed to be embedded in bitcode are detected in the submission ``` Solution: Patch Rust so that it will embed exactly the same clang cmdline that Xcode/clang will when emitting Bitcode. This patch is relatively brittle and not upstreamable in this form, but it serves well to demonstrate the problem and is likely to be a workable solution for now for anyone who wants to ship code.
1 parent 9a72808 commit d135d34

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

build.sh

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ cd rust
3838
git reset --hard
3939
git clean -f
4040
git checkout "$RUST_BRANCH"
41+
git apply ../../patches/rust_embed_cmdline.diff
4142
cd ..
4243
mkdir -p rust-build
4344
cd rust-build

config.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ RUST_BRANCH="tags/1.40.0"
1515
# 3. Select a name for the toolchain you want to install as. The toolchain will be installed
1616
# under $HOME/.rust-ios-arm64/toolchain-$RUST_TOOLCHAIN
1717

18-
RUST_TOOLCHAIN="1.40.0"
18+
RUST_TOOLCHAIN="1.40.0"
19+

patches/rust_embed_cmdline.diff

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
diff --git a/src/librustc_codegen_llvm/back/write.rs b/src/librustc_codegen_llvm/back/write.rs
2+
index 52f3a1cbb5c..6014a1d8ade 100644
3+
--- a/src/librustc_codegen_llvm/back/write.rs
4+
+++ b/src/librustc_codegen_llvm/back/write.rs
5+
@@ -686,7 +686,9 @@ unsafe fn embed_bitcode(cgcx: &CodegenContext<LlvmCodegenBackend>,
6+
llvm::LLVMRustSetLinkage(llglobal, llvm::Linkage::PrivateLinkage);
7+
llvm::LLVMSetGlobalConstant(llglobal, llvm::True);
8+
9+
- let llconst = common::bytes_in_context(llcx, &[]);
10+
+ let args = "-triple\0arm64-apple-ios11.0.0\0-emit-obj\0\
11+
+ -disable-llvm-passes\0-target-abi\0darwinpcs\0-Os\0";
12+
+ let llconst = common::bytes_in_context(llcx, args.as_bytes());
13+
let llglobal = llvm::LLVMAddGlobal(
14+
llmod,
15+
common::val_ty(llconst),

0 commit comments

Comments
 (0)