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

RCPP-8 Prepare vcpkg for submission #210

Merged
merged 21 commits into from
Jun 18, 2024
Merged
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
16 changes: 6 additions & 10 deletions .github/workflows/vcpkg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ jobs:
with:
submodules: 'recursive'

- name: "Set environmental variables"
shell: bash
run: |
echo "VCPKG_ROOT=$VCPKG_INSTALLATION_ROOT" >> $GITHUB_ENV
- uses: friendlyanon/setup-vcpkg@v1
with: { committish: 6e31ee33cc9fc93599c4ceb38e229098cf339bb7 }

- name: Install dependencies
if: matrix.os == 'ubuntu-latest'
Expand All @@ -41,7 +39,7 @@ jobs:
working-directory: ./tests
if: matrix.os == 'macos-latest'
run: |
cmake -GNinja -B build -S . -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DVCPKG_OVERLAY_PORTS="../ports" -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DVCPKG_TARGET_TRIPLET=x64-osx
cmake -GNinja -B build -S . -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DVCPKG_OVERLAY_PORTS="../ports" -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DVCPKG_TARGET_TRIPLET=arm64-osx
cd build
cmake --build . --config ${{matrix.build_type}}

Expand Down Expand Up @@ -88,10 +86,8 @@ jobs:
with:
submodules: 'recursive'

- name: "Set environmental variables"
shell: bash
run: |
echo "VCPKG_ROOT=$VCPKG_INSTALLATION_ROOT" >> $GITHUB_ENV
- uses: friendlyanon/setup-vcpkg@v1
with: { committish: 6e31ee33cc9fc93599c4ceb38e229098cf339bb7 }

- name: Install dependencies
if: matrix.os == 'ubuntu-latest'
Expand All @@ -108,7 +104,7 @@ jobs:
working-directory: ./tests
if: matrix.os == 'macos-latest'
run: |
cmake -GNinja -B build -S . -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DVCPKG_OVERLAY_PORTS="../ports" -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DVCPKG_TARGET_TRIPLET=x64-osx-dynamic
cmake -GNinja -B build -S . -DCMAKE_TOOLCHAIN_FILE="$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" -DVCPKG_OVERLAY_PORTS="../ports" -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DVCPKG_TARGET_TRIPLET=arm64-osx-dynamic
cd build
cmake --build . --config ${{matrix.build_type}}

Expand Down
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ X.Y.Z Release notes (YYYY-MM-DD)
=============================================================

### Fixed
* Fixed a compilation issue seen in MSBuild 17.10.4 due to usage of `std::apply`.
* Fixed a compilation issue seen in MSVC 19.40.33811 due to usage of `std::apply`.

### Enhancements
* None
* Add `realm::default_scheduler::set_default_factory(std::function<std::shared_ptr<realm::scheduler>()>&& factory_fn)` for generating a default scheduler.
Set your scheduler factory before instantiating a `realm::db_config`.
* Add `realm::default_scheduler::make_default()` which generates a platform default scheduler if `realm::default_scheduler::set_default_factory` is not set.

### Compatibility
* Fileformat: Generates files with format v24. Reads and automatically upgrade from fileformat v10.
Expand Down
20 changes: 14 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(REALM_USE_SYSTEM_OPENSSL ON)
endif()

add_subdirectory(realm-core)

if (VCPKG_TOOLCHAIN)
find_package(Realm REQUIRED)
else()
add_subdirectory(realm-core)
endif()

set(REALM_NO_CONFIG)
set(REALM_ENABLE_SYNC)
Expand Down Expand Up @@ -49,6 +54,13 @@ add_compile_definitions(REALM_ENABLE_ENCRYPTION)
add_compile_definitions(REALM_INSTALL_LIBEXECDIR)
add_compile_definitions(REALM_BUILD_LIB_ONLY)

# on Apple platforms we use the built-in CFRunLoop
# everywhere else it's libuv, except UWP where it doesn't build
Copy link
Contributor

Choose a reason for hiding this comment

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

And I assume that UWP is checked by WINDOWS_STORE

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed

if(NOT APPLE AND NOT WINDOWS_STORE AND NOT ANDROID)
set(REALM_HAVE_UV 1)
leemaguire marked this conversation as resolved.
Show resolved Hide resolved
add_compile_definitions(REALM_HAVE_UV=1)
leemaguire marked this conversation as resolved.
Show resolved Hide resolved
endif()

configure_file(src/cpprealm/util/config.h.in include/cpprealm/util/config.h)

