From 08f6b61639a864c7b994e9398d74a30d4d947f5c Mon Sep 17 00:00:00 2001
From: brave-builds <devops@brave.com>
Date: Mon, 28 Mar 2022 20:35:34 +0000
Subject: [PATCH] Uplift of #12774 (squashed) to release

---
 build/commands/lib/config.js | 6 ++----
 build/rust/config.gni        | 2 +-
 ios/BUILD.gn                 | 5 +++++
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/build/commands/lib/config.js b/build/commands/lib/config.js
index 1eb3fde893e3..a4ab49fdb427 100755
--- a/build/commands/lib/config.js
+++ b/build/commands/lib/config.js
@@ -440,9 +440,7 @@ Config.prototype.buildArgs = function () {
       args.target_environment = this.targetEnvironment
     }
     args.enable_dsyms = true
-    args.enable_stripping = !this.isDebug()
-    args.use_clang_coverage = false
-    args.use_lld = false
+    args.enable_stripping = !this.isComponentBuild()
     // Component builds are not supported for iOS:
     // https://chromium.googlesource.com/chromium/src/+/master/docs/component_build.md
     args.is_component_build = false
@@ -451,7 +449,7 @@ Config.prototype.buildArgs = function () {
     // DCHECK's crash on Static builds without allowing the debugger to continue
     // Can be removed when approprioate DCHECK's have been fixed:
     // https://github.com/brave/brave-browser/issues/10334
-    args.dcheck_always_on = this.isDebug()
+    args.dcheck_always_on = this.isComponentBuild()
 
     args.ios_enable_content_widget_extension = false
     args.ios_enable_search_widget_extension = false
diff --git a/build/rust/config.gni b/build/rust/config.gni
index 4935d0734cb1..a8a3d7b7228c 100644
--- a/build/rust/config.gni
+++ b/build/rust/config.gni
@@ -47,7 +47,7 @@ if (use_lto_in_rustc_linking) {
   rustflags += [ "-Clinker-plugin-lto" ]
 }
 
-if (!is_ios && !is_debug) {
+if (use_lld && !is_debug) {
   rustflags += [ "-Cembed-bitcode=yes" ]
   rustflags += [ "-Clto" ]
 }
diff --git a/ios/BUILD.gn b/ios/BUILD.gn
index 2dbecd6ec14f..00b4004a7158 100644
--- a/ios/BUILD.gn
+++ b/ios/BUILD.gn
@@ -8,6 +8,11 @@ import("//brave/ios/browser/api/url/headers.gni")
 import("//build/config/compiler/compiler.gni")
 import("//build/config/ios/rules.gni")
 
+# lld is required when building arm64 with optimization in order to avoid
+# runtime crashes
+assert(is_debug || current_cpu != "arm64" || use_lld,
+       "Optimized arm64 iOS builds require lld")
+
 config("internal_config") {
   visibility = [ ":*" ]
   ldflags =