Skip to content

Commit

Permalink
Conan compatibility
Browse files Browse the repository at this point in the history
- add basic conan file
- emulate cmake_find_package behaviour
- use dynamic version for now
- update resource_pool with latest  conan updates
- hotfix for yandex#281
  • Loading branch information
JonasProgrammer committed Jan 23, 2021
1 parent 8a65976 commit 5d859ca
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 5 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ services:
- docker

install:
- pip3 install --user --upgrade pip
- pip3 install --user --upgrade "pip>=20.3.4,<21.0"
- pip3 install --user docker-compose

matrix:
Expand Down Expand Up @@ -62,6 +62,10 @@ matrix:
dist: xenial
env: BUILD_ARGS='pg docker clang tsan'

- os: linux
dist: xenial
env: BUILD_ARGS='docker_conan clang conan'

- os: osx
osx_image: xcode11
install:
Expand Down
56 changes: 56 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from conans import ConanFile, CMake
from conans.tools import load
import re


def get_version():
try:
content = load("CMakeLists.txt")
version = re.search(r"^\s*project\(ozo\s+VERSION\s+([^\s)]+)", content, re.M).group(1)
return version.strip()
except Exception:
return None


class Ozo(ConanFile):
name = 'ozo'
version = get_version()
license = 'MIT'
url = 'https://github.com/yandex/ozo'
description = 'Conan package for yandex ozo'

exports_sources = 'include/*', 'CMakeLists.txt', 'cmake/*', 'LICENCE', 'AUTHORS'

generators = 'cmake_find_package'
requires = ('boost/1.74.0', 'resource_pool/0.1.0', 'libpq/13.1')

def _configure_cmake(self):
cmake = CMake(self)
cmake.configure()
return cmake

def build(self):
cmake = self._configure_cmake()
cmake.build()

def package(self):
cmake = self._configure_cmake()
cmake.install()

def package_id(self):
self.info.header_only()

def package_info(self):
self.cpp_info.components["_ozo"].includedirs = ["include"]
self.cpp_info.components["_ozo"].requires = ["boost::boost", "boost::system", "boost::thread", "boost::coroutine",
"resource_pool::resource_pool", # == elsid::resource_pool in cmake
"libpq::pq", # == PostgreSQL::PostgreSQL in cmake
]
self.cpp_info.components["_ozo"].defines = ["BOOST_COROUTINES_NO_DEPRECATION_WARNING", "BOOST_HANA_CONFIG_ENABLE_STRING_UDL", "BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT"]

self.cpp_info.filenames["cmake_find_package"] = "ozo"
self.cpp_info.filenames["cmake_find_package_multi"] = "ozo"
self.cpp_info.names["cmake_find_package"] = "yandex"
self.cpp_info.names["cmake_find_package_multi"] = "yandex"
self.cpp_info.components["_ozo"].names["cmake_find_package"] = "ozo"
self.cpp_info.components["_ozo"].names["cmake_find_package_multi"] = "ozo"
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ services:
volumes:
- ~/.ccache:/ccache
- .:/code
ozo_build_conan:
build:
context: docker/build
dockerfile: Dockerfile.conan
image: ozo_build_conan
privileged: true # https://github.com/google/sanitizers/issues/764
environment:
BASE_BUILD_DIR: build/docker
volumes:
- ~/.ccache:/ccache
- .:/code
ozo_postgres:
image: postgres:alpine
environment:
Expand Down
28 changes: 28 additions & 0 deletions docker/build/Dockerfile.conan
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM ubuntu:18.04

RUN apt-get update \
&& apt-get install -y apt-transport-https ca-certificates gnupg software-properties-common wget

RUN wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | apt-key add -

RUN apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main'

RUN apt-get update \
&& apt-get install -y \
ccache \
clang-10 \
cmake \
python3-pip \
&& rm -rf /var/lib/apt/lists/* \
&& pip3 install conan

RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-10 100 \
&& update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-10 100 \
&& CC=clang CXX=clang++ conan profile new default --detect

VOLUME /ccache
VOLUME /code

WORKDIR /code

ENV CCACHE_DIR=/ccache
23 changes: 20 additions & 3 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ build_clang() {
CMAKE_CXX_FLAGS_RELWITHDEBINFO='-g -O2 -fno-omit-frame-pointer -fsanitize=thread'
build
;;
conan)
build_conan
;;
*) usage "bad clang target '$TARGET'";;
esac
}
Expand Down Expand Up @@ -82,9 +85,11 @@ usage() {
compiler : gcc | clang
target :
- for gcc : debug | release | coverage
- for clang : debug | release | asan | ubsan
- for clang : debug | release | asan | ubsan | tsan | conan
'$NAME' docker [all | docs | <compiler> <target>]
Build inside Docker
'$NAME' docker_conan [<compiler> <target>]
Build inside Docker with a conan image
'$NAME' pg [docker] [all | <compiler> <target>]
Build with PostgreSQL integration tests' 1>&2
exit 1
Expand All @@ -102,6 +107,11 @@ build_all() {
$0 clang tsan
}

build_conan() {
conan create contrib/resource_pool
conan create .
}

build() {
echo "BASE_BUILD_DIR: ${BASE_BUILD_DIR}"
if ! [[ "${BASE_BUILD_DIR}" ]]; then
Expand Down Expand Up @@ -160,9 +170,16 @@ build() {
fi
}

launch_in_docker_conan() {
export OZO_BUILD_DOCKER_CONAN=ON
launch_in_docker $*
}

launch_in_docker() {
if [[ "${OZO_BUILD_PG_TESTS}" == "ON" ]]; then
SERVICE=ozo_build_with_pg_tests
elif [[ "${OZO_BUILD_DOCKER_CONAN}" == "ON" ]]; then
SERVICE=ozo_build_conan
else
SERVICE=ozo_build
fi
Expand Down Expand Up @@ -195,9 +212,9 @@ case "$1" in
build_${1}
exit 0
;;
docker)
docker|docker_conan)
set -x
launch_in_docker $2 $3 $4 $5
launch_in_${1} $2 $3 $4 $5
exit 0
;;
pg)
Expand Down
8 changes: 8 additions & 0 deletions test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.12)
project(PackageTest CXX)

find_package(ozo REQUIRED)

add_executable(example ../examples/connection_pool.cpp)
target_compile_features(example PRIVATE cxx_std_17)
target_link_libraries(example PRIVATE yandex::ozo)
21 changes: 21 additions & 0 deletions test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from conans import ConanFile, CMake


class OzoTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake_find_package"

def build(self):
cmake = CMake(self)
# Current dir is "test_package/build/<build_id>" and CMakeLists.txt is
# in "test_package"
cmake.configure()
cmake.build()

def imports(self):
self.copy("*.dll", dst="bin", src="bin")
self.copy("*.dylib*", dst="bin", src="lib")
self.copy('*.so*', dst='bin', src='lib')

def test(self):
pass # Building alone is sufficient

0 comments on commit 5d859ca

Please sign in to comment.