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

Firestore Swift Cpp Experiment #13956

Open
wants to merge 8 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
9 changes: 9 additions & 0 deletions FirebaseCore/Sources/Public/FirebaseCore/FIRVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@
NS_ASSUME_NONNULL_BEGIN

/** Returns the current version of Firebase. */

#ifdef __cplusplus
extern "C" {
#endif

NS_SWIFT_NAME(FirebaseVersion())
NSString* FIRFirebaseVersion(void);

#ifdef __cplusplus
}
#endif

NS_ASSUME_NONNULL_END
7 changes: 7 additions & 0 deletions FirebaseFirestore.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,20 @@ Google Cloud Firestore is a NoSQL document database built for automatic scaling,
'FirebaseFirestoreInternal/**/*.[mh]',
'Firestore/Swift/Source/**/*.swift',
]

s.pod_target_xcconfig = {
# Enables C++ <-> Swift interop (by default it's only C)
"SWIFT_OBJC_INTEROP_MODE" => "objcxx",
}

s.resource_bundles = {
"#{s.module_name}_Privacy" => 'Firestore/Swift/Source/Resources/PrivacyInfo.xcprivacy'
}

s.dependency 'FirebaseCore', '11.5'
s.dependency 'FirebaseCoreExtension', '11.5'
s.dependency 'FirebaseFirestoreInternal', '11.5.0'
s.dependency 'FirebaseFirestoreCpp', '11.5.0'
s.dependency 'FirebaseSharedSwift', '~> 11.0'

end
65 changes: 65 additions & 0 deletions FirebaseFirestoreCpp.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
Pod::Spec.new do |s|
s.name = 'FirebaseFirestoreCpp'
s.version = '11.5.0'
s.summary = 'Google Cloud Firestore'

s.description = <<-DESC
Google Cloud Firestore is a NoSQL document database built for automatic scaling, high performance, and ease of application development.
DESC

s.homepage = 'https://developers.google.com/'
s.license = { :type => 'Apache-2.0', :file => 'Firestore/LICENSE' }
s.authors = 'Google, Inc.'

s.source = {
:git => 'https://github.com/firebase/firebase-ios-sdk.git',
:tag => 'CocoaPods-' + s.version.to_s
}

s.ios.deployment_target = '13.0'
s.osx.deployment_target = '10.15'
s.tvos.deployment_target = '13.0'

s.swift_version = '5.9'

s.cocoapods_version = '>= 1.12.0'
s.prefix_header_file = false

s.public_header_files = 'Firestore/core/swift/include/*.h'

s.source_files = [
'Firestore/core/swift/**/*.{cc,h}'
]

abseil_version = '~> 1.20240116.1'
s.dependency 'abseil/algorithm', abseil_version
s.dependency 'abseil/base', abseil_version
s.dependency 'abseil/container/flat_hash_map', abseil_version
s.dependency 'abseil/memory', abseil_version
s.dependency 'abseil/meta', abseil_version
s.dependency 'abseil/strings/strings', abseil_version
s.dependency 'abseil/time', abseil_version
s.dependency 'abseil/types', abseil_version

s.ios.frameworks = 'SystemConfiguration', 'UIKit'
s.osx.frameworks = 'SystemConfiguration'
s.tvos.frameworks = 'SystemConfiguration', 'UIKit'

s.library = 'c++'
s.pod_target_xcconfig = {
'CLANG_CXX_LANGUAGE_STANDARD' => 'c++14',
'CLANG_CXX_LIBRARY' => 'libc++',
'GCC_C_LANGUAGE_STANDARD' => 'c99',
'GCC_PREPROCESSOR_DEFINITIONS' =>
"FIRFirestore_VERSION=#{s.version} " +
# The nanopb pod sets these defs, so we must too. (We *do* require 16bit
# (or larger) fields, so we'd have to set at least PB_FIELD_16BIT
# anyways.)
'PB_FIELD_32BIT=1 PB_NO_PACKED_STRUCTS=1 PB_ENABLE_MALLOC=1',
'HEADER_SEARCH_PATHS' =>
'"${PODS_TARGET_SRCROOT}" ' +
'"${PODS_TARGET_SRCROOT}/Firestore/core/swift" '
}

s.compiler_flags = '$(inherited) -Wreorder -Werror=reorder -Wno-comma'
end
23 changes: 23 additions & 0 deletions Firestore/Swift/Source/SwiftAPI/SwiftCppAPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2024 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.
*/

import FirebaseFirestoreCpp

