From 901aabf7d27b09219f8b121493e5a9a253e171be Mon Sep 17 00:00:00 2001 From: George Wright Date: Thu, 28 Jan 2021 15:14:10 -0800 Subject: [PATCH 1/2] Support iOS ARM64 simulator builds (#422) --- build/config/BUILDCONFIG.gn | 6 +++++- build/toolchain/clang.gni | 6 +++++- build/toolchain/mac/BUILD.gn | 25 +++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/build/config/BUILDCONFIG.gn b/build/config/BUILDCONFIG.gn index 44c276c80d..b43a3afb67 100644 --- a/build/config/BUILDCONFIG.gn +++ b/build/config/BUILDCONFIG.gn @@ -543,7 +543,11 @@ if (custom_toolchain != "") { import("//build/config/ios/ios_sdk.gni") # For use_ios_simulator host_toolchain = "//build/toolchain/mac:clang_$host_cpu" if (use_ios_simulator) { - set_default_toolchain("//build/toolchain/mac:ios_clang_x64") + if (target_cpu == "arm" || target_cpu == "arm64") { + set_default_toolchain("//build/toolchain/mac:ios_clang_arm_sim") + } else { + set_default_toolchain("//build/toolchain/mac:ios_clang_x64_sim") + } } else { set_default_toolchain("//build/toolchain/mac:ios_clang_arm") } diff --git a/build/toolchain/clang.gni b/build/toolchain/clang.gni index 021b141698..097b4ff384 100644 --- a/build/toolchain/clang.gni +++ b/build/toolchain/clang.gni @@ -2,6 +2,8 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. +import("//build/config/ios/ios_sdk.gni") # For use_ios_simulator + declare_args() { # Enable the optional type profiler in Clang, which will tag heap allocations # with the allocation type. @@ -26,5 +28,7 @@ declare_args() { # TODO(dnfield): We shouldn't need Xcode for bitcode_marker builds, but we do # until libpng and dart have explicitly added LLVM asm sections to their # assembly sources. https://github.com/flutter/flutter/issues/39281 - use_xcode = enable_bitcode + # TODO(gw280): Once our own copy of clang 12 is capable of building for arm64 simulator, + # we can safely remove the requirement that we use xcode for arm64 simulator builds. + use_xcode = enable_bitcode || (use_ios_simulator && (target_cpu == "arm" || target_cpu == "arm64")) } diff --git a/build/toolchain/mac/BUILD.gn b/build/toolchain/mac/BUILD.gn index 6b898234aa..742adcb71f 100644 --- a/build/toolchain/mac/BUILD.gn +++ b/build/toolchain/mac/BUILD.gn @@ -250,8 +250,29 @@ mac_toolchain("ios_clang_arm") { sysroot_flags = "-isysroot $ios_device_sdk_path -miphoneos-version-min=$ios_deployment_target" } -# Toolchain used for iOS simulator targets. -mac_toolchain("ios_clang_x64") { +# Toolchain used for iOS simulator targets (arm64). +mac_toolchain("ios_clang_arm_sim") { + toolchain_cpu = "arm" + toolchain_os = "mac" + if (!use_xcode) { + prefix = rebase_path(llvm_bin_path, root_build_dir) + ar = "$prefix/llvm-ar" + cc = "$prefix/clang" + cxx = "$prefix/clang++" + } else { + # TODO: https://github.com/harfbuzz/harfbuzz/issues/2834 + # harfbuzz has a non-fatal warning right now with Xcode 12 + ar = "ar" + cc = "clang" + cxx = "clang++" + } + ld = cxx + is_clang = true + sysroot_flags = "-isysroot $ios_simulator_sdk_path -mios-simulator-version-min=$ios_deployment_target" +} + +# Toolchain used for iOS simulator targets (x64). +mac_toolchain("ios_clang_x64_sim") { toolchain_cpu = "x64" toolchain_os = "mac" prefix = rebase_path(llvm_bin_path, root_build_dir) From e9e91e4164bb5e0ee20332dcea3bed22b426395e Mon Sep 17 00:00:00 2001 From: George Wright Date: Fri, 5 Feb 2021 11:54:08 -0800 Subject: [PATCH 2/2] Only set use_xcode if we're on Mac --- build/toolchain/clang.gni | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/build/toolchain/clang.gni b/build/toolchain/clang.gni index 097b4ff384..569fd779ae 100644 --- a/build/toolchain/clang.gni +++ b/build/toolchain/clang.gni @@ -2,7 +2,9 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -import("//build/config/ios/ios_sdk.gni") # For use_ios_simulator +if (is_mac) { + import("//build/config/ios/ios_sdk.gni") # For use_ios_simulator +} declare_args() { # Enable the optional type profiler in Clang, which will tag heap allocations @@ -30,5 +32,9 @@ declare_args() { # assembly sources. https://github.com/flutter/flutter/issues/39281 # TODO(gw280): Once our own copy of clang 12 is capable of building for arm64 simulator, # we can safely remove the requirement that we use xcode for arm64 simulator builds. - use_xcode = enable_bitcode || (use_ios_simulator && (target_cpu == "arm" || target_cpu == "arm64")) + if (is_mac) { + use_xcode = enable_bitcode || (use_ios_simulator && (target_cpu == "arm" || target_cpu == "arm64")) + } else { + use_xcode = false + } }