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}
This commit is contained in:
Mirko Bonadei
2018-09-17 13:48:44 +02:00
committed by Commit Bot
parent d8ff3f29ce
commit 55daf1aef6
4 changed files with 70 additions and 0 deletions

View File

@ -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" ]
}

15
rtc_base/build/BUILD.gn Normal file
View File

@ -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",
]
}

View File

@ -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_

View File

@ -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 = [