Skip to content

Commit

Permalink
(#4393) Add libavrocpp/1.10.1
Browse files Browse the repository at this point in the history
* Add libavrocpp/1.10.1

* Add libavrocpp/1.10.1

Add licenses

* Fix review comments

* Boost as a runtime dependency

* Create static target

* Add final endline

* Fix review comments

* Fix review comments

* Fix review comments

* Shared false by default

* Don't export CMakeLists.txt since it was removed

* fix windows build

* Use cmake wrapper

* Add snappy patch back in

Co-authored-by: Chris McArthur <prince.chrismc@gmail.com>
  • Loading branch information
plopp and prince-chrismc authored Feb 9, 2021
1 parent 9967e12 commit 2d6c725
Show file tree
Hide file tree
Showing 11 changed files with 357 additions and 0 deletions.
7 changes: 7 additions & 0 deletions recipes/libavrocpp/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.5)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory(source_subfolder/lang/c++)
14 changes: 14 additions & 0 deletions recipes/libavrocpp/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
sources:
"1.10.1":
url: "https://github.com/apache/avro/archive/release-1.10.1.tar.gz"
sha256: "8fd1f850ce37e60835e6d8335c0027a959aaa316773da8a9660f7d33a66ac142"
patches:
"1.10.1":
- base_path: "source_subfolder"
patch_file: "patches/0001-add-iterator-include.patch"
- base_path: "source_subfolder"
patch_file: "patches/0002-disable-tests.patch"
- base_path: "source_subfolder"
patch_file: "patches/0003-allow-static-boost-linkage.patch"
- base_path: "source_subfolder"
patch_file: "patches/0004-fix-windows-shared-installation.patch"
80 changes: 80 additions & 0 deletions recipes/libavrocpp/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import os

from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration


class LibavrocppConan(ConanFile):
name = "libavrocpp"
license = "Apache-2.0"
url = "https://github.com/conan-io/conan-center-index"
description = "Avro is a data serialization system."
homepage = "https://avro.apache.org/"
topics = ("serialization", "deserialization")
exports_sources = ["CMakeLists.txt", "patches/*.patch"]
generators = "cmake", "cmake_find_package"
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}

_cmake = None

@property
def _source_subfolder(self):
return os.path.join("source_subfolder", "lang", "c++")

@property
def _build_subfolder(self):
return "build_subfolder"

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
if self.settings.compiler.cppstd:
tools.check_min_cppstd(self, "11")

def requirements(self):
self.requires("boost/1.75.0")
self.requires("snappy/1.1.8")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
os.rename("avro-release-" + self.version, "source_subfolder")

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
tools.replace_in_file(
os.path.join(self._source_subfolder, "CMakeLists.txt"),
"${SNAPPY_LIBRARIES}", "${Snappy_LIBRARIES}"
)

def _configure_cmake(self):
if not self._cmake:
self._cmake = CMake(self)
self._cmake.definitions["SNAPPY_ROOT_DIR"] = self.deps_cpp_info["snappy"].rootpath.replace("\\", "/")
self._cmake.configure()
return self._cmake

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

def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
self.copy("NOTICE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()

def package_info(self):
# FIXME: avro does not install under a CMake namespace https://github.com/apache/avro/blob/351f589913b9691322966fb77fe72269a0a2ec82/lang/c%2B%2B/CMakeLists.txt#L193
target = "avrocpp" if self.options.shared else "avrocpp_s"
self.cpp_info.components[target].libs = [target]
self.cpp_info.components[target].requires = ["boost::boost", "snappy::snappy"]
if self.options.shared:
self.cpp_info.components[target].defines.append("AVRO_DYN_LINK")
80 changes: 80 additions & 0 deletions recipes/libavrocpp/all/patches/0001-add-iterator-include.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
--- lang/c++/api/buffer/detail/BufferDetail.hh
+++ lang/c++/api/buffer/detail/BufferDetail.hh
@@ -30,6 +30,7 @@
#include <exception>
#include <cassert>
#include <deque>
+#include <iterator>

/**
* \file BufferDetail.hh
--- lang/c++/impl/DataFile.cc
+++ lang/c++/impl/DataFile.cc
@@ -20,6 +20,7 @@
#include "Compiler.hh"
#include "Exception.hh"

+#include <iterator>
#include <sstream>

#include <boost/random/mersenne_twister.hpp>
--- lang/c++/impl/Stream.cc
+++ lang/c++/impl/Stream.cc
@@ -17,6 +17,7 @@
*/

#include "Stream.hh"
+#include <iterator>
#include <vector>

namespace avro {
--- lang/c++/impl/parsing/JsonCodec.cc
+++ lang/c++/impl/parsing/JsonCodec.cc
@@ -23,6 +23,7 @@
#include <algorithm>
#include <ctype.h>
#include <memory>
+#include <iterator>
#include <boost/math/special_functions/fpclassify.hpp>

#include "ValidatingCodec.hh"
--- lang/c++/impl/parsing/ResolvingDecoder.cc
+++ lang/c++/impl/parsing/ResolvingDecoder.cc
@@ -24,6 +24,7 @@
#include <algorithm>
#include <memory>
#include <ctype.h>
+#include <iterator>

#include "ValidatingCodec.hh"
#include "Symbol.hh"
--- lang/c++/impl/parsing/ValidatingCodec.cc
+++ lang/c++/impl/parsing/ValidatingCodec.cc
@@ -22,6 +22,7 @@
#include <map>
#include <algorithm>
#include <memory>
+#include <iterator>
#include <boost/any.hpp>

#include "ValidSchema.hh"
--- lang/c++/test/CodecTests.cc
+++ lang/c++/test/CodecTests.cc
@@ -30,6 +30,7 @@
#include <stack>
#include <string>
#include <functional>
+#include <iterator>
#include <boost/bind.hpp>

#include <boost/test/included/unit_test_framework.hpp>
--- lang/c++/test/DataFileTests.cc
+++ lang/c++/test/DataFileTests.cc
@@ -25,6 +25,7 @@

#include <thread>
#include <chrono>
+#include <iterator>

#include <sstream>

33 changes: 33 additions & 0 deletions recipes/libavrocpp/all/patches/0002-disable-tests.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
From e0961af7bfb69c1129a0347a8c8ccbd9608098cf Mon Sep 17 00:00:00 2001
From: Chris Mc <prince.chrismc@gmail.com>
Date: Tue, 2 Feb 2021 20:29:05 -0500
Subject: [PATCH] Update CMakeLists.txt

---
lang/c++/CMakeLists.txt | 4 ----
1 file changed, 4 deletions(-)

diff --git a/lang/c++/CMakeLists.txt b/lang/c++/CMakeLists.txt
index 69feee5b11..435d680e22 100644
--- a/lang/c++/CMakeLists.txt
+++ b/lang/c++/CMakeLists.txt
@@ -160,10 +160,6 @@ target_link_libraries (avrogencpp avrocpp_s ${Boost_LIBRARIES} ${SNAPPY_LIBRARIE
enable_testing()

macro (unittest name)
- add_executable (${name} test/${name}.cc)
- target_link_libraries (${name} avrocpp ${Boost_LIBRARIES} ${SNAPPY_LIBRARIES})
- add_test (NAME ${name} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
- COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${name})
endmacro (unittest)

unittest (buffertest)
@@ -178,7 +178,7 @@ unittest (JsonTests)
unittest (AvrogencppTests)
unittest (CompilerTests)

-add_dependencies (AvrogencppTests bigrecord_hh bigrecord_r_hh bigrecord2_hh
+add_dependencies (bigrecord_hh bigrecord_r_hh bigrecord2_hh
tweet_hh
union_array_union_hh union_map_union_hh union_conflict_hh
recursive_hh reuse_hh circulardep_hh tree1_hh tree2_hh crossref_hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
From 902717b4aa557b60d3450a1397cae728d44ebb07 Mon Sep 17 00:00:00 2001
From: Chris Mc <prince.chrismc@gmail.com>
Date: Tue, 2 Feb 2021 20:55:08 -0500
Subject: [PATCH] allow static linkage to boost

---
lang/c++/CMakeLists.txt | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/lang/c++/CMakeLists.txt b/lang/c++/CMakeLists.txt
index 435d680e22..770a9e8df5 100644
--- a/lang/c++/CMakeLists.txt
+++ b/lang/c++/CMakeLists.txt
@@ -44,14 +44,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR})

if (WIN32 AND NOT CYGWIN AND NOT MSYS)
add_definitions (/EHa)
- add_definitions (
- -DNOMINMAX
- -DBOOST_REGEX_DYN_LINK
- -DBOOST_FILESYSTEM_DYN_LINK
- -DBOOST_SYSTEM_DYN_LINK
- -DBOOST_IOSTREAMS_DYN_LINK
- -DBOOST_PROGRAM_OPTIONS_DYN_LINK
- -DBOOST_ALL_NO_LIB)
+ add_definitions (-DNOMINMAX)
else()
# Replease c++11 with c++17 below in case C++ 17 should be used
add_definitions(-std=c++11 -fPIC)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
From 2b1a4c4fe21bbb581d6f01794a465fe0cea2f167 Mon Sep 17 00:00:00 2001
From: Chris Mc <prince.chrismc@gmail.com>
Date: Tue, 2 Feb 2021 21:27:31 -0500
Subject: [PATCH] fix windows shared installation

---
lang/c++/CMakeLists.txt | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/lang/c++/CMakeLists.txt b/lang/c++/CMakeLists.txt
index 770a9e8df5..3ed26fa27d 100644
--- a/lang/c++/CMakeLists.txt
+++ b/lang/c++/CMakeLists.txt
@@ -173,8 +173,6 @@ add_dependencies (AvrogencppTests bigrecord_hh bigrecord_r_hh bigrecord2_hh
recursive_hh reuse_hh circulardep_hh tree1_hh tree2_hh crossref_hh
primitivetypes_hh empty_record_hh)

-include (InstallRequiredSystemLibraries)
-
set (CPACK_PACKAGE_FILE_NAME "avrocpp-${AVRO_VERSION_MAJOR}")

include (CPack)
@@ -182,7 +180,7 @@ include (CPack)
install (TARGETS avrocpp avrocpp_s
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
- RUNTIME DESTINATION lib)
+ RUNTIME DESTINATION bin)

install (TARGETS avrogencpp RUNTIME DESTINATION bin)

16 changes: 16 additions & 0 deletions recipes/libavrocpp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.8)
project(test_package CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

find_package(libavrocpp REQUIRED CONFIG)
add_executable(${PROJECT_NAME} test_package.cpp)

set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)

if(AVROCPP_SHARED)
target_link_libraries(${PROJECT_NAME} libavrocpp::avrocpp)
else()
target_link_libraries(${PROJECT_NAME} libavrocpp::avrocpp_s)
endif()
20 changes: 20 additions & 0 deletions recipes/libavrocpp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import os

from conans import ConanFile, CMake, tools


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.verbose = True
cmake.definitions["AVROCPP_SHARED"] = self.options["libavrocpp"].shared
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
44 changes: 44 additions & 0 deletions recipes/libavrocpp/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "avro/Decoder.hh"
#include "avro/Encoder.hh"
#include "avro/Specific.hh"

namespace c {
struct cpx {
double re;
double im;
};

}
namespace avro {
template<> struct codec_traits<c::cpx> {
static void encode(Encoder& e, const c::cpx& v) {
avro::encode(e, v.re);
avro::encode(e, v.im);
}
static void decode(Decoder& d, c::cpx& v) {
avro::decode(d, v.re);
avro::decode(d, v.im);
}
};

}

int main()
{
std::unique_ptr<avro::OutputStream> out = avro::memoryOutputStream(128);
avro::EncoderPtr e = avro::binaryEncoder();
e->init(*out);
c::cpx c1;
c1.re = 1.0;
c1.im = 2.13;
avro::encode(*e, c1);

std::unique_ptr<avro::InputStream> in = avro::memoryInputStream(*out);
avro::DecoderPtr d = avro::binaryDecoder();
d->init(*in);

c::cpx c2{};
avro::decode(*d, c2);
std::cout << '(' << c2.re << ", " << c2.im << ')' << std::endl;
return 0;
}
3 changes: 3 additions & 0 deletions recipes/libavrocpp/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
1.10.1:
folder: all

0 comments on commit 2d6c725

Please sign in to comment.