Skip to content

Commit

Permalink
Force embed-bitcode on non-simulator iOS/tvOS targets
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thombles committed May 7, 2020
1 parent 43271a3 commit 342aad1
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/librustc_codegen_ssa/back/write.rs
Expand Up @@ -147,6 +147,8 @@ impl ModuleConfig {
|| sess.opts.cg.linker_plugin_lto.enabled()
{
EmitObj::Bitcode
} else if sess.target.target.options.forces_embed_bitcode {
EmitObj::ObjectCode(BitcodeSection::Full)
} else if need_crate_bitcode_for_rlib(sess) {
let force_full = need_crate_bitcode_for_rlib(sess);
match sess.opts.optimize {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_target/spec/aarch64_apple_ios.rs
Expand Up @@ -19,6 +19,7 @@ pub fn target() -> TargetResult {
eliminate_frame_pointer: false,
max_atomic_width: Some(128),
abi_blacklist: super::arm_base::abi_blacklist(),
forces_embed_bitcode: true,
..base
},
})
Expand Down
1 change: 1 addition & 0 deletions src/librustc_target/spec/aarch64_apple_tvos.rs
Expand Up @@ -19,6 +19,7 @@ pub fn target() -> TargetResult {
eliminate_frame_pointer: false,
max_atomic_width: Some(128),
abi_blacklist: super::arm_base::abi_blacklist(),
forces_embed_bitcode: true,
..base
},
})
Expand Down
5 changes: 5 additions & 0 deletions src/librustc_target/spec/mod.rs
Expand Up @@ -783,6 +783,8 @@ pub struct TargetOptions {
// If we give emcc .o files that are actually .bc files it
// will 'just work'.
pub obj_is_bitcode: bool,
/// Whether the target requires that emitted object code includes bitcode.
pub forces_embed_bitcode: bool,

/// Don't use this field; instead use the `.min_atomic_width()` method.
pub min_atomic_width: Option<u64>,
Expand Down Expand Up @@ -939,6 +941,7 @@ impl Default for TargetOptions {
allow_asm: true,
has_elf_tls: false,
obj_is_bitcode: false,
forces_embed_bitcode: false,
min_atomic_width: None,
max_atomic_width: None,
atomic_cas: true,
Expand Down Expand Up @@ -1278,6 +1281,7 @@ impl Target {
key!(main_needs_argc_argv, bool);
key!(has_elf_tls, bool);
key!(obj_is_bitcode, bool);
key!(forces_embed_bitcode, bool);
key!(max_atomic_width, Option<u64>);
key!(min_atomic_width, Option<u64>);
key!(atomic_cas, bool);
Expand Down Expand Up @@ -1505,6 +1509,7 @@ impl ToJson for Target {
target_option_val!(main_needs_argc_argv);
target_option_val!(has_elf_tls);
target_option_val!(obj_is_bitcode);
target_option_val!(forces_embed_bitcode);
target_option_val!(min_atomic_width);
target_option_val!(max_atomic_width);
target_option_val!(atomic_cas);
Expand Down

0 comments on commit 342aad1

Please sign in to comment.