-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
ybogo
wants to merge
11
commits into
conan-io:master
Choose a base branch
from
ybogo:add-aerospike-common
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+211
−0
Open
aersopike-common: new recipe #23388
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9e45e9b
aersopike-common: new recipe
ybogo 34167c1
fix checks
ybogo 1f37d62
fix linkage
ybogo 14cce97
add static objects only to shared library
ybogo ed30567
add linker flags only for static builds
ybogo 473a2cd
fix deducing dynamic libs names
ybogo 543f67b
remove fpic for windows
ybogo b1fba1d
support arch and disable windows support
ybogo e770d05
review fixes
ybogo db2fe1e
use build settings instead of host settings
ybogo d33c02e
fix exception type
ybogo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
sources: | ||
"0009245": | ||
url: "https://github.com/aerospike/aerospike-common/archive/00092452bfa984d424fe0d579dbe38ce1c526883.tar.gz" | ||
sha256: da07457b629e647c455ceb1ece8c0ce8114ebee4ea6b6bbf42fbe733058a5e76 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import os | ||
|
||
from conan.errors import ConanException | ||
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, | ||
} | ||
|
||
def validate(self): | ||
if self.settings.os == "Windows": | ||
raise ConanException(f"Windows os is not supported") | ||
if self.settings.compiler not in ["gcc", "clang", "apple-clang"]: | ||
raise ConanException(f"Unsupported compiler: {self.settings.compiler}") | ||
if self.settings.arch not in ["x86", "x86_64", "armv7", "armv8"]: | ||
raise ConanException(f"Unsupported compiler: {self.settings.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._get_arch_flag()}'" | ||
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_arch_flag(self): | ||
gcc_arch = {'x86': '32', | ||
'x86_64': '64', | ||
'armv7': 'armv7', | ||
'armv8': 'armv8'} | ||
clang_arch = {'x86': 'i386', | ||
'x86_64': 'x86_64', | ||
'armv7': 'arm', | ||
'armv8': 'arm64'} | ||
if self.settings.compiler == "gcc": | ||
return f"-m {gcc_arch[str(self.settings.arch)]}" | ||
elif str(self.settings.compiler).endswith("clang"): | ||
return f"-arch {clang_arch[str(self.settings.arch)]}" | ||
raise ConanException(f"Unsupported compiler: {self.settings.compiler}") | ||
|
||
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: | ||
# 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)), | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
versions: | ||
"0009245": | ||
folder: all |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For these cases, we usually use
cci.YYYYMMDD
with the date of the picked commit