Skip to content

Commit 3dab95e

Browse files
authored
feat(core, windows): Change the windows plugin compiling way (#11594)
1 parent 13aaf03 commit 3dab95e

File tree

8 files changed

+14
-74
lines changed

8 files changed

+14
-74
lines changed

packages/firebase_auth/firebase_auth/example/windows/flutter/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ include(${EPHEMERAL_DIR}/generated_config.cmake)
1010
# https://github.com/flutter/flutter/issues/57146.
1111
set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper")
1212

13+
# Set fallback configurations for older versions of the flutter tool.
14+
if (NOT DEFINED FLUTTER_TARGET_PLATFORM)
15+
set(FLUTTER_TARGET_PLATFORM "windows-x64")
16+
endif()
17+
1318
# === Flutter Library ===
1419
set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll")
1520

@@ -92,7 +97,7 @@ add_custom_command(
9297
COMMAND ${CMAKE_COMMAND} -E env
9398
${FLUTTER_TOOL_ENVIRONMENT}
9499
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
95-
windows-x64 $<CONFIG>
100+
${FLUTTER_TARGET_PLATFORM} $<CONFIG>
96101
VERBATIM
97102
)
98103
add_custom_target(flutter_assemble DEPENDS

packages/firebase_auth/firebase_auth/windows/CMakeLists.txt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ list(APPEND PLUGIN_SOURCES
2222

2323
# Define the plugin library target. Its name must not be changed (see comment
2424
# on PLUGIN_NAME above).
25-
add_library(${PLUGIN_NAME} SHARED
25+
add_library(${PLUGIN_NAME} STATIC
2626
"include/firebase_auth/firebase_auth_plugin_c_api.h"
2727
"firebase_auth_plugin_c_api.cpp"
2828
${PLUGIN_SOURCES}
@@ -38,14 +38,13 @@ apply_standard_settings(${PLUGIN_NAME})
3838
# exported should be explicitly exported with the FLUTTER_PLUGIN_EXPORT macro.
3939
set_target_properties(${PLUGIN_NAME} PROPERTIES
4040
CXX_VISIBILITY_PRESET hidden)
41-
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
41+
target_compile_definitions(${PLUGIN_NAME} PUBLIC FLUTTER_PLUGIN_IMPL)
4242

4343
# Source include directories and library dependencies. Add any plugin-specific
4444
# dependencies here.
4545
set(MSVC_RUNTIME_MODE MD)
46-
set(firebase_libs firebase_core_plugin firebase_auth firebase_app)
47-
set(ADDITIONAL_LIBS advapi32 ws2_32 crypt32)
48-
target_link_libraries(${PLUGIN_NAME} PRIVATE "${firebase_libs}" "${ADDITIONAL_LIBS}")
46+
set(firebase_libs firebase_core_plugin firebase_auth)
47+
target_link_libraries(${PLUGIN_NAME} PRIVATE "${firebase_libs}")
4948

5049
target_include_directories(${PLUGIN_NAME} INTERFACE
5150
"${CMAKE_CURRENT_SOURCE_DIR}/include")

packages/firebase_auth/firebase_auth/windows/firebase_auth_plugin.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,7 @@ FirebaseAuthPlugin::FirebaseAuthPlugin() {
6161
FirebaseAuthPlugin::~FirebaseAuthPlugin() = default;
6262

6363
Auth* GetAuthFromPigeon(const PigeonFirebaseApp& pigeonApp) {
64-
std::vector<std::string> app_vector = GetFirebaseApp(pigeonApp.app_name());
65-
firebase::AppOptions options;
66-
67-
options.set_api_key(app_vector[1].c_str());
68-
options.set_app_id(app_vector[2].c_str());
69-
options.set_database_url(app_vector[3].c_str());
70-
options.set_project_id(app_vector[4].c_str());
71-
72-
App* app = App::Create(options, pigeonApp.app_name().c_str());
64+
App* app = App::GetInstance(pigeonApp.app_name().c_str());
7365

7466
Auth* auth = Auth::GetAuth(app);
7567

packages/firebase_core/firebase_core/windows/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ list(APPEND PLUGIN_SOURCES
6565

6666
# Define the plugin library target. Its name must not be changed (see comment
6767
# on PLUGIN_NAME above).
68-
add_library(${PLUGIN_NAME} SHARED
68+
add_library(${PLUGIN_NAME} STATIC
6969
"include/firebase_core/firebase_core_plugin_c_api.h"
7070
"firebase_core_plugin_c_api.cpp"
7171
${PLUGIN_SOURCES}
@@ -82,15 +82,15 @@ apply_standard_settings(${PLUGIN_NAME})
8282
# exported should be explicitly exported with the FLUTTER_PLUGIN_EXPORT macro.
8383
set_target_properties(${PLUGIN_NAME} PROPERTIES
8484
CXX_VISIBILITY_PRESET hidden)
85-
target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL)
85+
target_compile_definitions(${PLUGIN_NAME} PUBLIC FLUTTER_PLUGIN_IMPL)
8686

8787
# Source include directories and library dependencies. Add any plugin-specific
8888
# dependencies here.
8989
set(MSVC_RUNTIME_MODE MD)
9090
add_subdirectory(${FIREBASE_CPP_SDK_DIR} bin/ EXCLUDE_FROM_ALL)
9191
target_include_directories(${PLUGIN_NAME} INTERFACE
9292
"${FIREBASE_CPP_SDK_DIR}/include")
93-
set(FIREBASE_LIBS firebase_app firebase_auth firebase_remote_config)
93+
set(FIREBASE_LIBS firebase_app)
9494
foreach(firebase_lib IN ITEMS ${FIREBASE_LIBS})
9595
get_target_property(firebase_lib_path ${firebase_lib} IMPORTED_LOCATION)
9696
string(REPLACE "Debug" "Release" firebase_lib_release_path ${firebase_lib_path})

packages/firebase_core/firebase_core/windows/firebase_core_plugin.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <windows.h>
99

1010
#include "firebase/app.h"
11-
#include "firebase/auth.h"
12-
#include "firebase/remote_config.h"
1311
#include "messages.g.h"
1412

1513
// For getPlatformVersion; remove unless needed for your plugin implementation.
@@ -28,8 +26,6 @@
2826
#include <vector>
2927

3028
using ::firebase::App;
31-
using ::firebase::auth::Auth;
32-
using ::firebase::remote_config::RemoteConfig;
3329

3430
namespace firebase_core_windows {
3531

@@ -46,35 +42,6 @@ void FirebaseCorePlugin::RegisterWithRegistrar(
4642

4743
std::map<std::string, std::vector<std::string>> apps;
4844

49-
std::vector<std::string> FirebaseCorePlugin::GetFirebaseApp(
50-
std::string appName) {
51-
auto app_it = apps.find(appName);
52-
53-
// If the app is already in the map, return the stored shared_ptr
54-
if (app_it != apps.end()) {
55-
return app_it->second;
56-
}
57-
58-
std::vector<std::string> app_vector;
59-
return app_vector;
60-
}
61-
62-
void *FirebaseCorePlugin::GetFirebaseAuth(std::string appName) {
63-
App *app = App::GetInstance(appName.c_str());
64-
if (app == nullptr) {
65-
return nullptr;
66-
}
67-
return Auth::GetAuth(app);
68-
}
69-
70-
void *FirebaseCorePlugin::GetFirebaseRemoteConfig(std::string appName) {
71-
App *app = App::GetInstance(appName.c_str());
72-
if (app == nullptr) {
73-
return nullptr;
74-
}
75-
return RemoteConfig::GetInstance(app);
76-
}
77-
7845
FirebaseCorePlugin::FirebaseCorePlugin() {}
7946

8047
FirebaseCorePlugin::~FirebaseCorePlugin() = default;

packages/firebase_core/firebase_core/windows/firebase_core_plugin.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ class FirebaseCorePlugin : public flutter::Plugin,
2222
public FirebaseAppHostApi {
2323
public:
2424
static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar);
25-
static std::vector<std::string> GetFirebaseApp(std::string appName);
26-
static void *GetFirebaseAuth(std::string appName);
27-
static void *GetFirebaseRemoteConfig(std::string appName);
2825

2926
FirebaseCorePlugin();
3027

packages/firebase_core/firebase_core/windows/firebase_core_plugin_c_api.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,3 @@ void FirebaseCorePluginCApiRegisterWithRegistrar(
1717
flutter::PluginRegistrarManager::GetInstance()
1818
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar));
1919
}
20-
21-
std::vector<std::string> GetFirebaseApp(std::string appName) {
22-
return firebase_core_windows::FirebaseCorePlugin::GetFirebaseApp(appName);
23-
}
24-
25-
void* GetFirebaseAuth(std::string appName) {
26-
return firebase_core_windows::FirebaseCorePlugin::GetFirebaseAuth(appName);
27-
}
28-
29-
void* GetFirebaseRemoteConfig(std::string appName) {
30-
return firebase_core_windows::FirebaseCorePlugin::GetFirebaseRemoteConfig(
31-
appName);
32-
}

packages/firebase_core/firebase_core/windows/include/firebase_core/firebase_core_plugin_c_api.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,4 @@
2121
FLUTTER_PLUGIN_EXPORT void FirebaseCorePluginCApiRegisterWithRegistrar(
2222
FlutterDesktopPluginRegistrarRef registrar);
2323

24-
FLUTTER_PLUGIN_EXPORT std::vector<std::string> GetFirebaseApp(
25-
std::string appName);
26-
27-
FLUTTER_PLUGIN_EXPORT void* GetFirebaseAuth(std::string appName);
28-
29-
FLUTTER_PLUGIN_EXPORT void* GetFirebaseRemoteConfig(std::string appName);
30-
3124
#endif // FLUTTER_PLUGIN_FIREBASE_CORE_PLUGIN_C_API_H_

0 commit comments

Comments
 (0)