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 15 commits into
base: main
Choose a base branch
from
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
12 changes: 11 additions & 1 deletion FirebaseFirestore.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,30 @@ Google Cloud Firestore is a NoSQL document database built for automatic scaling,
s.cocoapods_version = '>= 1.12.0'
s.prefix_header_file = false

s.public_header_files = 'FirebaseFirestoreInternal/**/*.h'
s.public_header_files = [
'FirebaseFirestoreInternal/**/*.h',
'Firestore/Swift/Source/SwiftAPI/*.swift',
Copy link
Member

Choose a reason for hiding this comment

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

Swift files should not be in the headers

]

s.requires_arc = true
s.source_files = [
'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/umbrella/*.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/include" '
}

s.compiler_flags = '$(inherited) -Wreorder -Werror=reorder -Wno-comma'
end
14 changes: 14 additions & 0 deletions Firestore/Swift/Source/SwiftAPI/SwiftCppAPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// SwiftCppAPI.swift
// Firebase
//
// Created by Cheryl Lin on 2024-10-22.
//

import FirebaseFirestoreCpp

public class SwiftCppWrapper {
public init(_ value : String ){
_ = UsedBySwift(std.string(value))
}
}
3 changes: 3 additions & 0 deletions Firestore/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ firebase_ios_glob(
src/objc/*.h
src/remote/*.cc
src/remote/*.h
swift/include/*.h
swift/src/*.cc
swift/umbrella/*.h
EXCLUDE ${nanopb_sources}
)

Expand Down
15 changes: 15 additions & 0 deletions Firestore/core/swift/include/used_by_swift.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Created by Cheryl Lin on 2024-10-22.
//

#ifndef FIREBASE_USED_BY_SWIFT_H
#define FIREBASE_USED_BY_SWIFT_H

#include <string>

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

#endif // FIREBASE_USED_BY_SWIFT_H
10 changes: 10 additions & 0 deletions Firestore/core/swift/src/used_by_swift.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// Created by Cheryl Lin on 2024-10-22.
//

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

UsedBySwift::UsedBySwift(std::string content) {
std::cout << "ctor runs with value: " << content << std::endl;
}
10 changes: 10 additions & 0 deletions Firestore/core/swift/umbrella/FirebaseFirestoreCpp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// Created by Cheryl Lin on 2024-10-22.
//

#ifndef FIREBASE_FIREBASEFIRESTORECPP_H
#define FIREBASE_FIREBASEFIRESTORECPP_H

#import "../include/used_by_swift.h"

#endif // FIREBASE_FIREBASEFIRESTORECPP_H
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("umbrella"), // 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