Move win32 files to a new "win32" target to avoid cyclic dependencies.

I ran into this when using repeating_task, which depends on clock (in
system_wrappers) which in turn added a dependency on rtc_base on Windows
due to win32 files. That's a problem since rtc_base depends on
repeating_task:

  //rtc_base:rtc_base ->
  //rtc_base/task_utils:repeating_task ->
  //system_wrappers:system_wrappers ->
  //rtc_base:rtc_base

We could additionally consider moving Clock out of system_wrappers.

Bug: webrtc:9987
Change-Id: I54ed715ad5eb9e3f5dd6c322233c18c05d895dff
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/185506
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Tommi <tommi@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32203}
diff --git a/examples/BUILD.gn b/examples/BUILD.gn
index ad05571..86b06cd 100644
--- a/examples/BUILD.gn
+++ b/examples/BUILD.gn
@@ -689,7 +689,10 @@
         "peerconnection/client/main_wnd.h",
       ]
       configs += [ "//build/config/win:windowed" ]
-      deps += [ "../media:rtc_media_base" ]
+      deps += [
+        "../media:rtc_media_base",
+        "../rtc_base:win32",
+      ]
     }
     if (is_linux || is_chromeos) {
       sources += [
diff --git a/modules/audio_device/BUILD.gn b/modules/audio_device/BUILD.gn
index 819a866..4f701e4 100644
--- a/modules/audio_device/BUILD.gn
+++ b/modules/audio_device/BUILD.gn
@@ -317,6 +317,7 @@
           "msdmo.lib",
           "oleaut32.lib",
         ]
+        deps += [ "../../rtc_base:win32" ]
       }
       configs += [ ":audio_device_warnings_config" ]
     }
diff --git a/modules/desktop_capture/BUILD.gn b/modules/desktop_capture/BUILD.gn
index eb57a46..a45c339 100644
--- a/modules/desktop_capture/BUILD.gn
+++ b/modules/desktop_capture/BUILD.gn
@@ -76,6 +76,9 @@
         "window_finder_unittest.cc",
       ]
       public_configs = [ ":x11_config" ]
+      if (is_win) {
+        deps += [ "../../rtc_base:win32" ]
+      }
     }
   }
 
@@ -412,6 +415,21 @@
     ]
   }
 
+  deps = [
+    ":primitives",
+    "../../api:function_view",
+    "../../api:refcountedbase",
+    "../../api:scoped_refptr",
+    "../../rtc_base",  # TODO(kjellander): Cleanup in bugs.webrtc.org/3806.
+    "../../rtc_base:checks",
+    "../../rtc_base/synchronization:mutex",
+    "../../rtc_base/synchronization:rw_lock_wrapper",
+    "../../rtc_base/system:arch",
+    "../../rtc_base/system:rtc_export",
+    "../../system_wrappers",
+    "../../system_wrappers:metrics",
+  ]
+
   if (is_win) {
     sources += [
       "cropping_window_capturer_win.cc",
@@ -472,22 +490,9 @@
       "d3d11.lib",
       "dxgi.lib",
     ]
+    deps += [ "../../rtc_base:win32" ]
   }
 
