Commit 2a636651 by Derek Mauro Committed by Copybara-Service

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
parent 98156bb8
...@@ -185,4 +185,22 @@ int GetSignalHandlerStackConsumption(void (*signal_handler)(int)) { ...@@ -185,4 +185,22 @@ int GetSignalHandlerStackConsumption(void (*signal_handler)(int)) {
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
} // namespace absl } // 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 debugging_internal {
extern const char kAvoidEmptyStackConsumptionLibraryWarning;
const char kAvoidEmptyStackConsumptionLibraryWarning = 0;
} // namespace debugging_internal
ABSL_NAMESPACE_END
} // namespace absl
#endif // __APPLE__
#endif // ABSL_INTERNAL_HAVE_DEBUGGING_STACK_CONSUMPTION #endif // ABSL_INTERNAL_HAVE_DEBUGGING_STACK_CONSUMPTION
...@@ -25,5 +25,17 @@ constexpr int LogEntry::kNoVerbosityLevel; ...@@ -25,5 +25,17 @@ constexpr int LogEntry::kNoVerbosityLevel;
constexpr int LogEntry::kNoVerboseLevel; constexpr int LogEntry::kNoVerboseLevel;
#endif #endif
// 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 log_internal {
extern const char kAvoidEmptyLogEntryLibraryWarning;
const char kAvoidEmptyLogEntryLibraryWarning = 0;
} // namespace log_internal
#endif // __APPLE__
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
} // namespace absl } // namespace absl
...@@ -241,4 +241,22 @@ constexpr string_view::size_type string_view::kMaxSize; ...@@ -241,4 +241,22 @@ constexpr string_view::size_type string_view::kMaxSize;
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
} // namespace absl } // 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 strings_internal {
extern const char kAvoidEmptyStringViewLibraryWarning;
const char kAvoidEmptyStringViewLibraryWarning = 0;
} // namespace strings_internal
ABSL_NAMESPACE_END
} // namespace absl
#endif // __APPLE__
#endif // ABSL_USES_STD_STRING_VIEW #endif // ABSL_USES_STD_STRING_VIEW
...@@ -43,4 +43,22 @@ void ThrowBadAnyCast() { ...@@ -43,4 +43,22 @@ void ThrowBadAnyCast() {
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
} // namespace absl } // 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 #endif // ABSL_USES_STD_ANY
...@@ -45,4 +45,22 @@ void throw_bad_optional_access() { ...@@ -45,4 +45,22 @@ void throw_bad_optional_access() {
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
} // namespace absl } // 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 #endif // ABSL_USES_STD_OPTIONAL
...@@ -61,4 +61,22 @@ void Rethrow() { ...@@ -61,4 +61,22 @@ void Rethrow() {
ABSL_NAMESPACE_END ABSL_NAMESPACE_END
} // namespace absl } // 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 #endif // ABSL_USES_STD_VARIANT
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