From 55daf1aef65218a97eff88999e5190a2f2f6b72e Mon Sep 17 00:00:00 2001 From: Mirko Bonadei Date: Mon, 17 Sep 2018 13:48:44 +0200 Subject: [PATCH] Add RTC_EXPORT macro to export WebRTC symbols. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Karl Wiberg Reviewed-by: Niels Moller Reviewed-by: Patrik Höglund Reviewed-by: Yves Gerey Cr-Commit-Position: refs/heads/master@{#24757} --- BUILD.gn | 9 ++++++++ rtc_base/build/BUILD.gn | 15 +++++++++++++ rtc_base/build/rtc_export.h | 43 +++++++++++++++++++++++++++++++++++++ webrtc.gni | 3 +++ 4 files changed, 70 insertions(+) create mode 100644 rtc_base/build/BUILD.gn create mode 100644 rtc_base/build/rtc_export.h diff --git a/BUILD.gn b/BUILD.gn index 418408b7fa..3f06fa9da4 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -83,12 +83,21 @@ if (!build_with_chromium) { } } +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 0000000000..8635ad5518 --- /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 0000000000..b3636fcec9 --- /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 150599f8e9..dc0c7b5c00 100644 --- a/webrtc.gni +++ b/webrtc.gni @@ -279,6 +279,7 @@ rtc_common_inherited_config = webrtc_root + ":common_inherited_config" 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 @@ template("rtc_source_set") { } configs += invoker.configs + configs += rtc_library_impl_config configs -= rtc_remove_configs configs -= invoker.suppressed_configs public_configs = [ @@ -552,6 +554,7 @@ template("rtc_static_library") { } configs += invoker.configs + configs += rtc_library_impl_config configs -= rtc_remove_configs configs -= invoker.suppressed_configs public_configs = [