public class SwiftCppWrapper {
public init(_ value: String) {
_ = UsedBySwift(std.string(value))

Check failure on line 21 in Firestore/Swift/Source/SwiftAPI/SwiftCppAPI.swift

View workflow job for this annotation

GitHub Actions / platforms (catalyst)

no exact matches in call to initializer

Check failure on line 21 in Firestore/Swift/Source/SwiftAPI/SwiftCppAPI.swift

View workflow job for this annotation

GitHub Actions / platforms (catalyst)

no exact matches in call to initializer
}
}
2 changes: 2 additions & 0 deletions Firestore/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ firebase_ios_glob(
src/objc/*.h
src/remote/*.cc
src/remote/*.h
swift/include/*.h
swift/src/*.cc
EXCLUDE ${nanopb_sources}
)

Expand Down
22 changes: 22 additions & 0 deletions Firestore/core/swift/include/FirebaseFirestoreCpp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2024 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.
*/

#ifndef FIREBASE_FIREBASEFIRESTORECPP_H
#define FIREBASE_FIREBASEFIRESTORECPP_H

#import "used_by_swift.h"

#endif // FIREBASE_FIREBASEFIRESTORECPP_H
27 changes: 27 additions & 0 deletions Firestore/core/swift/include/used_by_swift.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2024 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.
*/

#ifndef FIREBASE_USED_BY_SWIFT_H
#define FIREBASE_USED_BY_SWIFT_H

#include <string>

Check failure on line 20 in Firestore/core/swift/include/used_by_swift.h

View workflow job for this annotation

GitHub Actions / client-app-spm-source-firestore (iOS, ClientApp)

'string' file not found

Check failure on line 20 in Firestore/core/swift/include/used_by_swift.h

View workflow job for this annotation

GitHub Actions / client-app-spm-source-firestore (iOS, ClientApp)

'string' file not found

Check failure on line 20 in Firestore/core/swift/include/used_by_swift.h

View workflow job for this annotation

GitHub Actions / client-app-spm-source-firestore (iOS, ClientApp)

'string' file not found

Check failure on line 20 in Firestore/core/swift/include/used_by_swift.h

View workflow job for this annotation

GitHub Actions / client-app-spm-source-firestore (iOS, ClientApp)

'string' file not found

Check failure on line 20 in Firestore/core/swift/include/used_by_swift.h

View workflow job for this annotation

GitHub Actions / client-app-spm-source-firestore (iOS, ClientApp)

'string' file not found

class UsedBySwift {
public:
explicit UsedBySwift(std::string content);
};

#endif // FIREBASE_USED_BY_SWIFT_H
22 changes: 22 additions & 0 deletions Firestore/core/swift/src/used_by_swift.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2024 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.
*/

#include "../include/used_by_swift.h"
#include <iostream>

UsedBySwift::UsedBySwift(std::string content) {
std::cout << "ctor runs with value: " << content << std::endl;
}
33 changes: 30 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,10 @@ let package = Package(
dependencies: [
"FirebaseFirestoreTarget",
],
path: "FirebaseCombineSwift/Sources/Firestore"
path: "FirebaseCombineSwift/Sources/Firestore",
swiftSettings: [
.interoperabilityMode(.Cxx), // C++ interoperability setting
]
),
.target(
name: "FirebaseStorageCombineSwift",
Expand Down Expand Up @@ -1171,7 +1174,10 @@ let package = Package(
"FirebaseStorage",
.product(name: "nanopb", package: "nanopb"),
],
path: "SwiftPMTests/swift-test"
path: "SwiftPMTests/swift-test",
swiftSettings: [
.interoperabilityMode(.Cxx), // C++ interoperability setting
]
),
.testTarget(
name: "analytics-import-test",
Expand Down Expand Up @@ -1399,6 +1405,17 @@ func firestoreWrapperTarget() -> Target {
)
}

func firebaseFirestoreCppTarget() -> Target {
return .target(
name: "FirebaseFirestoreCpp",
path: "Firestore/core/swift",
publicHeadersPath: "include", // Path to the public headers
cxxSettings: [
.headerSearchPath("include"), // Ensure the header search path is correct
]
)
}

func firestoreTargets() -> [Target] {
if ProcessInfo.processInfo.environment["FIREBASE_SOURCE_FIRESTORE"] != nil {
return [
Expand Down Expand Up @@ -1469,13 +1486,15 @@ func firestoreTargets() -> [Target] {
.linkedLibrary("c++"),
]
),
firebaseFirestoreCppTarget(),
.target(
name: "FirebaseFirestore",
dependencies: [
"FirebaseCore",
"FirebaseCoreExtension",
"FirebaseFirestoreInternalWrapper",
"FirebaseSharedSwift",
"FirebaseFirestoreCpp",
],
path: "Firestore",
exclude: [
Expand All @@ -1496,7 +1515,10 @@ func firestoreTargets() -> [Target] {
sources: [
"Swift/Source/",
],
resources: [.process("Source/Resources/PrivacyInfo.xcprivacy")]
resources: [.process("Source/Resources/PrivacyInfo.xcprivacy")],
swiftSettings: [
.interoperabilityMode(.Cxx), // C++ interoperability setting
]
),
]
}
Expand Down Expand Up @@ -1542,9 +1564,13 @@ func firestoreTargets() -> [Target] {
"FirebaseCoreExtension",
"leveldb",
"FirebaseSharedSwift",
"FirebaseFirestoreCpp",
],
path: "Firestore/Swift/Source",
resources: [.process("Resources/PrivacyInfo.xcprivacy")],
swiftSettings: [
.interoperabilityMode(.Cxx), // C++ interoperability setting
],
linkerSettings: [
.linkedFramework("SystemConfiguration", .when(platforms: [.iOS, .macOS, .tvOS])),
.linkedFramework("UIKit", .when(platforms: [.iOS, .tvOS])),
Expand All @@ -1561,5 +1587,6 @@ func firestoreTargets() -> [Target] {
publicHeadersPath: "."
),
firestoreInternalTarget,
firebaseFirestoreCppTarget(),
]
}
Loading