From df1a0923f1534a238e9773000dd03dd7b55e2c72 Mon Sep 17 00:00:00 2001
From: David Fifield <david@bamsoftware.com>
Date: Mon, 3 Dec 2018 21:03:16 -0700
Subject: [PATCH 1/6] Disable assertions that prevent cross-compiling for mac.

---
 config/BUILDCONFIG.gn  | 4 ++--
 toolchain/mac/BUILD.gn | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/build/config/BUILDCONFIG.gn b/build/config/BUILDCONFIG.gn
index 48ed140c7..15e06808c 100644
--- a/build/config/BUILDCONFIG.gn
+++ b/build/config/BUILDCONFIG.gn
@@ -238,8 +238,8 @@ if (target_os == "android") {
 } else if (target_os == "ios") {
   _default_toolchain = "//build/toolchain/mac:ios_clang_$target_cpu"
 } else if (target_os == "mac") {
-  assert(host_os == "mac", "Mac cross-compiles are unsupported.")
-  _default_toolchain = host_toolchain
+  # assert(host_os == "mac", "Mac cross-compiles are unsupported.")
+  _default_toolchain = "//build/toolchain/mac:clang_$host_cpu"
 } else if (target_os == "win") {
   # On Windows we use the same toolchain for host and target by default.
   # Beware, win cross builds mostly don't work yet, see docs/win_cross.md
diff --git a/build/toolchain/mac/BUILD.gn b/build/toolchain/mac/BUILD.gn
index fc113d6a3..7a0171700 100644
--- a/build/toolchain/mac/BUILD.gn
+++ b/build/toolchain/mac/BUILD.gn
@@ -14,7 +14,7 @@ if (is_ios) {
 import("//build/config/mac/mac_sdk.gni")
 import("//build/config/mac/symbols.gni")
 
-assert(host_os == "mac")
+# assert(host_os == "mac")
 
 import("//build/toolchain/cc_wrapper.gni")
 import("//build/toolchain/clang_static_analyzer.gni")
-- 
2.11.0

From c9cdc59ebb986392367115105ecbc1f5b511130d Mon Sep 17 00:00:00 2001
From: David Fifield <david@bamsoftware.com>
Date: Mon, 3 Dec 2018 21:04:26 -0700
Subject: [PATCH 2/6] Hardcode cross-compiling flags in config/mac/BUILD.gn.

The build system doesn't provide a general way to set flags externally.
"No way to provide extra CFLAGS/CXXFLAGS/LDFLAGS"
https://bugs.chromium.org/p/chromium/issues/detail?id=595653
---
 config/mac/BUILD.gn | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/build/config/mac/BUILD.gn b/build/config/mac/BUILD.gn
index 4c681e88c..26fbcac2b 100644
--- a/build/config/mac/BUILD.gn
+++ b/build/config/mac/BUILD.gn
@@ -57,6 +57,11 @@ config("runtime_library") {
     "-isysroot",
     rebase_path(sysroot, root_build_dir),
     "-mmacosx-version-min=$mac_deployment_target",
+    "-target",
+    "x86_64-apple-darwin11",
+    "-Wno-unknown-warning-option",
+    "-B",
+    "/var/tmp/dist/macosx-toolchain/cctools/bin",
   ]
 
   asmflags = common_flags
-- 
2.11.0

From 86d0882084c8b0595d693cce43e96b01182814b7 Mon Sep 17 00:00:00 2001
From: David Fifield <david@bamsoftware.com>
Date: Tue, 4 Dec 2018 07:37:42 +0000
Subject: [PATCH 3/6] Remove -instcombine-lower-dbg-declare=0 from cflags.

Not supported in our current version of llvm:
clang (LLVM option parsing): Unknown command line argument '-instcombine-lower-dbg-declare=0'.  Try: 'clang (LLVM option parsing) -help'
clang (LLVM option parsing): Did you mean '-combiner-use-tbaa=0'?
---
 config/compiler/BUILD.gn | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/config/compiler/BUILD.gn b/config/compiler/BUILD.gn
index a6ba4ea6..e775f9f5 100644
--- a/build/config/compiler/BUILD.gn
+++ b/build/config/compiler/BUILD.gn
@@ -427,10 +427,10 @@ config("compiler") {
   if (is_clang && !is_nacl && current_toolchain == host_toolchain &&
       target_os != "chromeos") {
     cflags += [
-      "-Xclang",
-      "-mllvm",
-      "-Xclang",
-      "-instcombine-lower-dbg-declare=0",
+      # "-Xclang",
+      # "-mllvm",
+      # "-Xclang",
+      # "-instcombine-lower-dbg-declare=0",
     ]
   }
 
-- 
2.11.0

From 96d243466006263e99b08ebf8b6085c60b736ccc Mon Sep 17 00:00:00 2001
From: David Fifield <david@bamsoftware.com>
Date: Mon, 3 Dec 2018 21:06:06 -0700
Subject: [PATCH 4/6] Port build/config/mac/plist_util.py to biplist.

So as not to require the plutil command. plutil was only being used to
convert between XML and binary plist formats, because versions of the
plistlib module before Python 3.4 only support the XML format. The
biplist library handles both formats natively.

FAILED: gen/webrtc/examples/AppRTCMobile_info_plist_merged.plist
python ../../build/config/mac/plist_util.py merge -f=xml1 -o=gen/webrtc/examples/AppRTCMobile_info_plist_merged.plist ../../build/config/mac/BuildInfo.plist ../../webrtc/examples/objc/AppRTCMobile/mac/Info.plist
Traceback (most recent call last):
  File "../../build/config/mac/plist_util.py", line 254, in <module>
    sys.exit(Main())
  File "../../build/config/mac/plist_util.py", line 250, in Main
    args.func(args)
  File "../../build/config/mac/plist_util.py", line 207, in _Execute
    data = MergePList(data, LoadPList(filename))
  File "../../build/config/mac/plist_util.py", line 121, in LoadPList
    subprocess.check_call(['plutil', '-convert', 'xml1', '-o', name, path])
  File "/usr/lib/python2.7/subprocess.py", line 535, in check_call
    retcode = call(*popenargs, **kwargs)
  File "/usr/lib/python2.7/subprocess.py", line 522, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
---
 config/mac/plist_util.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/build/config/mac/plist_util.py b/build/config/mac/plist_util.py
index bba0208a5..019dcf918 100644
--- a/build/config/mac/plist_util.py
+++ b/build/config/mac/plist_util.py
@@ -3,7 +3,7 @@
 # found in the LICENSE file.
 
 import argparse
-import plistlib
+import biplist
 import os
 import re
 import subprocess
@@ -89,6 +89,7 @@ def Interpolate(value, substitutions):
 
 def LoadPList(path):
   """Loads Plist at |path| and returns it as a dictionary."""
+  return biplist.readPlist(path)
   fd, name = tempfile.mkstemp()
   try:
     subprocess.check_call(['plutil', '-convert', 'xml1', '-o', name, path])
@@ -100,6 +101,7 @@ def LoadPList(path):
 
 def SavePList(path, format, data):
   """Saves |data| as a Plist to |path| in the specified |format|."""
+  return biplist.writePlist(data, path, {"xml1": False, "binary1": True}[format]) # doesn't handle "json" format
   fd, name = tempfile.mkstemp()
   try:
     # "plutil" does not replace the destination file but update it in place,
-- 
2.11.0

From eb3787dd670900cc2c3020c9323a9d95983c8887 Mon Sep 17 00:00:00 2001
From: David Fifield <david@bamsoftware.com>
Date: Tue, 4 Dec 2018 05:16:04 +0000
Subject: [PATCH 5/6] Override use_system_xcode=true.

---
 build_overrides/build.gni | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/build_overrides/build.gni b/build_overrides/build.gni
index 81cb3e73ae..b683ea850c 100644
--- a/build_overrides/build.gni
+++ b/build_overrides/build.gni
@@ -46,3 +46,5 @@ if (host_os == "mac") {
              "hermetic toolchain if the minimum OS version is not met.")
   use_system_xcode = _result == 0
 }
+
+use_system_xcode = true
-- 
2.11.0

From 5df71ea8f31fd25a05c6b6b881c8126b25b5475c Mon Sep 17 00:00:00 2001
From: David Fifield <david@bamsoftware.com>
Date: Mon, 3 Dec 2018 21:11:14 -0700
Subject: [PATCH 6/6] Disable the desktop_capture module.

It's causing an error related to CoreGraphics.h and hopefully we don't
need it.
---
 modules/BUILD.gn | 1 -
 1 file changed, 1 deletion(-)

diff --git a/modules/BUILD.gn b/modules/BUILD.gn
index 465f32d3c4..578cdbd57e 100644
--- a/modules/BUILD.gn
+++ b/modules/BUILD.gn
@@ -17,7 +17,6 @@ group("modules") {
     "audio_processing",
     "bitrate_controller",
     "congestion_controller",
-    "desktop_capture",
     "media_file",
     "pacing",
     "remote_bitrate_estimator",
-- 
2.11.0

