From e1913587889b0b1147531c370d9c810b46b5971e Mon Sep 17 00:00:00 2001 From: aspen Date: Tue, 30 Jun 2020 17:21:49 -0400 Subject: [PATCH 1/6] Changes required for rustc/cargo to build for iOS targets --- src/bootstrap/lib.rs | 5 +++++ src/bootstrap/native.rs | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index b611af54565ac..b11a7fc6255f3 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -811,6 +811,11 @@ impl Build { if target.contains("apple-darwin") { base.push("-stdlib=libc++".into()); } + + // Required for LLVM to properly compile. + if target.contains("apple-ios") { + base.push("-miphoneos-version-min=10.0".into()); + } // Work around an apparently bad MinGW / GCC optimization, // See: http://lists.llvm.org/pipermail/cfe-dev/2016-December/051980.html diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 106db90b2d0f0..e35ffb304bcfa 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -175,6 +175,14 @@ impl Step for Llvm { cfg.define("LLVM_ENABLE_ZLIB", "OFF"); } + // Are we compiling for iOS/tvOS? + if target.contains("apple") && !target.contains("darwin") { + cfg.define("CMAKE_OSX_SYSROOT", "/"); + cfg.define("CMAKE_OSX_DEPLOYMENT_TARGET", ""); + cfg.define("LLVM_ENABLE_PLUGINS", "OFF"); // Prevent cmake from adding -bundle to CFLAGS automatically. + cfg.define("LLVM_ENABLE_ZLIB", "OFF"); + } + if builder.config.llvm_thin_lto { cfg.define("LLVM_ENABLE_LTO", "Thin"); if !target.contains("apple") { From c22bcb03814a1600d17097123813495ea0a40796 Mon Sep 17 00:00:00 2001 From: aspen Date: Tue, 30 Jun 2020 17:56:31 -0400 Subject: [PATCH 2/6] Only set the flag in LLVM builds. --- src/bootstrap/lib.rs | 5 ----- src/bootstrap/native.rs | 3 +++ 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index b11a7fc6255f3..b611af54565ac 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -811,11 +811,6 @@ impl Build { if target.contains("apple-darwin") { base.push("-stdlib=libc++".into()); } - - // Required for LLVM to properly compile. - if target.contains("apple-ios") { - base.push("-miphoneos-version-min=10.0".into()); - } // Work around an apparently bad MinGW / GCC optimization, // See: http://lists.llvm.org/pipermail/cfe-dev/2016-December/051980.html diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index e35ffb304bcfa..c10e8723422a9 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -420,6 +420,9 @@ fn configure_cmake( if let Some(ref s) = builder.config.llvm_cflags { cflags.push_str(&format!(" {}", s)); } + if target.contains("apple-ios") { + cflags.push_str(" -miphoneos-version-min=10.0"); + } cfg.define("CMAKE_C_FLAGS", cflags); let mut cxxflags = builder.cflags(target, GitRepo::Llvm).join(" "); if builder.config.llvm_static_stdcpp && !target.contains("msvc") && !target.contains("netbsd") { From 5f3dbd83af1a2872ec2514ea1a18116b800e4aeb Mon Sep 17 00:00:00 2001 From: aspen Date: Tue, 30 Jun 2020 18:18:19 -0400 Subject: [PATCH 3/6] Don't break on iOS Simulator builds. --- src/bootstrap/native.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index c10e8723422a9..8d50dd0a9043b 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -421,7 +421,11 @@ fn configure_cmake( cflags.push_str(&format!(" {}", s)); } if target.contains("apple-ios") { - cflags.push_str(" -miphoneos-version-min=10.0"); + if target.contains("86-") { + cflags.push_str(" -miphonesimulator-version-min=10.0"); + } else { + cflags.push_str(" -miphoneos-version-min=10.0"); + } } cfg.define("CMAKE_C_FLAGS", cflags); let mut cxxflags = builder.cflags(target, GitRepo::Llvm).join(" "); From 4fd1c77a24288383600b02a7e3f11bf5eb718a32 Mon Sep 17 00:00:00 2001 From: aspen Date: Wed, 1 Jul 2020 12:15:24 -0400 Subject: [PATCH 4/6] Document the CMake defines. --- src/bootstrap/native.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 8d50dd0a9043b..fe1891f3ddf5f 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -177,9 +177,12 @@ impl Step for Llvm { // Are we compiling for iOS/tvOS? if target.contains("apple") && !target.contains("darwin") { + // These two defines prevent CMake from automatically trying to add a MacOSX sysroot, which leads to a compiler error. cfg.define("CMAKE_OSX_SYSROOT", "/"); cfg.define("CMAKE_OSX_DEPLOYMENT_TARGET", ""); - cfg.define("LLVM_ENABLE_PLUGINS", "OFF"); // Prevent cmake from adding -bundle to CFLAGS automatically. + // Prevent cmake from adding -bundle to CFLAGS automatically, which leads to a compiler error because "-bitcode_bundle" also gets added. + cfg.define("LLVM_ENABLE_PLUGINS", "OFF"); + // Zlib fails to link properly, leading to a compiler error. cfg.define("LLVM_ENABLE_ZLIB", "OFF"); } From 22e8ced9fd3ca7767c1ed479d736358b190bf22d Mon Sep 17 00:00:00 2001 From: aspen Date: Wed, 1 Jul 2020 12:21:48 -0400 Subject: [PATCH 5/6] Also document iphoneos-version-min. --- src/bootstrap/native.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index fe1891f3ddf5f..70c292e229da8 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -423,6 +423,7 @@ fn configure_cmake( if let Some(ref s) = builder.config.llvm_cflags { cflags.push_str(&format!(" {}", s)); } + // Some compiler features used by LLVM (such as thread locals) will not work on a min version below iOS 10. if target.contains("apple-ios") { if target.contains("86-") { cflags.push_str(" -miphonesimulator-version-min=10.0"); From 67b162f043e7e52e71b7ae8bbbdb0a732ec85eb1 Mon Sep 17 00:00:00 2001 From: aspen Date: Wed, 1 Jul 2020 13:19:09 -0400 Subject: [PATCH 6/6] Explicitly check for iOS/tvOS. --- src/bootstrap/native.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index 70c292e229da8..cceb794165059 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -176,7 +176,7 @@ impl Step for Llvm { } // Are we compiling for iOS/tvOS? - if target.contains("apple") && !target.contains("darwin") { + if target.contains("apple-ios") || target.contains("apple-tvos") { // These two defines prevent CMake from automatically trying to add a MacOSX sysroot, which leads to a compiler error. cfg.define("CMAKE_OSX_SYSROOT", "/"); cfg.define("CMAKE_OSX_DEPLOYMENT_TARGET", "");