ios: Use compat to provide items missing from the iOS SDK

This updates the way that the .defs files added in 1bfd7d06ed60 are
treated, by putting them in compat/ios, using compat as intended. The
.defs files in compat forward, via #include, to the ones in
third_party/xnu. Additionally, compat/mac is enabled for iOS, as
everything in compat/mac is sensible on iOS, and will have no effect
when rendered unnecessary by the iOS SDK.

This also changes util:mig_output to a static_library instead of a
source_set. I don’t think there was any reason for it to have been a
source_set to begin with. static_library is preferred for nearly
everything.

Bug: crashpad:31
Change-Id: I4fe9fac31d23f9fb53490d7f4c0790cd2d20f2ff
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2160310
Reviewed-by: Justin Cohen <justincohen@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
GitOrigin-RevId: adfd94a35798b1cfaeeac59149f7ef093f8b2ad9
diff --git a/compat/BUILD.gn b/compat/BUILD.gn
index 2f24656..9c22acf 100644
--- a/compat/BUILD.gn
+++ b/compat/BUILD.gn
@@ -17,12 +17,16 @@
 config("compat_config") {
   include_dirs = []
 
-  if (crashpad_is_mac) {
+  if (crashpad_is_mac || crashpad_is_ios) {
     include_dirs += [ "mac" ]
-  } else if (!crashpad_is_ios) {
+  } else {
     include_dirs += [ "non_mac" ]
   }
 
+  if (crashpad_is_ios) {
+    include_dirs += [ "ios" ]
+  }
+
   if (crashpad_is_linux || crashpad_is_android) {
     include_dirs += [ "linux" ]
   }
@@ -59,15 +63,16 @@
 compat_target("compat") {
   sources = []
 
-  if (crashpad_is_mac) {
+  if (crashpad_is_mac || crashpad_is_ios) {
     sources += [
       "mac/AvailabilityMacros.h",
       "mac/kern/exc_resource.h",
       "mac/mach-o/loader.h",
+      "mac/mach/i386/thread_state.h",
       "mac/mach/mach.h",
       "mac/sys/resource.h",
     ]
-  } else if (!crashpad_is_ios) {
+  } else {
     sources += [
       "non_mac/mach-o/loader.h",
       "non_mac/mach/mach.h",
@@ -76,6 +81,16 @@
     ]
   }
 
+  if (crashpad_is_ios) {
+    sources += [
+      "ios/mach/exc.defs",
+      "ios/mach/mach_exc.defs",
+      "ios/mach/mach_types.defs",
+      "ios/mach/machine/machine_types.defs",
+      "ios/mach/std_types.defs",
+    ]
+  }
+
   if (crashpad_is_linux || crashpad_is_android) {
     sources += [
       "linux/signal.h",
diff --git a/compat/ios/mach/exc.defs b/compat/ios/mach/exc.defs
new file mode 100644
index 0000000..d1648e9
--- /dev/null
+++ b/compat/ios/mach/exc.defs
@@ -0,0 +1,20 @@
+// Copyright 2020 The Crashpad Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef CRASHPAD_COMPAT_IOS_MACH_EXC_DEFS_
+#define CRASHPAD_COMPAT_IOS_MACH_EXC_DEFS_
+
+#include "third_party/xnu/osfmk/mach/exc.defs"
+
+#endif  // CRASHPAD_COMPAT_IOS_MACH_EXC_DEFS_
diff --git a/compat/ios/mach/mach_exc.defs b/compat/ios/mach/mach_exc.defs
new file mode 100644
index 0000000..c562128
--- /dev/null
+++ b/compat/ios/mach/mach_exc.defs
@@ -0,0 +1,20 @@
+// Copyright 2020 The Crashpad Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef CRASHPAD_COMPAT_IOS_MACH_MACH_EXC_DEFS_
+#define CRASHPAD_COMPAT_IOS_MACH_MACH_EXC_DEFS_
+
+#include "third_party/xnu/osfmk/mach/mach_exc.defs"
+
+#endif  // CRASHPAD_COMPAT_IOS_MACH_MACH_EXC_DEFS_
diff --git a/compat/ios/mach/mach_types.defs b/compat/ios/mach/mach_types.defs
new file mode 100644
index 0000000..dc18b8e
--- /dev/null
+++ b/compat/ios/mach/mach_types.defs
@@ -0,0 +1,20 @@
+// Copyright 2020 The Crashpad Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef CRASHPAD_COMPAT_IOS_MACH_MACH_TYPES_DEFS_
+#define CRASHPAD_COMPAT_IOS_MACH_MACH_TYPES_DEFS_
+
+#include "third_party/xnu/osfmk/mach/mach_types.defs"
+
+#endif  // CRASHPAD_COMPAT_IOS_MACH_MACH_TYPES_DEFS_
diff --git a/compat/ios/mach/machine/machine_types.defs b/compat/ios/mach/machine/machine_types.defs
new file mode 100644
index 0000000..e906466
--- /dev/null
+++ b/compat/ios/mach/machine/machine_types.defs
@@ -0,0 +1,20 @@
+// Copyright 2020 The Crashpad Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef CRASHPAD_COMPAT_IOS_MACH_MACHINE_MACHINE_TYPES_DEFS_
+#define CRASHPAD_COMPAT_IOS_MACH_MACHINE_MACHINE_TYPES_DEFS_
+
+#include "third_party/xnu/osfmk/mach/machine/machine_types.defs"
+
+#endif  // CRASHPAD_COMPAT_IOS_MACH_MACHINE_MACHINE_TYPES_DEFS_
diff --git a/compat/ios/mach/std_types.defs b/compat/ios/mach/std_types.defs
new file mode 100644
index 0000000..e49c6e4
--- /dev/null
+++ b/compat/ios/mach/std_types.defs
@@ -0,0 +1,20 @@
+// Copyright 2020 The Crashpad Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef CRASHPAD_COMPAT_IOS_MACH_STD_TYPES_DEFS_
+#define CRASHPAD_COMPAT_IOS_MACH_STD_TYPES_DEFS_
+
+#include "third_party/xnu/osfmk/mach/std_types.defs"
+
+#endif  // CRASHPAD_COMPAT_IOS_MACH_STD_TYPES_DEFS_
diff --git a/util/BUILD.gn b/util/BUILD.gn
index c924b93..f291f5b 100644
--- a/util/BUILD.gn
+++ b/util/BUILD.gn
@@ -87,13 +87,14 @@
     }
     args += [
       "--include",
+      rebase_path("..", root_build_dir),
+      "--include",
       rebase_path("../compat/mac", root_build_dir),
     ]
     if (crashpad_is_ios) {
       args += [
-        # The iOS SDK doesn’t have any .defs files. Get them directly from xnu.
         "--include",
-        rebase_path("../third_party/xnu/osfmk", root_build_dir),
+        rebase_path("../compat/ios", root_build_dir),
       ]
     }
     if (current_cpu == "x86") {
@@ -119,7 +120,7 @@
     }
   }
 
-  source_set("mig_output") {
+  static_library("mig_output") {
     deps = [ ":mig" ]
     sources = get_target_outputs(":mig")
     if (crashpad_is_in_chromium) {