diff --git a/.github/workflows/windows.yaml b/.github/workflows/windows.yaml index eb85f529856f..8edfb057028a 100644 --- a/.github/workflows/windows.yaml +++ b/.github/workflows/windows.yaml @@ -63,6 +63,8 @@ jobs: npm install -g firebase-tools - name: "Build Windows (Release)" run: cd tests && flutter build windows --release + - name: "Build Windows (Profile)" + run: cd tests && flutter build windows --profile - name: Start Firebase Emulator and run tests run: cd ./.github/workflows/scripts && firebase emulators:exec --project flutterfire-e2e-tests "cd ../../../tests && flutter test .\integration_test\e2e_test.dart -d windows --verbose" diff --git a/packages/cloud_firestore/cloud_firestore/windows/CMakeLists.txt b/packages/cloud_firestore/cloud_firestore/windows/CMakeLists.txt index 0fa1da05e299..8264289959f6 100644 --- a/packages/cloud_firestore/cloud_firestore/windows/CMakeLists.txt +++ b/packages/cloud_firestore/cloud_firestore/windows/CMakeLists.txt @@ -66,7 +66,12 @@ target_compile_definitions(${PLUGIN_NAME} PRIVATE -DINTERNAL_EXPERIMENTAL=1) # Source include directories and library dependencies. Add any plugin-specific # dependencies here. set(MSVC_RUNTIME_MODE MD) -set(firebase_libs firebase_core_plugin firebase_auth firebase_firestore) +# firebase_auth must come after firebase_firestore: the Firestore desktop +# credentials provider pulls symbols out of firebase_auth (e.g. +# `firebase::g_auth_initializer`), the Firebase C++ SDK does not declare that +# dependency between its imported targets, and MSVC resolves static libraries +# in the order they appear on the link line. +set(firebase_libs firebase_core_plugin firebase_firestore firebase_auth) set(ADDITIONAL_LIBS advapi32 ws2_32 crypt32 rpcrt4 ole32 shell32 Bcrypt.lib DbgHelp.lib) target_link_libraries(${PLUGIN_NAME} PRIVATE "${firebase_libs}" "${ADDITIONAL_LIBS}") diff --git a/packages/cloud_firestore/cloud_firestore/windows/cloud_firestore_plugin.cpp b/packages/cloud_firestore/cloud_firestore/windows/cloud_firestore_plugin.cpp index 10c22a824228..9681f1390d7e 100644 --- a/packages/cloud_firestore/cloud_firestore/windows/cloud_firestore_plugin.cpp +++ b/packages/cloud_firestore/cloud_firestore/windows/cloud_firestore_plugin.cpp @@ -255,7 +255,7 @@ void CloudFirestorePlugin::RegisterWithRegistrar( auto plugin = std::make_unique(); - messenger_ = registrar->messenger(); + plugin->messenger_ = registrar->messenger(); FirebaseFirestoreHostApi::SetUp(registrar->messenger(), plugin.get()); @@ -327,9 +327,6 @@ firebase::firestore::FieldValue CloudFirestorePlugin::ConvertToFieldValue( } } -flutter::BinaryMessenger* - cloud_firestore_windows::CloudFirestorePlugin::messenger_ = nullptr; - std::map>> event_channels_; @@ -343,12 +340,12 @@ std::map> cloud_firestore_windows::CloudFirestorePlugin::firestoreInstances_; std::string RegisterEventChannelWithUUID( - std::string prefix, std::string uuid, + flutter::BinaryMessenger* messenger, std::string prefix, std::string uuid, std::unique_ptr> handler) { std::string channelName = prefix + uuid; event_channels_[channelName] = std::make_unique>( - CloudFirestorePlugin::messenger_, channelName, + messenger, channelName, &flutter::StandardMethodCodec::GetInstance( &FirebaseFirestoreHostApiCodecSerializer::GetInstance())); @@ -361,7 +358,7 @@ std::string RegisterEventChannelWithUUID( } std::string RegisterEventChannel( - std::string prefix, + flutter::BinaryMessenger* messenger, std::string prefix, std::unique_ptr> handler) { UUID uuid; UuidCreate(&uuid); @@ -371,7 +368,7 @@ std::string RegisterEventChannel( std::string channelName = prefix + str; event_channels_[channelName] = std::make_unique>( - CloudFirestorePlugin::messenger_, channelName, + messenger, channelName, &flutter::StandardMethodCodec::GetInstance( &FirebaseFirestoreHostApiCodecSerializer::GetInstance())); stream_handlers_[channelName] = std::move(handler); @@ -831,7 +828,8 @@ void CloudFirestorePlugin::LoadBundle( std::make_unique(firestore, bundleConverted); std::string channelName = RegisterEventChannel( - "plugins.flutter.io/firebase_firestore/loadBundle/", std::move(handler)); + messenger_, "plugins.flutter.io/firebase_firestore/loadBundle/", + std::move(handler)); result(channelName); } @@ -1029,7 +1027,7 @@ void CloudFirestorePlugin::SnapshotsInSyncSetup( std::string snapshotInSyncId(str); std::string channelName = RegisterEventChannelWithUUID( - "plugins.flutter.io/firebase_firestore/snapshotsInSync/", + messenger_, "plugins.flutter.io/firebase_firestore/snapshotsInSync/", snapshotInSyncId, std::move(handler)); result(snapshotInSyncId); } @@ -1202,8 +1200,8 @@ void CloudFirestorePlugin::TransactionCreate( // Register the event channel. std::string channelName = RegisterEventChannelWithUUID( - "plugins.flutter.io/firebase_firestore/transaction/", transactionId, - std::move(handler)); + messenger_, "plugins.flutter.io/firebase_firestore/transaction/", + transactionId, std::move(handler)); // Return the result (assumed to be transaction ID in this example). result(transactionId); @@ -1864,9 +1862,9 @@ void CloudFirestorePlugin::QuerySnapshot( GetServerTimestampBehaviorFromPigeon( options.server_timestamp_behavior())); - std::string channelName = - RegisterEventChannel("plugins.flutter.io/firebase_firestore/query/", - std::move(query_snapshot_handler)); + std::string channelName = RegisterEventChannel( + messenger_, "plugins.flutter.io/firebase_firestore/query/", + std::move(query_snapshot_handler)); result(channelName); } @@ -1962,9 +1960,9 @@ void CloudFirestorePlugin::DocumentReferenceSnapshot( GetServerTimestampBehaviorFromPigeon( *parameters.server_timestamp_behavior())); - std::string channelName = - RegisterEventChannel("plugins.flutter.io/firebase_firestore/document/", - std::move(document_snapshot_handler)); + std::string channelName = RegisterEventChannel( + messenger_, "plugins.flutter.io/firebase_firestore/document/", + std::move(document_snapshot_handler)); result(channelName); } diff --git a/packages/cloud_firestore/cloud_firestore/windows/cloud_firestore_plugin.h b/packages/cloud_firestore/cloud_firestore/windows/cloud_firestore_plugin.h index d023fb4c0236..2c2027883950 100644 --- a/packages/cloud_firestore/cloud_firestore/windows/cloud_firestore_plugin.h +++ b/packages/cloud_firestore/cloud_firestore/windows/cloud_firestore_plugin.h @@ -176,7 +176,12 @@ class CloudFirestorePlugin : public flutter::Plugin, std::function reply)> result) override; - static flutter::BinaryMessenger* messenger_; + // Per-registration messenger. A Windows app can host several Flutter engines + // in the same process (e.g. via `desktop_multi_window`), and each one + // registers the plugin with its own registrar. Keeping this per instance + // means every channel is built on the messenger of the engine that asked for + // it, instead of whichever engine registered last. + flutter::BinaryMessenger* messenger_ = nullptr; static std::map< std::string, std::unique_ptr>> diff --git a/packages/firebase_core/firebase_core/windows/CMakeLists.txt b/packages/firebase_core/firebase_core/windows/CMakeLists.txt index ce7de57c23fa..b2476a359ddf 100644 --- a/packages/firebase_core/firebase_core/windows/CMakeLists.txt +++ b/packages/firebase_core/firebase_core/windows/CMakeLists.txt @@ -126,9 +126,17 @@ set(FIREBASE_RELEASE_PATH_LIBS firebase_app firebase_auth firebase_remote_config foreach(firebase_lib IN ITEMS ${FIREBASE_RELEASE_PATH_LIBS}) get_target_property(firebase_lib_path ${firebase_lib} IMPORTED_LOCATION) string(REPLACE "Debug" "Release" firebase_lib_release_path ${firebase_lib_path}) + # Flutter builds Windows apps in Debug, Profile or Release. Profile uses the + # release CRT (Flutter maps its compiler/linker flags onto Release), so it + # must pick the release libraries too - without an explicit mapping CMake + # falls back to plain IMPORTED_LOCATION, which the SDK points at Debug, and + # linking fails with unresolved __imp__CrtDbgReport / __imp__invalid_parameter. set_target_properties(${firebase_lib} PROPERTIES IMPORTED_LOCATION_DEBUG "${firebase_lib_path}" IMPORTED_LOCATION_RELEASE "${firebase_lib_release_path}" + IMPORTED_LOCATION_PROFILE "${firebase_lib_release_path}" + IMPORTED_LOCATION_RELWITHDEBINFO "${firebase_lib_release_path}" + IMPORTED_LOCATION_MINSIZEREL "${firebase_lib_release_path}" ) endforeach()