summaryrefslogtreecommitdiff
path: root/absl/types
diff options
context:
space:
mode:
authorGravatar Derek Mauro <dmauro@google.com>2024-01-03 13:00:42 -0800
committerGravatar Copybara-Service <copybara-worker@google.com>2024-01-03 13:01:46 -0800
commit2a636651729cec997a433ce8e363c6344130944e (patch)
treef039cfa461d15224bc67fd74b8dcbd4fa4f0065b /absl/types
parent98156bb8e0337cc8c2e0480ebc14fee208a2f08c (diff)
Avoid a empty library build failure on Apple platforms
https://github.com/abseil/abseil-cpp/issues/1465 reports that some CMake builds on Apply platforms issue ``` warning: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: archive library: libabsl_bad_any_cast_impl.a the table of contents is empty (no object file members in the library define global symbols) ``` Our CMake build handles this problem for header-only libraries by not building a library at all. For some libraries, for example our polyfills, the library is only conditionally empty. In these libraries, I added a single char variable on Apple platforms as a workaround. I have been able to reproduce the warnings reported in https://github.com/abseil/abseil-cpp/issues/1465, but they don't fail the build for me. I don't see them any more after this change. PiperOrigin-RevId: 595480705 Change-Id: Ie48637e84ebae2f2aea4e2de83b146f30f6a76b9
Diffstat (limited to 'absl/types')
-rw-r--r--absl/types/bad_any_cast.cc18
-rw-r--r--absl/types/bad_optional_access.cc18
-rw-r--r--absl/types/bad_variant_access.cc18
3 files changed, 54 insertions, 0 deletions
diff --git a/absl/types/bad_any_cast.cc b/absl/types/bad_any_cast.cc
index b0592cc9..22558b48 100644
--- a/absl/types/bad_any_cast.cc
+++ b/absl/types/bad_any_cast.cc
@@ -43,4 +43,22 @@ void ThrowBadAnyCast() {
ABSL_NAMESPACE_END
} // namespace absl
+#else
+
+// https://github.com/abseil/abseil-cpp/issues/1465
+// CMake builds on Apple platforms error when libraries are empty.
+// Our CMake configuration can avoid this error on header-only libraries,
+// but since this library is conditionally empty, including a single
+// variable is an easy workaround.
+#ifdef __APPLE__
+namespace absl {
+ABSL_NAMESPACE_BEGIN
+namespace types_internal {
+extern const char kAvoidEmptyBadAnyCastLibraryWarning;
+const char kAvoidEmptyBadAnyCastLibraryWarning = 0;
+} // namespace types_internal
+ABSL_NAMESPACE_END
+} // namespace absl
+#endif // __APPLE__
+
#endif // ABSL_USES_STD_ANY
diff --git a/absl/types/bad_optional_access.cc b/absl/types/bad_optional_access.cc
index 26aca70d..2552cc85 100644
--- a/absl/types/bad_optional_access.cc
+++ b/absl/types/bad_optional_access.cc
@@ -45,4 +45,22 @@ void throw_bad_optional_access() {
ABSL_NAMESPACE_END
} // namespace absl
+#else
+
+// https://github.com/abseil/abseil-cpp/issues/1465
+// CMake builds on Apple platforms error when libraries are empty.
+// Our CMake configuration can avoid this error on header-only libraries,
+// but since this library is conditionally empty, including a single
+// variable is an easy workaround.
+#ifdef __APPLE__
+namespace absl {
+ABSL_NAMESPACE_BEGIN
+namespace types_internal {
+extern const char kAvoidEmptyBadOptionalAccessLibraryWarning;
+const char kAvoidEmptyBadOptionalAccessLibraryWarning = 0;
+} // namespace types_internal
+ABSL_NAMESPACE_END
+} // namespace absl
+#endif // __APPLE__
+
#endif // ABSL_USES_STD_OPTIONAL
diff --git a/absl/types/bad_variant_access.cc b/absl/types/bad_variant_access.cc
index 3dc88cc0..a76aa80d 100644
--- a/absl/types/bad_variant_access.cc
+++ b/absl/types/bad_variant_access.cc
@@ -61,4 +61,22 @@ void Rethrow() {
ABSL_NAMESPACE_END
} // namespace absl
+#else
+
+// https://github.com/abseil/abseil-cpp/issues/1465
+// CMake builds on Apple platforms error when libraries are empty.
+// Our CMake configuration can avoid this error on header-only libraries,
+// but since this library is conditionally empty, including a single
+// variable is an easy workaround.
+#ifdef __APPLE__
+namespace absl {
+ABSL_NAMESPACE_BEGIN
+namespace types_internal {
+extern const char kAvoidEmptyBadVariantAccessLibraryWarning;
+const char kAvoidEmptyBadVariantAccessLibraryWarning = 0;
+} // namespace types_internal
+ABSL_NAMESPACE_END
+} // namespace absl
+#endif // __APPLE__
+
#endif // ABSL_USES_STD_VARIANT