Skip to content

Commit

Permalink
C API for Core / Object Store (#3955)
Browse files Browse the repository at this point in the history
* List: Expose insert_any/set_any/get_any

* C wrapper API basics

* Constify Results::is_frozen()

* C API: Query functions

* const fixes

* Rename realm_err_info_t to realm_error_t

* Reorder typedefs

* TypedLink to realm_value_t

* List type checking

* List tests

* Document more things

* Option to disable __declspec(dllimport) on Win32

* Build C API as a separate library, and export it

* Typo

* Remove no-unused compiler flag

* Define RLM_NO_DLLIMPORT publicly

* FFI: Sync opt-out

* Disable unrelated failing test

* Typo

* FFI: -landroid for .so file

* FFI: -llog for .so on android

* FFI: Workaround for missing thread_local (iOS)

* Remove debug #define

* C API: Catch query parser errors

* Revert unnecessary changes to list.hpp/.cpp

* C API: Object Notifications

* Fix conversion realm_string_t -> std::string

* More tests, more checks, more errors

* Add bulk get/set properties

* Don't compile realm.c, since it appears to cause trouble

* C API: Split implementation into separate cpp files

* Collapse before/after notification callbacks

* Scheduler API

* Fix build on Android

* realm_equals()

* Collection notifications

* By-index collection changes

* Test

* More documentation

* Query builder API

* Query results notifications

* Disable Query builder API

* Query support

* Remove outlines of object accessor, query build APIs

* Missing _t

* Export the RealmFFIStatic CMake target

* Set include dirs for exported CMake target

* Disable realm_scheduler_set_default_factory for now

* Reenable default scheduler factory functions

* ThreadSafeReference API

* Don't link GenericScheduler twice

* Another GenericScheduler fix

* Another GenericScheduler fix (part 2)

* Include util/overloaded.hpp

* realm_thread_safe_reference_t revamp

* Support Scheduler::is_same_as

* util::overloaded -> util::overload

* UUID support

* PropertyType::Any -> PropertyType::Mixed

* Dict/Set schema support

* Guarantee zero-termination of error messages

* Document thread safe references of SharedRealm

* Use clang-format-11

* Don't build C API dynamic library

* Fix DataType switch statements

* Expose Object::verify_attached()

* Use verify_attached() instead of is_valid()

* Simplify wrap_err

* realm_is_closed(), realm_is_writable()

* realm_object_get_table()

* Small C API smoke test written in C

* Leaks

* Exclude C API from Package.swift

* Remove unused function

* Use const char* instead of realm_string_t in API functions

* Add modulemap file for SPM consumption

* realm_class_key_t, realm_property_key_t, realm_object_key_t rename, change to int typedefs

* Fix reported number of properties

Co-authored-by: Jason Flax <[email protected]>

* Add tests for schema; move capi tests to own dir

* set_schema => update schema; clean up test; data => c_str

* Fix warning

* realm_release(const void* -> void*), remove unused functions

* Move cast_ptr to util.cpp

* Simplify schema_for_table

* Cosmetic null check

* Test realm_equals()

* Missing 'void' in zero-argument functions

* realm/realm.h -> realm.h

* Prevent spurious callbacks for notifications

* Fix warnings

* realm_object_find_all()

* Fix more warnings

* Remove unnecessary wrap_err

* fix cmakeslists for tests

* Fix package.swift; add method signatures to second realm.h

* Fix test for windows

* appease linter

* free mallocd memory in test

* release schema in test

* Remove duplicate realm.h

* remove extra realm.h

* fix warning

* fix modulemap

Co-authored-by: Jason Flax <[email protected]>
  • Loading branch information
simonask and jsflax authored Jan 11, 2021
1 parent 5cf0956 commit 6d3ce14
Show file tree
Hide file tree
Showing 28 changed files with 5,763 additions and 11 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if(ANDROID)
if(NOT APPLE)
# TODO: Core APIs should always built for internal usage. But there seems to be issues with cocoa. Enable it only for Android for now.
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
elseif(APPLE)
Expand Down Expand Up @@ -291,6 +291,8 @@ set(REALM_EXPORTED_TARGETS
Storage
QueryParser
ObjectStore
RealmFFI
RealmFFIStatic
)
if(REALM_ENABLE_SYNC)
list(APPEND REALM_EXPORTED_TARGETS Sync)
Expand Down
52 changes: 48 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ let package = Package(
.library(
name: "RealmObjectStore",
targets: ["ObjectStore"]),
.library(
name: "RealmCapi",
targets: ["Capi"]),
.library(
name: "RealmFFI",
targets: ["FFI"]),
],
targets: [
.target(
Expand Down Expand Up @@ -112,7 +118,8 @@ let package = Package(
"realm/util/network.cpp",
"realm/util/network_ssl.cpp",
"realm/util/http.cpp",
"realm/util/websocket.cpp"
"realm/util/websocket.cpp",
"realm/realm.h"
],
sources: [
"realm"
Expand Down Expand Up @@ -165,12 +172,13 @@ let package = Package(
]),
.target(
name: "ObjectStore",
dependencies: ["Storage", "QueryParser", "SyncClient"],
dependencies: ["SyncClient", "QueryParser"],
path: "src",
exclude: [
"realm/object-store/impl/epoll",
"realm/object-store/impl/generic",
"realm/object-store/impl/windows"
"realm/object-store/impl/windows",
"realm/object-store/c_api"
],
sources: ["realm/object-store"],
publicHeadersPath: "realm/object-store",
Expand All @@ -179,19 +187,55 @@ let package = Package(
.define("REALM_PLATFORM_APPLE", to: "1", .when(platforms: [.macOS, .iOS, .tvOS, .watchOS])),
.headerSearchPath("realm/object-store")
] + cxxSettings) as [CXXSetting]),
.target(
name: "Capi",
dependencies: ["ObjectStore"],
path: "src",
exclude: [
"realm/object-store/c_api/realm.c"
],
sources: ["realm/object-store/c_api"],
publicHeadersPath: "realm/object-store/c_api",
cxxSettings: ([
.define("REALM_ENABLE_SYNC", to: "1"),
.define("REALM_PLATFORM_APPLE", to: "1", .when(platforms: [.macOS, .iOS, .tvOS, .watchOS])),
.headerSearchPath("external/pegtl/include/tao")
] + cxxSettings) as [CXXSetting]),
.target(
name: "FFI",
dependencies: ["Capi"],
path: "src/swift"),
.target(
name: "ObjectStoreTests",
dependencies: ["ObjectStore", "SyncServer"],
path: "test/object-store",
exclude: [
"benchmarks",
"notifications-fuzzer"
"notifications-fuzzer",
"c_api"
],
cxxSettings: ([
.define("REALM_ENABLE_SYNC", to: "1"),
.define("REALM_PLATFORM_APPLE", to: "1", .when(platforms: [.macOS, .iOS, .tvOS, .watchOS])),
.headerSearchPath("."),
.headerSearchPath("../../external/catch/single_include")
] + cxxSettings) as [CXXSetting]),
.target(
name: "CapiTests",
dependencies: ["Capi"],
path: "test/object-store/c_api",
exclude: [
"benchmarks",
"mongodb",
"notifications-fuzzer",
"sync",
"util"
],
cxxSettings: ([
.define("REALM_ENABLE_SYNC", to: "1"),
.define("REALM_PLATFORM_APPLE", to: "1", .when(platforms: [.macOS, .iOS, .tvOS, .watchOS])),
.headerSearchPath("../"),
.headerSearchPath("../../../external/catch/single_include")
] + cxxSettings) as [CXXSetting])
],
cxxLanguageStandard: .cxx1z
Expand Down
5 changes: 5 additions & 0 deletions src/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module RealmFFI {
header "realm.h"

export *
}
Loading

0 comments on commit 6d3ce14

Please sign in to comment.