Commit 5906c258 authored by Mirko Bonadei's avatar Mirko Bonadei Committed by Commit Bot

Abseil component build (default symbols visibility).

This CL introduces an Abseil component on which all Chromium Abseil
clients will have to depend on.

Abseil doesn't export symbols explicitly, so for the moment Chromium
exports all of them when is_component_build=true. On Android, Linux and
Mac -fvisibility=default is used while on Windows a .def file is
generated at Abseil roll time.

Bug: 1046390
Change-Id: I1697eb9e0179cee01badcf1b687acd94160e5f6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2174434
Commit-Queue: Mirko Bonadei <mbonadei@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781225}
parent 538764b6
...@@ -79,7 +79,6 @@ group("gn_all") { ...@@ -79,7 +79,6 @@ group("gn_all") {
"//services/service_manager/public/cpp", "//services/service_manager/public/cpp",
"//skia:skia_unittests", "//skia:skia_unittests",
"//sql:sql_unittests", "//sql:sql_unittests",
"//third_party/abseil-cpp:absl_tests",
"//third_party/flatbuffers:flatbuffers_unittests", "//third_party/flatbuffers:flatbuffers_unittests",
"//tools/binary_size:binary_size_trybot_py", "//tools/binary_size:binary_size_trybot_py",
"//tools/ipc_fuzzer:ipc_fuzzer_all", "//tools/ipc_fuzzer:ipc_fuzzer_all",
...@@ -90,6 +89,12 @@ group("gn_all") { ...@@ -90,6 +89,12 @@ group("gn_all") {
"//url:url_unittests", "//url:url_unittests",
] ]
if (!is_component_build) {
deps += [
"//third_party/abseil-cpp:absl_tests",
]
}
if (!is_android && !is_chromecast) { if (!is_android && !is_chromecast) {
deps += [ deps += [
"//crypto:crypto_unittests", "//crypto:crypto_unittests",
......
...@@ -9,13 +9,30 @@ ...@@ -9,13 +9,30 @@
import("//build/toolchain/toolchain.gni") import("//build/toolchain/toolchain.gni")
import("//testing/test.gni") import("//testing/test.gni")
config("absl_component_build") {
defines = [ "ABSL_CONSUME_DLL" ]
}
# TODO(mbonadei): WebRTC tests and binaries use absl flags but they are
# marked testonly because we don't want them to be usable in Chromium.
# Add an absl_flags component which depends on the main absl component.
component("absl") {
if (is_component_build) {
public_configs = [ ":absl_component_build" ]
if (is_win) {
if (target_cpu == "x64") {
sources = [ "symbols_x64.def" ]
}
if (target_cpu == "x86") {
sources = [ "symbols_x86.def" ]
}
if (target_cpu == "arm64") {
sources = [ "symbols_arm64.def" ]
}
}
}
# This is a placeholder target (that will become a "component" in a follow up
# CL) to allow both WebRTC and OpenScreen to depend on
# //third_party/abseil-cpp:absl. This is beneficial for the
# migration from an always statically linked Abseil to an Abseil that
# will respect the value of is_component_build.
group("absl") {
public_deps = [ public_deps = [
"//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/base:config", "//third_party/abseil-cpp/absl/base:config",
...@@ -103,25 +120,27 @@ config("absl_test_cflags_cc") { ...@@ -103,25 +120,27 @@ config("absl_test_cflags_cc") {
} }
} }
test("absl_tests") { if (!is_component_build) {
testonly = true test("absl_tests") {
deps = [ testonly = true
"absl/algorithm:algorithm_test", deps = [
"absl/algorithm:container_test", "absl/algorithm:algorithm_test",
"absl/base:config_test", "absl/algorithm:container_test",
"absl/container:inlined_vector_test", "absl/base:config_test",
"absl/memory:memory_test", "absl/container:inlined_vector_test",
"absl/meta:type_traits_test", "absl/memory:memory_test",
"absl/strings:ascii_test", "absl/meta:type_traits_test",
"absl/strings:match_test", "absl/strings:ascii_test",
"absl/strings:str_replace_test", "absl/strings:match_test",
"absl/strings:string_view_test", "absl/strings:str_replace_test",
"absl/strings:string_view_test",
# TODO(mbonadei): On iOS, gtest doesn't support death tests. Fix upstream
# Abseil to use EXPECT_DEATH_IF_SUPPORTED instead of EXPECT_DEATH. # TODO(mbonadei): On iOS, gtest doesn't support death tests. Fix upstream
# "absl/types:optional_test", # Abseil to use EXPECT_DEATH_IF_SUPPORTED instead of EXPECT_DEATH.
# "absl/types:variant_test", # "absl/types:optional_test",
# "absl/types:variant_test",
"//third_party/googletest:gtest_main",
] "//third_party/googletest:gtest_main",
]
}
} }
...@@ -60,6 +60,14 @@ template("absl_source_set") { ...@@ -60,6 +60,14 @@ template("absl_source_set") {
"//third_party/abseil-cpp:absl_default_cflags_cc", "//third_party/abseil-cpp:absl_default_cflags_cc",
] ]
if (is_component_build) {
defines = [ "ABSL_BUILD_DLL" ]
if (!is_win) {
configs -= [ "//build/config/gcc:symbol_visibility_hidden" ]
configs += [ "//build/config/gcc:symbol_visibility_default" ]
}
}
if (!defined(public_configs)) { if (!defined(public_configs)) {
public_configs = [] public_configs = []
} }
......
...@@ -227,7 +227,7 @@ bool RawLoggingFullySupported() { ...@@ -227,7 +227,7 @@ bool RawLoggingFullySupported() {
#endif // !ABSL_LOW_LEVEL_WRITE_SUPPORTED #endif // !ABSL_LOW_LEVEL_WRITE_SUPPORTED
} }
ABSL_DLL ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES ABSL_DLL
absl::base_internal::AtomicHook<InternalLogFunction> absl::base_internal::AtomicHook<InternalLogFunction>
internal_log_function(DefaultInternalLog); internal_log_function(DefaultInternalLog);
......
...@@ -170,7 +170,7 @@ using InternalLogFunction = void (*)(absl::LogSeverity severity, ...@@ -170,7 +170,7 @@ using InternalLogFunction = void (*)(absl::LogSeverity severity,
const char* file, int line, const char* file, int line,
const std::string& message); const std::string& message);
ABSL_DLL ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES extern base_internal::AtomicHook< ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES ABSL_DLL extern base_internal::AtomicHook<
InternalLogFunction> InternalLogFunction>
internal_log_function; internal_log_function;
......
...@@ -586,7 +586,7 @@ constexpr bool operator>=(string_view x, string_view y) noexcept { ...@@ -586,7 +586,7 @@ constexpr bool operator>=(string_view x, string_view y) noexcept {
} }
// IO Insertion Operator // IO Insertion Operator
std::ostream& operator<<(std::ostream& o, string_view piece); ABSL_DLL std::ostream& operator<<(std::ostream& o, string_view piece);
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
} // namespace absl } // namespace absl
......
"""Script to generate Chromium's Abseil .def file at roll time.
This script generates //third_party/abseil-app/absl/symbols_x64.def at Abseil
roll time.
Since Abseil doesn't export symbols, Chromium is forced to consider all
Abseil's symbols as publicly visible. On POSIX it is possible to use
-fvisibility=default but on Windows a .def file with all the symbols
is needed.
Unless you are on a Windows machine, you need to set up your Chromium
checkout for cross-compilation by following the instructions at
https://chromium.googlesource.com/chromium/src.git/+/master/docs/win_cross.md.
"""
import fnmatch
import logging
import os
import re
import subprocess
import tempfile
import time
# Matches a mangled symbol that has 'absl' in it, this should be a good
# enough heuristic to select Abseil symbols to list in the .def file.
ABSL_SYM_RE = re.compile(r'0* [BT] (?P<symbol>\?{1}[^\?].*absl.*)')
def _GenerateDefFile(cpu):
"""Generates a .def file for the absl component build on the specified CPU."""
gn_args = [
'ffmpeg_branding = "Chrome"',
'is_component_build = false',
'is_debug = true',
'proprietary_codecs = true',
'symbol_level = 0',
'target_cpu = "{}"'.format(cpu),
'target_os = "win"',
]
with tempfile.TemporaryDirectory() as out_dir:
logging.info('[%s] Creating tmp out dir in %s', cpu, out_dir)
subprocess.check_call(['gn', 'gen', out_dir, '--args=' + ' '.join(gn_args)],
cwd=os.getcwd())
logging.info('[%s] gn gen completed', cpu)
subprocess.check_call(
['autoninja', '-C', out_dir, 'third_party/abseil-cpp:absl'],
cwd=os.getcwd())
logging.info('[%s] autoninja completed', cpu)
obj_files = []
for root, _dirnames, filenames in os.walk(
os.path.join(out_dir, 'obj', 'third_party', 'abseil-cpp')):
matched_files = fnmatch.filter(filenames, '*.obj')
obj_files.extend((os.path.join(root, f) for f in matched_files))
logging.info('[%s] Found %d object files.', cpu, len(obj_files))
absl_symbols = []
for f in obj_files:
stdout = subprocess.check_output(['llvm-nm-9', f], cwd=os.getcwd())
for line in stdout.splitlines():
match = re.match(ABSL_SYM_RE, line.decode('utf-8'))
if match:
absl_symbols.append(match.group('symbol'))
logging.info('[%s] Found %d absl symbols.', cpu, len(absl_symbols))
def_file = os.path.join('third_party', 'abseil-cpp',
'symbols_{}.def'.format(cpu))
with open(def_file, 'w') as f:
f.write('EXPORTS\n')
for s in sorted(absl_symbols):
f.write(' {}\n'.format(s))
# Hack, it looks like there is a race in the directory cleanup.
time.sleep(3)
logging.info('[%s] .def file successfully generated.', cpu)
if __name__ == '__main__':
logging.getLogger().setLevel(logging.INFO)
if not os.getcwd().endswith('chromium/src'):
logging.error('Run this script from Chromium\'s src/ directory.')
exit(1)
_GenerateDefFile('x86')
_GenerateDefFile('x64')
_GenerateDefFile('arm64')
From 330cb7c7a62ab3187a6a2a3dc3a7b92f3690677c Mon Sep 17 00:00:00 2001
From: Mirko Bonadei <mbonadei@chromium.org>
Date: Wed, 17 Jun 2020 21:37:18 +0200
Subject: [PATCH] Manual ABSL_DLL fixes.
---
third_party/abseil-cpp/absl/base/internal/raw_logging.cc | 2 +-
third_party/abseil-cpp/absl/base/internal/raw_logging.h | 2 +-
third_party/abseil-cpp/absl/strings/string_view.h | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/third_party/abseil-cpp/absl/base/internal/raw_logging.cc b/third_party/abseil-cpp/absl/base/internal/raw_logging.cc
index 40cea5506172..f27e2838d72b 100644
--- a/third_party/abseil-cpp/absl/base/internal/raw_logging.cc
+++ b/third_party/abseil-cpp/absl/base/internal/raw_logging.cc
@@ -227,7 +227,7 @@ bool RawLoggingFullySupported() {
#endif // !ABSL_LOW_LEVEL_WRITE_SUPPORTED
}
-ABSL_DLL ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES
+ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES ABSL_DLL
absl::base_internal::AtomicHook<InternalLogFunction>
internal_log_function(DefaultInternalLog);
diff --git a/third_party/abseil-cpp/absl/base/internal/raw_logging.h b/third_party/abseil-cpp/absl/base/internal/raw_logging.h
index 418d6c856feb..51551bafff48 100644
--- a/third_party/abseil-cpp/absl/base/internal/raw_logging.h
+++ b/third_party/abseil-cpp/absl/base/internal/raw_logging.h
@@ -170,7 +170,7 @@ using InternalLogFunction = void (*)(absl::LogSeverity severity,
const char* file, int line,
const std::string& message);
-ABSL_DLL ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES extern base_internal::AtomicHook<
+ABSL_INTERNAL_ATOMIC_HOOK_ATTRIBUTES ABSL_DLL extern base_internal::AtomicHook<
InternalLogFunction>
internal_log_function;
diff --git a/third_party/abseil-cpp/absl/strings/string_view.h b/third_party/abseil-cpp/absl/strings/string_view.h
index 8a9db8c3d796..7fb033300338 100644
--- a/third_party/abseil-cpp/absl/strings/string_view.h
+++ b/third_party/abseil-cpp/absl/strings/string_view.h
@@ -586,7 +586,7 @@ constexpr bool operator>=(string_view x, string_view y) noexcept {
}
// IO Insertion Operator
-std::ostream& operator<<(std::ostream& o, string_view piece);
+ABSL_DLL std::ostream& operator<<(std::ostream& o, string_view piece);
ABSL_NAMESPACE_END
} // namespace absl
--
2.27.0.290.gba653c62da-goog
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -170,7 +170,7 @@ blink_modules_sources("peerconnection") { ...@@ -170,7 +170,7 @@ blink_modules_sources("peerconnection") {
] ]
public_deps = [ "//third_party/webrtc_overrides:webrtc_component" ] public_deps = [ "//third_party/webrtc_overrides:webrtc_component" ]
deps = [ "//third_party/abseil-cpp/absl/types:optional" ] deps = [ "//third_party/abseil-cpp:absl" ]
} }
jumbo_source_set("test_support") { jumbo_source_set("test_support") {
......
...@@ -1584,7 +1584,7 @@ jumbo_component("platform") { ...@@ -1584,7 +1584,7 @@ jumbo_component("platform") {
"//skia", "//skia",
"//skia:skcms", "//skia:skcms",
"//third_party:freetype_harfbuzz", "//third_party:freetype_harfbuzz",
"//third_party/abseil-cpp/absl/types:optional", "//third_party/abseil-cpp:absl",
"//third_party/blink/public:image_resources", "//third_party/blink/public:image_resources",
"//third_party/blink/public/common", "//third_party/blink/public/common",
"//third_party/blink/public/mojom:embedded_frame_sink_mojo_bindings_blink", "//third_party/blink/public/mojom:embedded_frame_sink_mojo_bindings_blink",
......
...@@ -134,12 +134,7 @@ source_set("gtest") { ...@@ -134,12 +134,7 @@ source_set("gtest") {
] ]
if (gtest_enable_absl_printers) { if (gtest_enable_absl_printers) {
public_deps += [ public_deps += [
"//third_party/abseil-cpp/absl/debugging:failure_signal_handler", "//third_party/abseil-cpp:absl",
"//third_party/abseil-cpp/absl/debugging:stacktrace",
"//third_party/abseil-cpp/absl/debugging:symbolize",
"//third_party/abseil-cpp/absl/strings",
"//third_party/abseil-cpp/absl/types:optional",
"//third_party/abseil-cpp/absl/types:variant",
] ]
} }
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment