Skip to content

Commit

Permalink
Merge 92d1380 into 0d569cf
Browse files Browse the repository at this point in the history
  • Loading branch information
cherylEnkidu authored Dec 17, 2024
2 parents 0d569cf + 92d1380 commit 68bf0dc
Show file tree
Hide file tree
Showing 33 changed files with 879 additions and 238 deletions.
4 changes: 3 additions & 1 deletion FirebaseCombineSwift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ for internal testing only. It should not be published.

s.pod_target_xcconfig = {
'HEADER_SEARCH_PATHS' => '"${PODS_TARGET_SRCROOT}"',
'SWIFT_OBJC_INTEROP_MODE' => 'objcxx',
}

s.test_spec 'unit' do |unit_tests|
Expand All @@ -81,7 +82,8 @@ for internal testing only. It should not be published.
unit_tests.exclude_files = 'FirebaseCombineSwift/Tests/Unit/**/*Template.swift'
unit_tests.requires_app_host = true
unit_tests.pod_target_xcconfig = {
'SWIFT_OBJC_BRIDGING_HEADER' => '$(PODS_TARGET_SRCROOT)/FirebaseCombineSwift/Tests/Unit/FirebaseCombine-unit-Bridging-Header.h'
'SWIFT_OBJC_BRIDGING_HEADER' => '$(PODS_TARGET_SRCROOT)/FirebaseCombineSwift/Tests/Unit/FirebaseCombine-unit-Bridging-Header.h',
'SWIFT_OBJC_INTEROP_MODE' => 'objcxx',
}
unit_tests.dependency 'OCMock'
unit_tests.dependency 'FirebaseAuthTestingSupport'
Expand Down
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
6 changes: 6 additions & 0 deletions FirebaseFirestore.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ 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'
}
Expand Down
6 changes: 5 additions & 1 deletion FirebaseFirestoreInternal.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ Google Cloud Firestore is a NoSQL document database built for automatic scaling,
# Header files that constitute the interface to this module. Only Objective-C
# headers belong here, since FirebaseFirestore is primarily an Objective-C
# framework.
s.public_header_files = 'Firestore/Source/Public/FirebaseFirestore/*.h'
s.public_header_files = [
'Firestore/Source/Public/FirebaseFirestore/*.h',
'Firestore/core/swift/include/*.h'
]

# source_files contains most of the header and source files for the project.
# This includes files named in `public_header_files`.
Expand All @@ -52,6 +55,7 @@ Google Cloud Firestore is a NoSQL document database built for automatic scaling,
'Firestore/core/include/**/*.{cc,mm}',
'Firestore/core/src/**/*.{cc,mm}',
'FirebaseAuth/Interop/**/*.h',
'Firestore/core/swift/**/*.{cc,h}',
]

# Internal headers that aren't necessarily globally unique. Most C++ internal
Expand Down
481 changes: 250 additions & 231 deletions Firestore/Example/Firestore.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions Firestore/Source/API/FIRFirestore+Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ NS_ASSUME_NONNULL_BEGIN

- (const std::shared_ptr<firebase::firestore::util::AsyncQueue> &)workerQueue;

@property(nonatomic, assign, readonly) std::shared_ptr<api::Firestore> wrapped;

@property(nonatomic, assign, readonly) const model::DatabaseId &databaseID;
@property(nonatomic, strong, readonly) FSTUserDataReader *dataReader;

Expand Down
36 changes: 36 additions & 0 deletions Firestore/Source/API/FIRInterface.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 <Foundation/Foundation.h>

#import "Firestore/Source/Public/FirebaseFirestore/FIRInterface.h"

#import "Firestore/core/src/api/used_by_objective_c.h"
#include "Firestore/core/src/util/string_apple.h"

using firebase::firestore::util::MakeString;

NS_ASSUME_NONNULL_BEGIN

@implementation FIRInterface

+ (void)print:(NSString *)content {
CppInterfaceCalledByObjectiveC::print(MakeString(content));
}

@end

NS_ASSUME_NONNULL_END
13 changes: 13 additions & 0 deletions Firestore/Source/Public/FirebaseFirestore/FIRFirestore.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

#import <Foundation/Foundation.h>
#import <memory>

#import "FIRListenerRegistration.h"

Expand All @@ -30,6 +31,16 @@
@class FIRWriteBatch;
@class FIRPersistentCacheIndexManager;

namespace firebase {
namespace firestore {
namespace api {
class Firestore;
} // namespace api
} // namespace firestore
} // namespace firebase

namespace api = firebase::firestore::api;

NS_ASSUME_NONNULL_BEGIN

/**
Expand Down Expand Up @@ -91,6 +102,8 @@ NS_SWIFT_NAME(Firestore)
*/
+ (instancetype)firestoreForDatabase:(NSString *)database NS_SWIFT_NAME(firestore(database:));

@property(nonatomic, assign, readonly) std::shared_ptr<api::Firestore> wrapped;