add_subdirectory(src)
Expand All @@ -65,9 +77,7 @@ target_include_directories(${PROJECT_NAME}
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

# on Apple platforms we use the built-in CFRunLoop
# everywhere else it's libuv, except UWP where it doesn't build
if(NOT APPLE AND NOT WINDOWS_STORE AND NOT ANDROID)
if(REALM_HAVE_UV)
if(VCPKG_TOOLCHAIN)
find_package(libuv CONFIG REQUIRED)
if(BUILD_SHARED_LIBS)
Expand Down Expand Up @@ -102,9 +112,7 @@ if(NOT APPLE AND NOT WINDOWS_STORE AND NOT ANDROID)
endif()
endif()

target_compile_definitions(ObjectStore PUBLIC REALM_HAVE_UV=1)
target_link_libraries(cpprealm PUBLIC ${libuv_target})
target_link_libraries(ObjectStore PUBLIC ${libuv_target})
endif()

target_link_libraries(cpprealm PUBLIC Realm::ObjectStore)
Expand Down
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def source(self):
git = Git(self)
git.clone(url="https://github.com/realm/realm-cpp", target=".")
git.folder = "."
git.checkout(commit="70ccfd7254b8b76fe63119b9a12528cf7e84ca69")
git.checkout(commit="fd20cf3d9f226dac8a21c89300728ac9be8bd2e2")
git.run("submodule update --init --recursive")

def layout(self):
Expand Down
9 changes: 5 additions & 4 deletions include/cpprealm/internal/bridge/realm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
#ifndef CPPREALM_BRIDGE_REALM_HPP
#define CPPREALM_BRIDGE_REALM_HPP

#include <cpprealm/internal/bridge/utils.hpp>

#include <functional>
#include <map>
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include <cpprealm/internal/bridge/utils.hpp>

namespace realm {
class Realm;
Expand Down Expand Up @@ -176,8 +177,8 @@ namespace realm::internal::bridge {
manual
};
config();
config(const config& other) ;
config& operator=(const config& other) ;
config(const config& other);
config& operator=(const config& other);
config(config&& other);
config& operator=(config&& other);
~config();
Expand All @@ -186,7 +187,7 @@ namespace realm::internal::bridge {
const std::shared_ptr<struct scheduler>& scheduler);
[[nodiscard]] std::string path() const;
[[nodiscard]] struct sync_config sync_config() const;
[[nodiscard]] std::shared_ptr<struct scheduler> scheduler();
[[nodiscard]] std::shared_ptr<struct scheduler> scheduler() const;
operator RealmConfig() const; //NOLINT(google-explicit-constructor)
void set_path(const std::string&);
void set_schema(const std::vector<object_schema>&);
Expand Down
74 changes: 74 additions & 0 deletions include/cpprealm/internal/scheduler/realm_core_scheduler.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2024 Realm Inc.
//
// 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 CPPREALM_REALM_CORE_SCHEDULER_HPP
#define CPPREALM_REALM_CORE_SCHEDULER_HPP

#include <cpprealm/scheduler.hpp>

namespace realm {
namespace util {
class Scheduler;
}
}
namespace realm::internal {

/**
* A type erased scheduler used for wrapping default scheduler implementations from RealmCore.
*/
struct realm_core_scheduler final : public scheduler {
/**
* Invoke the given function on the scheduler's thread.
* This function can be called from any thread.
*/
void invoke(std::function<void()> &&fn) final;

/**
* Check if the caller is currently running on the scheduler's thread.
* This function can be called from any thread.
*/
[[nodiscard]] bool is_on_thread() const noexcept final;

/**
* Checks if this scheduler instance wraps the same underlying instance.
* This is up to the platforms to define, but if this method returns true,
* caching may occur.
*/
bool is_same_as(const scheduler *other) const noexcept final;

/**
* Check if this scheduler actually can support invoke(). Invoking may be
* either not implemented, not applicable to a scheduler type, or simply not
* be possible currently (e.g. if the associated event loop is not actually
* running).
*
* This function is not thread-safe.
*/
[[nodiscard]] bool can_invoke() const noexcept final;
~realm_core_scheduler() final = default;
realm_core_scheduler() = delete;
explicit realm_core_scheduler(std::shared_ptr<util::Scheduler> s) : s(std::move(s)) {}
operator std::shared_ptr<util::Scheduler>();
private:
std::shared_ptr<util::Scheduler> s;
};

std::shared_ptr<util::Scheduler> create_scheduler_shim(const std::shared_ptr<scheduler>& s);
} // namespace realm::internal

#endif//CPPREALM_REALM_CORE_SCHEDULER_HPP
58 changes: 58 additions & 0 deletions include/cpprealm/schedulers/default_scheduler.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2024 Realm Inc.
//
// 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 CPPREALM_DEFAULT_SCHEDULERS_HPP
#define CPPREALM_DEFAULT_SCHEDULERS_HPP

#include <cpprealm/scheduler.hpp>

#if __has_include(<cpprealm/util/config.h>)
#include <cpprealm/util/config.h>
#endif

#if defined(REALM_HAVE_UV) && REALM_HAVE_UV
typedef struct uv_loop_s uv_loop_t;
#endif

namespace realm::default_scheduler {
/**
* Tries to choose a built in scheduler as default for the platform
* Current options are:
* - CFRunLoop for Apple platforms
* - UV for Linux and Windows
* - ALooper for Android
* If no suitable scheduler is available a generic scheduler will be provided.
*/
std::shared_ptr<scheduler> make_platform_default();

/**
* Register a factory function which can produce custom schedulers when
* `scheduler::make_default()` is called. This function is not thread-safe
* and must be called before any schedulers are created.
*/
void set_default_factory(std::function<std::shared_ptr<scheduler>()>&& factory_fn);

/**
* Create a new instance of the scheduler type returned by the default
* scheduler factory. By default, the factory function is
* `scheduler::make_platform_default()`.
*/
std::shared_ptr<scheduler> make_default();
} // namespace realm

#endif//CPPREALM_DEFAULT_SCHEDULERS_HPP
4 changes: 2 additions & 2 deletions include/cpprealm/sdk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
#ifndef CPPREALM_SDK_HPP
#define CPPREALM_SDK_HPP

#if __has_include(<cpprealm/config.h>)
#include <cpprealm/config.h>
#if __has_include(<cpprealm/util/config.h>)
#include <cpprealm/util/config.h>
#endif

#include <utility>
Expand Down
9 changes: 2 additions & 7 deletions ports/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ vcpkg_execute_required_process(
LOGNAME submodules
)

set(CPPREALM_CMAKE_OPTIONS -DREALM_CPP_NO_TESTS=ON -DREALM_CORE_SUBMODULE_BUILD=OFF)
set(CPPREALM_CMAKE_OPTIONS -DREALM_CPP_NO_TESTS=ON -DREALM_ENABLE_EXPERIMENTAL=ON)

if (ANDROID OR WIN32 OR CMAKE_SYSTEM_NAME STREQUAL "Linux")
list(APPEND CPPREALM_CMAKE_OPTIONS -DREALM_USE_SYSTEM_OPENSSL=ON)
Expand All @@ -24,7 +24,6 @@ vcpkg_cmake_configure(
vcpkg_cmake_install()

vcpkg_cmake_config_fixup(PACKAGE_NAME "cpprealm" CONFIG_PATH "cmake")
vcpkg_cmake_config_fixup(PACKAGE_NAME "Realm" CONFIG_PATH "share/cmake/Realm")

file(READ ${CURRENT_PACKAGES_DIR}/debug/include/cpprealm/internal/bridge/bridge_types.hpp DEBUG_TYPE_HEADER_CONTENTS)
set(REGEX_PATTERN "\\{([^()]*)\\}")
Expand All @@ -47,11 +46,7 @@ string(REGEX REPLACE "\\{([^()]*)\\}" "
" MODIFIED_HEADER "${DEBUG_TYPE_HEADER_CONTENTS}")

file(WRITE ${CURRENT_PACKAGES_DIR}/include/cpprealm/internal/bridge/bridge_types.hpp "${MODIFIED_HEADER}")

file(REMOVE_RECURSE
"${CURRENT_PACKAGES_DIR}/debug/include"
"${CURRENT_PACKAGES_DIR}/debug/share"
)
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")

file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")
11 changes: 3 additions & 8 deletions ports/vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Realm is a mobile database that runs directly inside phones, tablets or wearables.",
"homepage": "https://github.com/realm/realm-cpp",
"license": "Apache-2.0",
"supports": "!emscripten",
"dependencies": [
{
"name": "vcpkg-cmake",
Expand All @@ -24,14 +25,8 @@
"platform": "linux"
},
{
"name": "openssl",
"version>=": "3.2.0",
"platform": "!osx"
},
{
"name": "zlib",
"version>=": "1.3",
"platform": "!osx, !emscripten"
"name": "realm-core",
"version>=": "14.8.0"
}
]
}
10 changes: 9 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ set(SOURCES
cpprealm/internal/bridge/thread_safe_reference.cpp
cpprealm/internal/bridge/timestamp.cpp
cpprealm/internal/bridge/uuid.cpp
cpprealm/internal/scheduler/realm_core_scheduler.cpp
cpprealm/schedulers/default_scheduler.cpp
cpprealm/logger.cpp
cpprealm/sdk.cpp) # REALM_SOURCES

Expand Down Expand Up @@ -124,6 +126,8 @@ set(HEADERS
../include/cpprealm/internal/bridge/uuid.hpp
../include/cpprealm/internal/generic_network_transport.hpp
../include/cpprealm/internal/type_info.hpp
../include/cpprealm/internal/scheduler/realm_core_scheduler.hpp
../include/cpprealm/schedulers/default_scheduler.hpp
../include/cpprealm/logger.hpp
../include/cpprealm/notifications.hpp
../include/cpprealm/rbool.hpp
Expand All @@ -136,7 +140,11 @@ include(GNUInstallDirs)

add_library(cpprealm ${SOURCES} ${HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/cpprealm/internal/bridge/bridge_types.hpp)

install(TARGETS ${PROJECT_NAME} ObjectStore Storage QueryParser Sync
if (NOT VCPKG_TOOLCHAIN)
set(INSTALL_TARGETS ObjectStore Storage QueryParser Sync)
endif()

install(TARGETS ${PROJECT_NAME} ${INSTALL_TARGETS}
EXPORT "${PROJECT_NAME}Targets"
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} # include
)
Expand Down
Loading
Loading