Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a couple of workarounds for Swift on Windows #1414

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions app/src/include/firebase/future.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,11 @@ class Future : public FutureBase {
/// when you set up the callback.
typedef void (*TypedCompletionCallback)(const Future<ResultType>& result_data,
void* user_data);
#if defined(__swift__)
// TODO(apple/swift#67662) indirect block parameters are unsupported
typedef void (*TypedCompletionCallback_SwiftWorkaround)(
const Future<ResultType>* result_data, void* user_data);
#endif

/// Construct a future.
Future() {}
Expand Down Expand Up @@ -464,6 +469,16 @@ class Future : public FutureBase {
inline void OnCompletion(TypedCompletionCallback callback,
void* user_data) const;

#if defined(__swift__)
// TODO(apple/swift#67662) indirect block parameters are unsupported
inline void OnCompletion_SwiftWorkaround(
TypedCompletionCallback_SwiftWorkaround callback, void* user_data) const {
OnCompletion([callback, user_data](const Future<ResultType>& future) {
callback(&future, user_data);
});
}
#endif

#if defined(FIREBASE_USE_STD_FUNCTION) || defined(DOXYGEN)
/// Register a single callback that will be called at most once, when the
/// future is completed.
Expand Down
1 change: 1 addition & 0 deletions auth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ build_flatbuffers("${flatbuffer_schemas}"
# Common source files used by all platforms
set(common_SRCS
src/auth.cc
src/auth_swift.cc
src/credential.cc
src/common.cc
src/common.h
Expand Down
26 changes: 26 additions & 0 deletions auth/src/auth_swift.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#define __swift__ 50000
#include "auth/src/include/firebase/auth.h"

#if FIREBASE_PLATFORM_WINDOWS
namespace firebase {
namespace auth {
Auth::Auth(const Auth &) noexcept = default;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm uncomfortable having this copy constructor broadly available for all Windows developers. Could you wrap this and all of the other changes in an #if for the Swift compatibility that you can use in your build? e.g. FIREBASE_SWIFT_WINDOWS=1

Copy link
Contributor Author

@compnerd compnerd Sep 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That wouldn't work. That would mean that the distribution of firebase would not be usable as the copy-constructor would not be available when used for Swift.

Note that the header actually indicates that the copy constructor is not declared (and thus the compiler will synthesize one - except because it is a movable type, it will prefer to move it) when the interop is not enabled. This means that this is only going to add the distribution size but will be discarded by the linker as static linking is employed. As a result the copy constructor is not available for Windows developers, they would need to define __swift__ for it to be made available.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'm following. I'll take another look at this after our next release goes out.

}
} // namespace firebase
#endif
7 changes: 7 additions & 0 deletions auth/src/include/firebase/auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ class Auth {

~Auth();

#if defined(__swift__)
#if FIREBASE_PLATFORM_WINDOWS
// TODO(apple/swift#67288) support trivial C++ types with non-trivial dtors
Auth(const Auth&) noexcept;
#endif
#endif

/// Synchronously gets the cached current user, or returns an object where
/// is_valid() == false if there is none.
///
Expand Down
Loading