From 791f6d572de48b8ee2677404e64311b414926519 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Fri, 30 Jun 2023 08:52:29 +0300 Subject: [PATCH] libunifex: migrate to Conan v2, add v0.3.0 --- recipes/libunifex/all/CMakeLists.txt | 7 -- recipes/libunifex/all/conandata.yml | 3 + recipes/libunifex/all/conanfile.py | 108 +++++++++--------- .../libunifex/all/test_package/CMakeLists.txt | 7 +- .../libunifex/all/test_package/conanfile.py | 19 ++- .../all/test_v1_package/CMakeLists.txt | 8 ++ .../all/test_v1_package/conanfile.py | 17 +++ recipes/libunifex/config.yml | 4 +- 8 files changed, 99 insertions(+), 74 deletions(-) delete mode 100644 recipes/libunifex/all/CMakeLists.txt create mode 100644 recipes/libunifex/all/test_v1_package/CMakeLists.txt create mode 100644 recipes/libunifex/all/test_v1_package/conanfile.py diff --git a/recipes/libunifex/all/CMakeLists.txt b/recipes/libunifex/all/CMakeLists.txt deleted file mode 100644 index 4beb13671fe5e7..00000000000000 --- a/recipes/libunifex/all/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -cmake_minimum_required(VERSION 2.8) -project(cmake_wrapper) - -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup() - -add_subdirectory("source_subfolder") diff --git a/recipes/libunifex/all/conandata.yml b/recipes/libunifex/all/conandata.yml index 2eaea0e7a17a75..e6e95ae0f7c76d 100644 --- a/recipes/libunifex/all/conandata.yml +++ b/recipes/libunifex/all/conandata.yml @@ -1,4 +1,7 @@ sources: + "0.3.0": + url: "https://github.com/facebookexperimental/libunifex/archive/refs/tags/v0.3.0.tar.gz" + sha256: "da6b65227adcf1ce3e3410865cc2974b1aacaa20d0f03905bd3bd4fb4e6e4d44" "cci.20220430": url: "https://github.com/facebookexperimental/libunifex/archive/c359fd8e7d97d91359cf4a6c1dbef99b0b1767b6.tar.gz" sha256: "c306891967fa4cc1a22f3401581d35ceea41eb1dbdac3e6157ecf3defaa4b15d" diff --git a/recipes/libunifex/all/conanfile.py b/recipes/libunifex/all/conanfile.py index 49d7f959dc5395..6a418d014c0536 100644 --- a/recipes/libunifex/all/conanfile.py +++ b/recipes/libunifex/all/conanfile.py @@ -1,110 +1,106 @@ -from conans import ConanFile, CMake, tools -from conans.errors import ConanInvalidConfiguration -import functools import os -required_conan_version = ">=1.43.0" +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 +from conan.tools.microsoft import is_msvc + +required_conan_version = ">=1.52.0" class LibunifexConan(ConanFile): name = "libunifex" + description = "A prototype implementation of the C++ sender/receiver async programming model" license = ("Apache-2.0", "LLVM-exception") url = "https://github.com/conan-io/conan-center-index" homepage = "https://github.com/facebookexperimental/libunifex" - description = "A prototype implementation of the C++ sender/receiver async programming model" topics = ("async", "cpp") + package_type = "static-library" settings = "os", "arch", "compiler", "build_type" - generators = "cmake", "cmake_find_package_multi" - no_copy_source = True - exports_sources = ["CMakeLists.txt"] - @property - def _source_subfolder(self): - return "source_subfolder" + def _minimum_standard(self): + return 17 @property def _compilers_minimum_version(self): return { "gcc": "9", - "Visual Studio": "16", "clang": "10", "apple-clang": "11", + "Visual Studio": "16", + "msvc": "193", } - @property - def _minimum_standard(self): - return "17" + def layout(self): + cmake_layout(self, src_folder="src") - # FIXME: Add support for liburing - # def requirements(self): - # TODO: Make an option to opt-out of liburing for old kernel versions - # if self.settings.os == "Linux": - # self.requires("liburing/2.1") + def requirements(self): + if self.settings.os in ["Linux", "FreeBSD"]: + self.requires("liburing/2.2", transitive_headers=True) def validate(self): if self.settings.compiler.get_safe("cppstd"): - tools.check_min_cppstd( - self, self._minimum_standard) + check_min_cppstd(self, self._minimum_standard) def lazy_lt_semver(v1, v2): - lv1 = [int(v) for v in v1.split(".")] - lv2 = [int(v) for v in v2.split(".")] - min_length = min(len(lv1), len(lv2)) - return lv1[:min_length] < lv2[:min_length] - - minimum_version = self._compilers_minimum_version.get( - str(self.settings.compiler), False) - if not minimum_version: - self.output.warn( - "{0} {1} requires C++{2}. Your compiler is unknown. Assuming it supports C++{2}." - .format(self.name, self.version, self._minimum_standard)) - elif lazy_lt_semver(str(self.settings.compiler.version), minimum_version): + return all(int(p1) < int(p2) for p1, p2 in zip(v1.split("."), v2.split("."))) + + minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False) + if minimum_version and lazy_lt_semver(self.settings.compiler.version, minimum_version): raise ConanInvalidConfiguration( - "{} {} requires C++{}, which your compiler does not support." - .format(self.name, self.version, self._minimum_standard)) + f"{self.ref} requires C++{self._minimum_standard}, which your compiler does not support." + ) + + if self.version == "cci.20220430" and is_msvc(self): + raise ConanInvalidConfiguration(f"{self.ref} is not supported on MSVC") def source(self): - tools.get(**self.conan_data["sources"][self.version], - destination=self._source_subfolder, strip_root=True) + get(self, **self.conan_data["sources"][self.version], strip_root=True) - @functools.lru_cache(1) - def _configure_cmake(self): - cmake = CMake(self) - cmake.definitions["BUILD_TESTING"] = "OFF" - cmake.configure() - return cmake + def generate(self): + tc = CMakeToolchain(self) + tc.variables["BUILD_TESTING"] = False + tc.generate() + tc = CMakeDeps(self) + tc.generate() def build(self): - cmake = self._configure_cmake() + cmake = CMake(self) + cmake.configure() cmake.build() def package(self): - self.copy("LICENSE.txt", dst="licenses", src=self._source_subfolder) - cmake = self._configure_cmake() + copy(self, "LICENSE.txt", + dst=os.path.join(self.package_folder, "licenses"), + src=self.source_folder) + cmake = CMake(self) cmake.install() - tools.rmdir(os.path.join(self.package_folder, "lib", "cmake")) - tools.rmdir(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, "lib", "pkgconfig")) def package_info(self): + self.cpp_info.bindirs = [] + self.cpp_info.libdirs = [] + self.cpp_info.set_property("cmake_file_name", "unifex") self.cpp_info.set_property("cmake_target_name", "unifex::unifex") self.cpp_info.set_property("pkg_config_name", "unifex") + self.cpp_info.components["unifex"].libs = ["unifex"] + self.cpp_info.components["unifex"].set_property("cmake_target_name", "unifex::unifex") + # TODO: to remove in conan v2 once cmake_find_package_* generators removed self.cpp_info.filenames["cmake_find_package"] = "unifex" self.cpp_info.filenames["cmake_find_package_multi"] = "unifex" self.cpp_info.names["cmake_find_package"] = "unifex" self.cpp_info.names["cmake_find_package_multi"] = "unifex" - self.cpp_info.names["pkg_config"] = "unifex" self.cpp_info.components["unifex"].names["cmake_find_package"] = "unifex" self.cpp_info.components["unifex"].names["cmake_find_package_multi"] = "unifex" - self.cpp_info.components["unifex"].set_property( - "cmake_target_name", "unifex::unifex") - self.cpp_info.components["unifex"].libs = ["unifex"] - if self.settings.os == "Linux": + if self.settings.os in ["Linux", "FreeBSD"]: self.cpp_info.components["unifex"].system_libs = ["pthread"] - # self.cpp_info.components["unifex"].requires.append( - # "liburing::liburing") + self.cpp_info.components["unifex"].requires.append("liburing::liburing") diff --git a/recipes/libunifex/all/test_package/CMakeLists.txt b/recipes/libunifex/all/test_package/CMakeLists.txt index a487dfdf2b7ad1..8b6bbba4a1e1bf 100644 --- a/recipes/libunifex/all/test_package/CMakeLists.txt +++ b/recipes/libunifex/all/test_package/CMakeLists.txt @@ -1,8 +1,5 @@ -cmake_minimum_required(VERSION 3.1) -project(test_package) - -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup(TARGETS) +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES CXX) find_package(unifex REQUIRED CONFIG) diff --git a/recipes/libunifex/all/test_package/conanfile.py b/recipes/libunifex/all/test_package/conanfile.py index 38f4483872d47f..ef5d7042163ecc 100644 --- a/recipes/libunifex/all/test_package/conanfile.py +++ b/recipes/libunifex/all/test_package/conanfile.py @@ -1,10 +1,19 @@ -from conans import ConanFile, CMake, tools +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 = "cmake", "cmake_find_package_multi" + generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" + test_type = "explicit" + + def requirements(self): + self.requires(self.tested_reference_str) + + def layout(self): + cmake_layout(self) def build(self): cmake = CMake(self) @@ -12,6 +21,6 @@ def build(self): cmake.build() def test(self): - if not tools.cross_building(self): - bin_path = os.path.join("bin", "test_package") - self.run(bin_path, run_environment=True) + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindir, "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/libunifex/all/test_v1_package/CMakeLists.txt b/recipes/libunifex/all/test_v1_package/CMakeLists.txt new file mode 100644 index 00000000000000..91630d79f4abb3 --- /dev/null +++ b/recipes/libunifex/all/test_v1_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup(TARGETS) + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/ + ${CMAKE_CURRENT_BINARY_DIR}/test_package/) diff --git a/recipes/libunifex/all/test_v1_package/conanfile.py b/recipes/libunifex/all/test_v1_package/conanfile.py new file mode 100644 index 00000000000000..38f4483872d47f --- /dev/null +++ b/recipes/libunifex/all/test_v1_package/conanfile.py @@ -0,0 +1,17 @@ +from conans import ConanFile, CMake, tools +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "cmake", "cmake_find_package_multi" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True) diff --git a/recipes/libunifex/config.yml b/recipes/libunifex/config.yml index 1bf3ed95d8368d..5273f6416dfbac 100644 --- a/recipes/libunifex/config.yml +++ b/recipes/libunifex/config.yml @@ -1,3 +1,5 @@ versions: + "0.3.0": + folder: all "cci.20220430": - folder: "all" + folder: all