Skip to content

Commit 4b2004d

Browse files
markchandlera-maurice
authored andcommitted
Firebase cpp: Exported symbol with compiler used and std library used to provide compile link error instead of runtime crash if differnet setup is used.
PiperOrigin-RevId: 278485256
1 parent 34391a8 commit 4b2004d

File tree

7 files changed

+67
-5
lines changed

7 files changed

+67
-5
lines changed

app/src/app_android.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ AppOptions* AppOptions::LoadDefault(AppOptions* app_options,
420420
return app_options;
421421
}
422422

423-
App::App() : activity_(nullptr), internal_(nullptr) {}
423+
void App::Initialize() {}
424424

425425
App::~App() {
426426
app_common::RemoveApp(this);

app/src/app_common.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@
4646

4747
namespace FIREBASE_NAMESPACE {
4848

49+
#ifdef FIREBASE_LINUX_BUILD_CONFIG_STRING
50+
void CheckCompilerString(const char* input) {
51+
FIREBASE_ASSERT_MESSAGE(
52+
strcmp(FIREBASE_LINUX_BUILD_CONFIG_STRING, input) == 0,
53+
"The compiler or stdlib library Firebase was compiled with does not "
54+
"match what is being used to compile this application."
55+
" [Lib: '%s' != Bin: '%s']",
56+
FIREBASE_LINUX_BUILD_CONFIG_STRING, input);
57+
}
58+
#endif // FIREBASE_LINUX_BUILD_CONFIG_STRING
59+
4960
// Default app name.
5061
const char* const kDefaultAppName = "__FIRAPP_DEFAULT";
5162

app/src/app_desktop.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ AppOptions* AppOptions::LoadDefault(AppOptions* options) {
117117
return nullptr;
118118
}
119119

120-
App::App() {
120+
void App::Initialize() {
121121
internal_ = new internal::AppInternal();
122122
}
123123

app/src/app_ios.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ static void PlatformOptionsToAppOptions(FIROptions* platform_options,
220220
return app_options;
221221
}
222222

223-
App::App() : internal_(nullptr) {}
223+
void App::Initialize() {}
224224

225225
App::~App() {
226226
app_common::RemoveApp(this);

app/src/app_stub.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ DEFINE_FIREBASE_VERSION_STRING(Firebase);
3131

3232
const char* const kDefaultAppName = "default";
3333

34-
App::App() : data_(new internal::FunctionRegistry) {
34+
void App::Initialize() {
35+
data_ = new internal::FunctionRegistry;
3536
LogDebug("Creating firebase::App for %s", kFirebaseVersionString);
3637
}
3738

app/src/include/firebase/app.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939

4040
namespace FIREBASE_NAMESPACE {
4141

42+
#ifdef FIREBASE_LINUX_BUILD_CONFIG_STRING
43+
// Check to see if the shared object compiler string matches the input
44+
void CheckCompilerString(const char* input);
45+
#endif // FIREBASE_LINUX_BUILD_CONFIG_STRING
46+
4247
// Predeclarations.
4348
#ifdef INTERNAL_EXPERIMENTAL
4449
namespace internal {
@@ -754,7 +759,21 @@ class App {
754759

755760
private:
756761
/// Construct the object.
757-
App();
762+
App() :
763+
#if FIREBASE_PLATFORM_ANDROID || defined(DOXYGEN)
764+
activity_(nullptr),
765+
#endif
766+
internal_(nullptr) {
767+
Initialize();
768+
769+
#ifdef FIREBASE_LINUX_BUILD_CONFIG_STRING
770+
CheckCompilerString(FIREBASE_LINUX_BUILD_CONFIG_STRING);
771+
#endif // FIREBASE_LINUX_BUILD_CONFIG_STRING
772+
}
773+
774+
775+
/// Initialize internal implementation
776+
void Initialize();
758777

759778
#ifndef SWIG
760779
// <SWIG>

app/src/include/firebase/internal/platform.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,37 @@
6565
#define FIREBASE_PLATFORM_UNKNOWN 1
6666
#endif
6767

68+
#if FIREBASE_PLATFORM_LINUX
69+
70+
// Include std library header to get version defines
71+
#include <stdexcept>
72+
73+
#if defined(__clang__)
74+
#define FIREBASE_COMPILER_CLANG 1
75+
#elif defined(__GNUC__)
76+
#define FIREBASE_COMPILER_GCC 1
77+
#endif
78+
79+
#if defined(_LIBCPP_VERSION)
80+
#define FIREBASE_STANDARD_LIBCPP 1
81+
#elif defined(__GLIBCXX__)
82+
#define FIREBASE_STANDARD_LIBSTDCPP 1
83+
#endif
84+
85+
#if (FIREBASE_COMPILER_CLANG && FIREBASE_STANDARD_LIBCPP)
86+
#define FIREBASE_LINUX_BUILD_CONFIG_STRING "clang_libstdcpp"
87+
#elif (FIREBASE_COMPILER_CLANG && FIREBASE_STANDARD_LIBSTDCPP)
88+
#define FIREBASE_LINUX_BUILD_CONFIG_STRING "clang_libcpp"
89+
#elif (FIREBASE_COMPILER_GCC && FIREBASE_STANDARD_LIBCPP)
90+
#define FIREBASE_LINUX_BUILD_CONFIG_STRING "gcc_libstdcpp"
91+
#elif (FIREBASE_COMPILER_GCC && FIREBASE_STANDARD_LIBSTDCPP)
92+
#define FIREBASE_LINUX_BUILD_CONFIG_STRING "gcc_libcpp"
93+
#else
94+
#error "Unsupported compiler or standard library"
95+
#endif
96+
97+
#endif // FIREBASE_PLATFORM_LINUX
98+
6899
#define FIREBASE_PLATFORM_MOBILE \
69100
(FIREBASE_PLATFORM_IOS || FIREBASE_PLATFORM_ANDROID)
70101
#define FIREBASE_PLATFORM_DESKTOP \

0 commit comments

Comments
 (0)