Add RTC_EXPORT macro to export WebRTC symbols.

This CL introduces the utility macro RTC_EXPORT which will let WebRTC
developers decide which symbols are supposed to be exported/imported
and which ones are private.

RTC_EXPORT will only export/import symbols in a component build, more
info: https://cs.chromium.org/chromium/src/docs/component_build.md.
During a component build, the macro COMPONENT_BUILD will be globally
defined in a consistent fashion so it is safe to rely on it to
understand how to expand RTC_EXPORT.
In a non component build, RTC_EXPORT will expand to nothing.

Bug: webrtc:9419
Change-Id: Ic58162783be7f5883136ade27f324d6d34fdf932
Reviewed-on: https://webrtc-review.googlesource.com/97960
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Reviewed-by: Patrik Höglund <phoglund@webrtc.org>
Reviewed-by: Yves Gerey <yvesg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24757}
diff --git a/BUILD.gn b/BUILD.gn
index 418408b..3f06fa9 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -83,12 +83,21 @@
   }
 }
 
+config("library_impl_config") {
+  # Build targets that contain WebRTC implementation need this macro to
+  # be defined in order to correctly export symbols when is_component_build
+  # is true.
+  # For more info see: rtc_base/build/rtc_export.h.
+  defines = [ "WEBRTC_LIBRARY_IMPL" ]
+}
+
 # Contains the defines and includes in common.gypi that are duplicated both as
 # target_defaults and direct_dependent_settings.
 config("common_inherited_config") {
   defines = []
   cflags = []
   ldflags = []
+
   if (build_with_mozilla) {
     defines += [ "WEBRTC_MOZILLA_BUILD" ]
   }
diff --git a/rtc_base/build/BUILD.gn b/rtc_base/build/BUILD.gn
new file mode 100644
index 0000000..8635ad5
--- /dev/null
+++ b/rtc_base/build/BUILD.gn
@@ -0,0 +1,15 @@
+# Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
+#
+# Use of this source code is governed by a BSD-style license
+# that can be found in the LICENSE file in the root of the source
+# tree. An additional intellectual property rights grant can be found
+# in the file PATENTS.  All contributing project authors may
+# be found in the AUTHORS file in the root of the source tree.
+
+import("../../webrtc.gni")
+
+rtc_source_set("rtc_export") {
+  sources = [
+    "rtc_export.h",
+  ]
+}
diff --git a/rtc_base/build/rtc_export.h b/rtc_base/build/rtc_export.h
new file mode 100644
index 0000000..b3636fc
--- /dev/null
+++ b/rtc_base/build/rtc_export.h
@@ -0,0 +1,43 @@
+/*
+ *  Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef RTC_BASE_BUILD_RTC_EXPORT_H_
+#define RTC_BASE_BUILD_RTC_EXPORT_H_
+
+// RTC_EXPORT is used to mark symbols as exported or imported when WebRTC is
+// built or used as a shared library.
+// When WebRTC is built as a static library the RTC_EXPORT macro expands to
+// nothing.
+
+#ifdef COMPONENT_BUILD
+
+#ifdef WEBRTC_WIN
+
+#ifdef WEBRTC_LIBRARY_IMPL
+#define RTC_EXPORT __declspec(dllexport)
+#else
+#define RTC_EXPORT __declspec(dllimport)
+#endif
+
+#else  // WEBRTC_WIN
+
+#if __has_attribute(visibility) && defined(WEBRTC_LIBRARY_IMPL)
+#define RTC_EXPORT __attribute__((visibility("default")))
+#endif
+
+#endif  // WEBRTC_WIN
+
+#endif  // COMPONENT_BUILD
+
+#ifndef RTC_EXPORT
+#define RTC_EXPORT
+#endif
+
+#endif  // RTC_BASE_BUILD_RTC_EXPORT_H_
diff --git a/webrtc.gni b/webrtc.gni
index 150599f..dc0c7b5 100644
--- a/webrtc.gni
+++ b/webrtc.gni
@@ -279,6 +279,7 @@
 rtc_remove_configs = []
 rtc_add_configs = rtc_common_configs
 rtc_prod_configs = [ webrtc_root + ":rtc_prod_config" ]
+rtc_library_impl_config = [ webrtc_root + ":library_impl_config" ]
 
 set_defaults("rtc_test") {
   configs = rtc_add_configs
@@ -444,6 +445,7 @@
     }
 
     configs += invoker.configs
+    configs += rtc_library_impl_config
     configs -= rtc_remove_configs
     configs -= invoker.suppressed_configs
     public_configs = [
@@ -552,6 +554,7 @@
     }
 
     configs += invoker.configs
+    configs += rtc_library_impl_config
     configs -= rtc_remove_configs
     configs -= invoker.suppressed_configs
     public_configs = [