Skip to content

Add reduct-cpp #27398

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

Open
wants to merge 15 commits into
base: master
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
8 changes: 8 additions & 0 deletions recipes/reduct-cpp/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sources:
"1.15.0":
url: "https://github.com/reductstore/reduct-cpp/archive/refs/tags/v1.15.0.tar.gz"
sha256: "120caa687389b6a0f9d05b1d1b8670640e63aaeaf2463714427d7cd353220b86"
patches:
"1.15.0":
- patch_file: "patches/0001-1.15.0-disable-conan-lookup.patch"
patch_type: "conan"
121 changes: 121 additions & 0 deletions recipes/reduct-cpp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import os
from os.path import join

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get, rmdir, export_conandata_patches, apply_conandata_patches

required_conan_version = ">=2"


class ReductCppConan(ConanFile):
name = "reduct-cpp"
description = "Reduct Storage Client SDK for C++"
license = "MIT"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://www.reduct.store/docs/getting-started/with-cpp"
topics = ("reduct-storage", "http-client", "http-api")
package_type = "library"
settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
"fPIC": [True, False],
"with_chrono": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"with_chrono": False,
}

implements = ["auto_shared_fpic"]

def export_sources(self):
export_conandata_patches(self)

def requirements(self):
self.requires("fmt/11.0.2", transitive_headers=True, transitive_libs=True)
self.requires("cpp-httplib/0.14.1")
self.requires("nlohmann_json/3.11.3")
self.requires("openssl/[>=1.1 <4]", transitive_headers=True, transitive_libs=True)
self.requires("concurrentqueue/1.0.4")
if not self.options.with_chrono:
self.requires("date/3.0.1")

def validate(self):
check_min_cppstd(self, 20)

httplib = self.dependencies["cpp-httplib"]

if not httplib.options.with_openssl:
raise ConanInvalidConfiguration("cpp-httplib must be built with OpenSSL")

if not httplib.options.with_zlib:
raise ConanInvalidConfiguration("cpp-httplib must be built with zlib")

if self.options.with_chrono:
date = self.dependencies["date"]
if not date.options.header_only:
raise ConanInvalidConfiguration("date must be built as header-only")

if self.settings.get_safe("os") == "Windows" and not self.options.with_chrono:
raise ConanInvalidConfiguration("ReductCpp requires chrono on Windows.")

elif self.settings.get_safe("compiler") == "gcc":
if (
self.settings.get_safe("compiler.version") < "14"
and self.options.with_chrono
):
raise ConanInvalidConfiguration(
"ReductCpp with chrono requires GCC 14 or higher. "
)
elif (
self.settings.get_safe("compiler.version") >= "14"
and not self.options.with_chrono
):
raise ConanInvalidConfiguration(
"ReductCpp requires chrono with GCC 14 or higher. "
)

def layout(self):
cmake_layout(self, src_folder="src")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
apply_conandata_patches(self)

def generate(self):
tc = CMakeToolchain(self)
if self.options.with_chrono:
tc.cache_variables["REDUCT_CPP_USE_STD_CHRONO"] = True
tc.cache_variables["REDUCT_CPP_USE_CONAN"] = True
tc.generate()

deps = CMakeDeps(self)
deps.generate()

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(
self,
"LICENSE",
src=self.source_folder,
dst=os.path.join(self.package_folder, "licenses"),
)
cmake = CMake(self)
cmake.install()

rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.libs = ["reductcpp"]
self.cpp_info.set_property("cmake_file_name", "ReductCpp")
self.cpp_info.set_property("cmake_target_name", "reductcpp")
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
diff --git a/cmake/InstallDependencies.cmake b/cmake/InstallDependencies.cmake
index 8171db3..33b0a00 100644
--- a/cmake/InstallDependencies.cmake
+++ b/cmake/InstallDependencies.cmake
@@ -1,12 +1,4 @@
if(REDUCT_CPP_USE_CONAN)
- message(STATUS "Using Conan to fetch dependencies")
- find_program(CONAN conan)
- if(NOT CONAN)
- message(
- FATAL_ERROR
- "Conan not found. Please install Conan and run cmake again"
- )
- endif()

find_package(fmt REQUIRED)
find_package(nlohmann_json REQUIRED)
7 changes: 7 additions & 0 deletions recipes/reduct-cpp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

find_package(ReductCpp REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE reductcpp)
25 changes: 25 additions & 0 deletions recipes/reduct-cpp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain"

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
12 changes: 12 additions & 0 deletions recipes/reduct-cpp/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "reduct/client.h"

#include <iostream>

using reduct::IBucket;
using reduct::IClient;

/* It's a constructor with no network calls, so it's safe to use in test */
int main() {
auto client = IClient::Build("http://127.0.0.1:8383");
return EXIT_SUCCESS;
}
3 changes: 3 additions & 0 deletions recipes/reduct-cpp/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.15.0":
folder: all