Conversation

compnerd

The C++ Interop efforts in Swift currently have some limitations. In particular, it cannot support trivial types with non-trivial destructors. As a workaround, provide a copy constructor which can be used by the Swift interop while using the regular semantics for all other cases.

A second issue arises in the handling of futures. Unfortunately, it is not currently possible to pass an indirect block parameter which prevents the construction of a callback. Workaround this by providing an inline shim to use a direct parameter (i.e. indirect value through a pointer) which then allows a callback to be formed.

Both of these items are being tracked upstream but seem to be potentially sufficient to enable the use of Swift for using the C++ SDK for desktop scenarios.

@compnerdcompnerd force-pushed the swift branch 3 times, most recently from 9b6c99c to 51e693e Compare August 5, 2023 16:16
The C++ Interop efforts in Swift currently have some limitations.  In
particular, it cannot support trivial types with non-trivial
destructors.  As a workaround, provide a copy constructor which can be
used by the Swift interop while using the regular semantics for all
other cases.

A second issue arises in the handling of futures.  Unfortunately, it is
not currently possible to pass an indirect block parameter which
prevents the construction of a callback.  Workaround this by providing
an inline shim to use a direct parameter (i.e. indirect value through a
pointer) which then allows a callback to be formed.

Both of these items are being tracked upstream but seem to be
potentially sufficient to enable the use of Swift for using the C++ SDK
for desktop scenarios.
#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.

@github-actions-actions bot added the tests: in-progressThis PR's integration tests are in progress.label Oct 20, 2023
@github-actions

✅  Integration test succeeded!

Requested by @jonsimantov on commit refs/pull/1414/merge
Last updated: Wed Mar 13 16:30 PDT 2024
View integration test log & download artifacts

@github-actions-actions bot added the tests: failedThis PR's integration tests failed.label Oct 20, 2023
@firebase-workflow-triggerfirebase-workflow-trigger bot removed the tests: in-progressThis PR's integration tests are in progress.label Oct 20, 2023
@github-actions-actions bot added tests: succeededThis PR's integration tests succeeded.and removed tests: failedThis PR's integration tests failed.labels Oct 20, 2023
@jonsimantovjonsimantov self-requested a review October 23, 2023 17:34
jonsimantov
jonsimantov previously approved these changes Oct 23, 2023

Choose a reason for hiding this comment

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

This looks good to merge, though we will need to confirm after merge that it doesn't break our C++ packaging tests and Unity SDK build (in which case we'd need to roll it back).

@jonsimantovjonsimantov added the skip-release-notesSkip release notes checklabel Oct 23, 2023
@github-actions-actions bot dismissed jonsimantov’s stale review October 23, 2023 17:51

🍞 Dismissed stale approval on external PR.

@jonsimantovjonsimantov self-requested a review October 23, 2023 18:03
jonsimantov
jonsimantov previously approved these changes Oct 23, 2023
@compnerd

@jonsimantov - anything else left before we can merge this?

@github-actions-actions bot dismissed jonsimantov’s stale review January 16, 2024 22:53

🍞 Dismissed stale approval on external PR.

@github-actions-actions bot added tests: in-progressThis PR's integration tests are in progress.tests: failedThis PR's integration tests failed.and removed tests: succeededThis PR's integration tests succeeded.labels Jan 16, 2024
@firebase-workflow-triggerfirebase-workflow-trigger bot removed the tests: in-progressThis PR's integration tests are in progress.label Jan 17, 2024
@github-actions-actions bot added tests: in-progressThis PR's integration tests are in progress.and removed tests: failedThis PR's integration tests failed.labels Jan 31, 2024
@github-actions-actions bot added the tests: failedThis PR's integration tests failed.label Jan 31, 2024
@firebase-workflow-triggerfirebase-workflow-trigger bot removed the tests: in-progressThis PR's integration tests are in progress.label Jan 31, 2024
@github-actions-actions bot added tests: succeededThis PR's integration tests succeeded.and removed tests: failedThis PR's integration tests failed.labels Feb 1, 2024
@jonsimantovjonsimantov self-requested a review February 1, 2024 18:23
jonsimantov
jonsimantov previously approved these changes Feb 1, 2024

Choose a reason for hiding this comment

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

Looks good - let's go ahead and get this in. I do want to make sure this doesn't cause any weirdness with our public release, but I'll take a look next time we do one and roll this back if it needs any changes at that point.

@github-actions-actions bot dismissed jonsimantov’s stale review March 13, 2024 21:33

🍞 Dismissed stale approval on external PR.

@github-actions-actions bot added tests: in-progressThis PR's integration tests are in progress.tests: succeededThis PR's integration tests succeeded.and removed tests: succeededThis PR's integration tests succeeded.labels Mar 13, 2024
@firebase-workflow-triggerfirebase-workflow-trigger bot removed the tests: in-progressThis PR's integration tests are in progress.label Mar 13, 2024
@wti

bumping (with apologies) in case this can be merged, so people can use it...

@jonsimantov

You should have permission to merge since I approved it, but if not, let me know and I'll do it.

@marcprux

Could this be merged? I would also like to be able to use firebase-cpp from Swift…

Sign up for free to join this conversation on . Already have an account? Sign in to comment
skip-release-notesSkip release notes checktests: succeededThis PR's integration tests succeeded.
None yet

Successfully merging this pull request may close these issues.