-  deps = [
-    ":primitives",
-    "../../api:function_view",
-    "../../api:refcountedbase",
-    "../../api:scoped_refptr",
-    "../../rtc_base",  # TODO(kjellander): Cleanup in bugs.webrtc.org/3806.
-    "../../rtc_base:checks",
-    "../../rtc_base/synchronization:mutex",
-    "../../rtc_base/synchronization:rw_lock_wrapper",
-    "../../rtc_base/system:arch",
-    "../../rtc_base/system:rtc_export",
-    "../../system_wrappers",
-    "../../system_wrappers:metrics",
-  ]
   absl_deps = [
     "//third_party/abseil-cpp/absl/memory",
     "//third_party/abseil-cpp/absl/strings",
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
index 4e33aa5..e3b4581 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -784,12 +784,26 @@
 
 if (is_win) {
   rtc_source_set("win32") {
-    # TODO(bugs.webrtc.org/9987): This build target will soon contain
-    #                             the following files:
-    # sources = [
-    #   "win32.cc",
-    #   "win32.h",
-    # ]
+    sources = [
+      "win32.cc",
+      "win32.h",
+      "win32_window.cc",
+      "win32_window.h",
+    ]
+
+    deps = [
+      ":checks",
+      ":macromagic",
+      ":rtc_base_approved",
+    ]
+
+    libs = [
+      "crypt32.lib",
+      "iphlpapi.lib",
+      "secur32.lib",
+    ]
+
+    defines = [ "_CRT_NONSTDC_NO_DEPRECATE" ]
   }
 }
 
@@ -1004,20 +1018,7 @@
   }
 
   if (is_win) {
-    sources += [
-      "win32.cc",
-      "win32.h",
-      "win32_window.cc",
-      "win32_window.h",
-    ]
-
-    libs += [
-      "crypt32.lib",
-      "iphlpapi.lib",
-      "secur32.lib",
-    ]
-
-    defines += [ "_CRT_NONSTDC_NO_DEPRECATE" ]
+    deps += [ ":win32" ]
   }
 
   if (is_posix || is_fuchsia) {
@@ -1406,22 +1407,6 @@
       "thread_unittest.cc",
       "unique_id_generator_unittest.cc",
     ]
-    if (is_win) {
-      sources += [
-        "win32_unittest.cc",
-        "win32_window_unittest.cc",
-      ]
-    }
-    if (is_posix || is_fuchsia) {
-      sources += [
-        "openssl_adapter_unittest.cc",
-        "openssl_session_cache_unittest.cc",
-        "openssl_utility_unittest.cc",
-        "ssl_adapter_unittest.cc",
-        "ssl_identity_unittest.cc",
-        "ssl_stream_adapter_unittest.cc",
-      ]
-    }
     deps = [
       ":checks",
       ":gunit_helpers",
@@ -1442,6 +1427,23 @@
       "task_utils:to_queued_task",
       "third_party/sigslot",
     ]
+    if (is_win) {
+      sources += [
+        "win32_unittest.cc",
+        "win32_window_unittest.cc",
+      ]
+      deps += [ ":win32" ]
+    }
+    if (is_posix || is_fuchsia) {
+      sources += [
+        "openssl_adapter_unittest.cc",
+        "openssl_session_cache_unittest.cc",
+        "openssl_utility_unittest.cc",
+        "ssl_adapter_unittest.cc",
+        "ssl_identity_unittest.cc",
+        "ssl_stream_adapter_unittest.cc",
+      ]
+    }
     absl_deps = [
       "//third_party/abseil-cpp/absl/algorithm:container",
       "//third_party/abseil-cpp/absl/memory",
diff --git a/system_wrappers/BUILD.gn b/system_wrappers/BUILD.gn
index 769e530..b446648 100644
--- a/system_wrappers/BUILD.gn
+++ b/system_wrappers/BUILD.gn
@@ -71,7 +71,7 @@
 
     # Windows needs ../rtc_base due to include of
     # webrtc/rtc_base/win32.h in source/clock.cc.
-    deps += [ "../rtc_base" ]
+    deps += [ "../rtc_base:win32" ]
   }
 
   deps += [
diff --git a/test/BUILD.gn b/test/BUILD.gn
index 9cf5422..300a083 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -638,7 +638,7 @@
     deps += [ ":fileutils_mac_objc" ]
   }
   if (is_win) {
-    deps += [ "../rtc_base" ]
+    deps += [ "../rtc_base:win32" ]
   }
 }
 
@@ -667,7 +667,7 @@
     deps += [ ":fileutils_mac_objc" ]
   }
   if (is_win) {
-    deps += [ "../rtc_base" ]
+    deps += [ "../rtc_base:win32" ]
   }
 }