/**
* Custom settings used to configure this `Firestore` object.
*/
Expand Down
29 changes: 29 additions & 0 deletions Firestore/Source/Public/FirebaseFirestore/FIRInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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 <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface FIRInterface : NSObject

#pragma mark - Create Filter

+ (void)print:(NSString *)content;

@end

NS_ASSUME_NONNULL_END
4 changes: 4 additions & 0 deletions Firestore/Swift/Source/AsyncAwait/Firestore+AsyncAwait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,8 @@ public extension Firestore {
}
}
}

func pipeline() -> PipelineSource {
return PipelineSource(firebase.firestore.api.FirestorePipeline.pipeline(wrapped))
}
}
14 changes: 14 additions & 0 deletions Firestore/Swift/Source/SwiftAPI/PipelineSource.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// PipelineSource.swift
// Pods
//
// Created by Cheryl Lin on 2024-12-12.
//

public class PipelineSource {
let cppPtr: firebase.firestore.api.PipelineSource

public init(_ cppSource: firebase.firestore.api.PipelineSource) {
cppPtr = cppSource
}
}
25 changes: 25 additions & 0 deletions Firestore/Swift/Source/SwiftAPI/SwiftCppAPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.
*/

#if SWIFT_PACKAGE
@_exported import FirebaseFirestoreCpp
#endif // SWIFT_PACKAGE

public class SwiftCallingCpp {
public init(_ value: String) {
CppInterfaceCalledBySwift.print(std.string(value))
}
}
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
4 changes: 4 additions & 0 deletions Firestore/core/src/api/firestore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ void Firestore::SetClientLanguage(std::string language_token) {
GrpcConnection::SetClientLanguage(std::move(language_token));
}

PipelineSource Firestore::pipeline() {
return {shared_from_this()};
}

std::unique_ptr<ListenerRegistration> Firestore::AddSnapshotsInSyncListener(
std::unique_ptr<core::EventListener<Empty>> listener) {
EnsureClientConfigured();
Expand Down
3 changes: 3 additions & 0 deletions Firestore/core/src/api/firestore.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "Firestore/core/src/model/database_id.h"
#include "Firestore/core/src/util/byte_stream.h"
#include "Firestore/core/src/util/status_fwd.h"
#include "Firestore/core/swift/include/pipeline_source.h"

namespace firebase {
namespace firestore {
Expand Down Expand Up @@ -125,6 +126,8 @@ class Firestore : public std::enable_shared_from_this<Firestore> {
*/
static void SetClientLanguage(std::string language_token);

PipelineSource pipeline();

private:
void EnsureClientConfigured();
core::DatabaseInfo MakeDatabaseInfo() const;
Expand Down
22 changes: 22 additions & 0 deletions Firestore/core/src/api/used_by_objective_c.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 "used_by_objective_c.h"
#include <iostream>

void CppInterfaceCalledByObjectiveC::print(std::string content) {
std::cout << "C++ function runs with value: " << content << std::endl;
}
27 changes: 27 additions & 0 deletions Firestore/core/src/api/used_by_objective_c.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>

class CppInterfaceCalledByObjectiveC {
public:
static void print(std::string content);
};

#endif // FIREBASE_USED_BY_SWIFT_H
27 changes: 27 additions & 0 deletions Firestore/core/swift/include/FirebaseFirestoreCpp.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_FIREBASEFIRESTORECPP_H
#define FIREBASE_FIREBASEFIRESTORECPP_H

#import "collection_stage.h"
#import "firestore_pipeline.h"
#import "pipeline.h"
#import "pipeline_source.h"
#import "stage.h"
#import "used_by_swift.h"

#endif // FIREBASE_FIREBASEFIRESTORECPP_H
29 changes: 29 additions & 0 deletions Firestore/core/swift/include/collection_stage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// Created by Cheryl Lin on 2024-12-11.
//

#ifndef FIREBASE_COLLECTION_GROUP_STAGE_H
#define FIREBASE_COLLECTION_GROUP_STAGE_H

#include <string>
#include "stage.h"

namespace firebase {
namespace firestore {

namespace api {

class Collection : public Stage {
public:
Collection(std::string collection_path);

private:
std::string collection_path_;
};

} // namespace api

} // namespace firestore
} // namespace firebase

#endif // FIREBASE_COLLECTION_GROUP_STAGE_H
25 changes: 25 additions & 0 deletions Firestore/core/swift/include/firestore_pipeline.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Created by Cheryl Lin on 2024-12-10.
//

#ifndef FIREBASE_FIRESTORE_PIPELINE_H
#define FIREBASE_FIRESTORE_PIPELINE_H

#include "pipeline_source.h"

namespace firebase {
namespace firestore {

namespace api {
class Firestore;

class FirestorePipeline {
public:
static PipelineSource pipeline(std::shared_ptr<Firestore> firestore);
};

} // namespace api
} // namespace firestore
} // namespace firebase

#endif // FIREBASE_FIRESTORE_PIPELINE_H
Loading

0 comments on commit 68bf0dc

Please sign in to comment.