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

aersopike-common: new recipe #23388

Open
wants to merge 11 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
4 changes: 4 additions & 0 deletions recipes/aerospike-common/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"cci.20240124":
url: "https://github.com/aerospike/aerospike-common/archive/00092452bfa984d424fe0d579dbe38ce1c526883.tar.gz"
sha256: da07457b629e647c455ceb1ece8c0ce8114ebee4ea6b6bbf42fbe733058a5e76
160 changes: 160 additions & 0 deletions recipes/aerospike-common/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import os

from conan.errors import ConanInvalidConfiguration
from conan import ConanFile
from conan.tools.files import (
copy,
apply_conandata_patches,
export_conandata_patches,
get,
download,
)
from conan.tools.layout import basic_layout

required_conan_version = ">=1.57.0"


class AerospikeCommonConan(ConanFile):
name = "aerospike-common"
homepage = "https://github.com/aerospike/aerospike-common"
description = "Library for commonly used or shared code. Used by Aerospike Server and Aerospike C Client."
url = "https://github.com/conan-io/conan-center-index"
topics = ("aerospike", "client", "database")
license = "Apache-2.0"
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

_compiler_arch_flags = {
"gcc": {"x86": "-m32", "x86_64": "-m64", "armv8": "-march=aarch64"},
"clang": {
"x86": "-arch i386",
"x86_64": "-arch x86_64",
"armv8": "-arch arm64",
},
"apple-clang": {
"x86": "-arch i386",
"x86_64": "-arch x86_64",
"armv8": "-arch arm64",
},
}

def validate(self):
if self.settings.os == "Windows":
raise ConanInvalidConfiguration(f"Windows os is not supported")

Check warning on line 51 in recipes/aerospike-common/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Using an f-string that does not have any interpolated variables
if str(self.settings_build.compiler) not in self._compiler_arch_flags.keys():
raise ConanInvalidConfiguration(f"Unsupported compiler: {self.settings_build.compiler}")
if str(self.settings_build.arch) not in self._compiler_arch_flags[str(self.settings_build.compiler)].keys():
raise ConanInvalidConfiguration(
f"Unsupported arch {self.settings.arch} for compiler {self.settings_build.compiler}"
)

def configure(self):
if self.options.shared or self.settings.os == "Windows":
self.options.rm_safe("fPIC")
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd

def requirements(self):
self.requires("openssl/[>=1.1 <4]")
self.requires("zlib/[>=1.2.11 <2]")

def export_sources(self):
export_conandata_patches(self)

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

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

def build(self):
apply_conandata_patches(self)
includes = []
for _, dependency in self.dependencies.items():
for path in dependency.cpp_info.includedirs:
includes.append(path)
include_flags = " ".join([f"-I{i}" for i in includes])

ld_flags = ""
if self.options.shared:
ld_flags = f"LDFLAGS='{self._get_ld_flags()}'"

cc_flags = f"EXT_CFLAGS='{include_flags} {self._compiler_arch_flags[str(self.settings_build.compiler)][str(self.settings_build.arch)]}'"
self.run(
f"make TARGET_BASE='target' {ld_flags} {cc_flags} -C {self.source_path}"
)

def package(self):
if self.options.shared:
copy(
self,
src=f"{self.source_folder}/target",
pattern="lib/*.so*",
dst=self.package_folder,
)
copy(
self,
src=f"{self.source_folder}/target",
pattern="lib/*.dylib",
dst=self.package_folder,
)
else:
copy(
self,
src=f"{self.source_folder}/target",
pattern="lib/*.a",
dst=self.package_folder,
)

copy(
self,
pattern="*",
src=f"{self.source_folder}/src/include",
dst=f"{self.package_folder}/include",
)
download(
self,
"https://www.apache.org/licenses/LICENSE-2.0.txt",
f"{self.package_folder}/licenses/LICENSE.txt",
)

def package_info(self):
self.cpp_info.includedirs = ["include"]
self.cpp_info.libs = ["aerospike-common"]

def _get_ld_flags(self):
static_libs = []
dynamic_libs_dirs = []
dynamic_libs = []
for _, dependency in self.dependencies.items():
for dir in dependency.cpp_info.libdirs:

Check warning on line 138 in recipes/aerospike-common/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Redefining built-in 'dir'
# add path to search for dynamic libs
dynamic_libs_dirs.append(f"-L{dir}")
files = filter(
lambda item: os.path.isfile(os.path.join(dir, item)),

Check warning on line 142 in recipes/aerospike-common/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Cell variable dir defined in loop
os.listdir(dir),
)
for lib in files:
if lib.endswith(".a"):
# add static lib only in case of shared build
static_libs.append(os.path.join(dir, lib))
else:
# add dynamic lib
dynamic_libs.append(f"-l{self._get_dynamic_library_name(lib)}")
static_libs_str = " ".join(static_libs)
dynamic_libs_dirs_str = " ".join(dynamic_libs_dirs)
dynamic_libs_str = " ".join(dynamic_libs)
return f"{dynamic_libs_dirs_str} {dynamic_libs_str} {static_libs_str}"

def _get_dynamic_library_name(self, file_name):
lib = file_name[3:] # removes 'lib' prefix
lib = lib.split(".", 1)[0]
return lib
7 changes: 7 additions & 0 deletions recipes/aerospike-common/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)

find_package(aerospike-common REQUIRED CONFIG)

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


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

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.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
11 changes: 11 additions & 0 deletions recipes/aerospike-common/all/test_package/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <iostream>

#include <aerospike/as_aerospike.h>

int main()
{
as_aerospike as;
as_aerospike_init(&as, NULL, NULL);
as_aerospike_destroy(&as);
return 0;
}
3 changes: 3 additions & 0 deletions recipes/aerospike-common/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"cci.20240124":
folder: all
Loading