Skip to content

Commit 342aad1

Browse files
committed
Force embed-bitcode on non-simulator iOS/tvOS targets
At this time Apple recommends Bitcode be included for iOS apps, and requires it for tvOS. It is unlikely that a developer would want to disable bitcode when building for these targets, yet by default it will not be generated. This presents a papercut for developers on those platforms. Introduces a new TargetOption boolean key for specific triples to indicate that bitcode should be generated, even if cargo attempts to optimise with -Cembed-bitcode=no.
1 parent 43271a3 commit 342aad1

File tree

4 files changed

+9
-0
lines changed

4 files changed

+9
-0
lines changed

src/librustc_codegen_ssa/back/write.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ impl ModuleConfig {
147147
|| sess.opts.cg.linker_plugin_lto.enabled()
148148
{
149149
EmitObj::Bitcode
150+
} else if sess.target.target.options.forces_embed_bitcode {
151+
EmitObj::ObjectCode(BitcodeSection::Full)
150152
} else if need_crate_bitcode_for_rlib(sess) {
151153
let force_full = need_crate_bitcode_for_rlib(sess);
152154
match sess.opts.optimize {

src/librustc_target/spec/aarch64_apple_ios.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub fn target() -> TargetResult {
1919
eliminate_frame_pointer: false,
2020
max_atomic_width: Some(128),
2121
abi_blacklist: super::arm_base::abi_blacklist(),
22+
forces_embed_bitcode: true,
2223
..base
2324
},
2425
})

src/librustc_target/spec/aarch64_apple_tvos.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub fn target() -> TargetResult {
1919
eliminate_frame_pointer: false,
2020
max_atomic_width: Some(128),
2121
abi_blacklist: super::arm_base::abi_blacklist(),
22+
forces_embed_bitcode: true,
2223
..base
2324
},
2425
})

src/librustc_target/spec/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,8 @@ pub struct TargetOptions {
783783
// If we give emcc .o files that are actually .bc files it
784784
// will 'just work'.
785785
pub obj_is_bitcode: bool,
786+
/// Whether the target requires that emitted object code includes bitcode.
787+
pub forces_embed_bitcode: bool,
786788

787789
/// Don't use this field; instead use the `.min_atomic_width()` method.
788790
pub min_atomic_width: Option<u64>,
@@ -939,6 +941,7 @@ impl Default for TargetOptions {
939941
allow_asm: true,
940942
has_elf_tls: false,
941943
obj_is_bitcode: false,
944+
forces_embed_bitcode: false,
942945
min_atomic_width: None,
943946
max_atomic_width: None,
944947
atomic_cas: true,
@@ -1278,6 +1281,7 @@ impl Target {
12781281
key!(main_needs_argc_argv, bool);
12791282
key!(has_elf_tls, bool);
12801283
key!(obj_is_bitcode, bool);
1284+
key!(forces_embed_bitcode, bool);
12811285
key!(max_atomic_width, Option<u64>);
12821286
key!(min_atomic_width, Option<u64>);
12831287
key!(atomic_cas, bool);
@@ -1505,6 +1509,7 @@ impl ToJson for Target {
15051509
target_option_val!(main_needs_argc_argv);
15061510
target_option_val!(has_elf_tls);
15071511
target_option_val!(obj_is_bitcode);
1512+
target_option_val!(forces_embed_bitcode);
15081513
target_option_val!(min_atomic_width);
15091514
target_option_val!(max_atomic_width);
15101515
target_option_val!(atomic_cas);

0 commit comments

Comments
 (0)