From b1a7d6c37ab702c478fdc872e754e2fe9121106f Mon Sep 17 00:00:00 2001 From: fhamonic Date: Mon, 9 Sep 2024 15:08:18 +0200 Subject: [PATCH 1/4] new recipe for melon/1.0.0-alpha.1 --- recipes/melon/all/conandata.yml | 4 + recipes/melon/all/conanfile.py | 117 ++++++++++++++++++ recipes/melon/all/test_package/CMakeLists.txt | 11 ++ recipes/melon/all/test_package/conanfile.py | 27 ++++ .../melon/all/test_package/test_package.cpp | 34 +++++ recipes/melon/config.yml | 3 + 6 files changed, 196 insertions(+) create mode 100644 recipes/melon/all/conandata.yml create mode 100644 recipes/melon/all/conanfile.py create mode 100644 recipes/melon/all/test_package/CMakeLists.txt create mode 100644 recipes/melon/all/test_package/conanfile.py create mode 100644 recipes/melon/all/test_package/test_package.cpp create mode 100644 recipes/melon/config.yml diff --git a/recipes/melon/all/conandata.yml b/recipes/melon/all/conandata.yml new file mode 100644 index 0000000000000..9550cdb9601e7 --- /dev/null +++ b/recipes/melon/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "1.0.0-alpha.1": + url: "https://github.com/fhamonic/melon/archive/refs/tags/v1.0.0-alpha.1.tar.gz" + sha256: "370f6bb1fddc68f1ab771c8b659fed6d9dc8da51290897ed72fd87589143220c" diff --git a/recipes/melon/all/conanfile.py b/recipes/melon/all/conanfile.py new file mode 100644 index 0000000000000..9b2875d87ac69 --- /dev/null +++ b/recipes/melon/all/conanfile.py @@ -0,0 +1,117 @@ +from conan import ConanFile +from conan.errors import ConanInvalidConfiguration +from conan.tools.build import check_min_cppstd +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get +from conan.tools.layout import basic_layout +from conan.tools.scm import Version +import os + + +required_conan_version = ">=1.52.0" + +class PackageConan(ConanFile): + name = "melon" + description = "A modern and efficient graph library using C++20 ranges and concepts." + # Use short name only, conform to SPDX License List: https://spdx.org/licenses/ + # In case it's not listed there, use "LicenseRef-" + license = "BSL-1.0" + url = "https://github.com/fhamonic/melon" + homepage = "https://github.com/project/package" + # Do not put "conan" nor the project name in topics. Use topics from the upstream listed on GH + # Keep 'header-only' as topic + topics = ("graph", "algorithm", "ranges", "c++20", "header-only") + package_type = "header-library" + # Keep these or explain why it's not required for this particular case + settings = "os", "arch", "compiler", "build_type" + # Do not copy sources to build folder for header only projects, unless you need to apply patches + no_copy_source = True + + @property + def _min_cppstd(self): + return 20 + + # In case the project requires C++14/17/20/... the minimum compiler version should be listed + @property + def _compilers_minimum_version(self): + return { + "apple-clang": "14", + "clang": "17", + "gcc": "12", + "msvc": "192", + "Visual Studio": "17", + } + + # Use the export_sources(self) method instead of the exports_sources attribute. + # This allows finer grain exportation of patches per version + def export_sources(self): + export_conandata_patches(self) + + def layout(self): + # src_folder must use the same source folder name than the project + basic_layout(self, src_folder="src") + + def requirements(self): + # Prefer self.requires method instead of requires attribute + # Direct dependencies of header only libs are always transitive since they are included in public headers + self.requires("range-v3/[>=0.11.0]", transitive_headers=True) + self.requires("fmt/[>=10.0.0]", transitive_headers=True) + + # same package ID for any package + def package_id(self): + self.info.clear() + + def validate(self): + if self.settings.compiler.get_safe("cppstd"): + # Validate the minimum cpp standard supported when installing the package. For C++ projects only + check_min_cppstd(self, self._min_cppstd) + minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False) + if minimum_version and Version(self.settings.compiler.version) < minimum_version: + raise ConanInvalidConfiguration( + f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support." + ) + + # In case this library does not work in some another configuration, it should be validated here too + if self.settings.os == "Windows": + raise ConanInvalidConfiguration(f"{self.ref} can not be used on Windows.") + + def source(self): + # Download source package and extract to source folder + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + # Not mandatory when there is no patch, but will suppress warning message about missing build() method + def build(self): + # The attribute no_copy_source should not be used when applying patches in build + apply_conandata_patches(self) + + # Copy all files to the package folder + def package(self): + copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses")) + copy( + self, + "*.hpp", + os.path.join(self.source_folder, "include"), + os.path.join(self.package_folder, "include"), + ) + + def package_info(self): + # Folders not used for header-only + self.cpp_info.bindirs = [] + self.cpp_info.libdirs = [] + + # Set these to the appropriate values if the package has an official FindPACKAGE.cmake + # listed in https://cmake.org/cmake/help/latest/manual/cmake-modules.7.html#find-modules + # examples: bzip2, freetype, gdal, icu, libcurl, libjpeg, libpng, libtiff, openssl, sqlite3, zlib... + # self.cpp_info.set_property("cmake_module_file_name", "melon") + # self.cpp_info.set_property("cmake_module_target_name", "melon::melon") + + # Set these to the appropriate values if package provides a CMake config file + # (package-config.cmake or packageConfig.cmake, with package::package target, usually installed in /lib/cmake//) + # self.cpp_info.set_property("cmake_file_name", "melon") + # self.cpp_info.set_property("cmake_target_name", "melon::melon") + # Set this to the appropriate value if the package provides a pkgconfig file + # (package.pc, usually installed in /lib/pkgconfig/) + # self.cpp_info.set_property("pkg_config_name", "melon") + + # Add m, pthread and dl if needed in Linux/FreeBSD + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.system_libs.extend(["pthread"]) diff --git a/recipes/melon/all/test_package/CMakeLists.txt b/recipes/melon/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..fbed126ed191d --- /dev/null +++ b/recipes/melon/all/test_package/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.15) +# project(test_package LANGUAGES C) # if the project is pure C +project(test_package LANGUAGES CXX) # if the project uses c++ + +find_package(melon REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.cpp) +# don't link to ${CONAN_LIBS} or CONAN_PKG::package +target_link_libraries(${PROJECT_NAME} PRIVATE melon::melon) +# In case the target project need a specific C++ standard +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20) diff --git a/recipes/melon/all/test_package/conanfile.py b/recipes/melon/all/test_package/conanfile.py new file mode 100644 index 0000000000000..0a808db45f245 --- /dev/null +++ b/recipes/melon/all/test_package/conanfile.py @@ -0,0 +1,27 @@ +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import cmake_layout, CMake +import os + + +# It will become the standard on Conan 2.x +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.bindir, "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/melon/all/test_package/test_package.cpp b/recipes/melon/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..7e18262cace47 --- /dev/null +++ b/recipes/melon/all/test_package/test_package.cpp @@ -0,0 +1,34 @@ +#include "melon/algorithm/bidirectional_dijkstra.hpp" +#include "melon/utility/static_digraph_builder.hpp" +#include "melon/container/static_digraph.hpp" + +using namespace fhamonic::melon; + +int main(int argc, char * argv[]) { + static_digraph_builder builder(6); + + builder.add_arc(0u, 1u, 7); + builder.add_arc(0u, 2u, 9); + builder.add_arc(0u, 5u, 14); + builder.add_arc(1u, 0u, 7); + builder.add_arc(1u, 2u, 10); + builder.add_arc(1u, 3u, 15); + builder.add_arc(2u, 0u, 9); + builder.add_arc(2u, 1u, 10); + builder.add_arc(2u, 3u, 12); + builder.add_arc(2u, 5u, 2); + builder.add_arc(3u, 1u, 15); + builder.add_arc(3u, 2u, 12); + builder.add_arc(3u, 4u, 6); + builder.add_arc(4u, 3u, 6); + builder.add_arc(4u, 5u, 9); + builder.add_arc(5u, 0u, 14); + builder.add_arc(5u, 2u, 2); + builder.add_arc(5u, 4u, 9); + + auto [graph, length_map] = builder.build(); + + bidirectional_dijkstra alg(graph, length_map, 0u, 3u); + + return alg.run() == 21 ? EXIT_SUCCESS : EXIT_FAILURE; +} \ No newline at end of file diff --git a/recipes/melon/config.yml b/recipes/melon/config.yml new file mode 100644 index 0000000000000..6aee52e82f90c --- /dev/null +++ b/recipes/melon/config.yml @@ -0,0 +1,3 @@ +versions: + "1.0.0-alpha.1": + folder: all From 299f5d37cb552869f532a7f63ddb476e0e4dbd66 Mon Sep 17 00:00:00 2001 From: fhamonic Date: Mon, 9 Sep 2024 17:21:47 +0200 Subject: [PATCH 2/4] fixed url in conanfile.py --- recipes/melon/all/conanfile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/recipes/melon/all/conanfile.py b/recipes/melon/all/conanfile.py index 9b2875d87ac69..75e68b9ba07a5 100644 --- a/recipes/melon/all/conanfile.py +++ b/recipes/melon/all/conanfile.py @@ -15,8 +15,8 @@ class PackageConan(ConanFile): # Use short name only, conform to SPDX License List: https://spdx.org/licenses/ # In case it's not listed there, use "LicenseRef-" license = "BSL-1.0" - url = "https://github.com/fhamonic/melon" - homepage = "https://github.com/project/package" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/fhamonic/melon" # Do not put "conan" nor the project name in topics. Use topics from the upstream listed on GH # Keep 'header-only' as topic topics = ("graph", "algorithm", "ranges", "c++20", "header-only") From 7ee12be3bf2ffc5f8cbde656144cc5764ce6c5f3 Mon Sep 17 00:00:00 2001 From: fhamonic Date: Thu, 12 Sep 2024 12:32:13 +0200 Subject: [PATCH 3/4] removed unecessary stuff in conanfile.py + improved test_package --- recipes/melon/all/conanfile.py | 40 +------------- .../melon/all/test_package/test_package.cpp | 53 ++++++++++++------- 2 files changed, 35 insertions(+), 58 deletions(-) diff --git a/recipes/melon/all/conanfile.py b/recipes/melon/all/conanfile.py index 75e68b9ba07a5..8251aea3e522e 100644 --- a/recipes/melon/all/conanfile.py +++ b/recipes/melon/all/conanfile.py @@ -12,25 +12,18 @@ class PackageConan(ConanFile): name = "melon" description = "A modern and efficient graph library using C++20 ranges and concepts." - # Use short name only, conform to SPDX License List: https://spdx.org/licenses/ - # In case it's not listed there, use "LicenseRef-" license = "BSL-1.0" url = "https://github.com/conan-io/conan-center-index" homepage = "https://github.com/fhamonic/melon" - # Do not put "conan" nor the project name in topics. Use topics from the upstream listed on GH - # Keep 'header-only' as topic topics = ("graph", "algorithm", "ranges", "c++20", "header-only") package_type = "header-library" - # Keep these or explain why it's not required for this particular case settings = "os", "arch", "compiler", "build_type" - # Do not copy sources to build folder for header only projects, unless you need to apply patches no_copy_source = True @property def _min_cppstd(self): return 20 - # In case the project requires C++14/17/20/... the minimum compiler version should be listed @property def _compilers_minimum_version(self): return { @@ -41,28 +34,21 @@ def _compilers_minimum_version(self): "Visual Studio": "17", } - # Use the export_sources(self) method instead of the exports_sources attribute. - # This allows finer grain exportation of patches per version def export_sources(self): export_conandata_patches(self) def layout(self): - # src_folder must use the same source folder name than the project basic_layout(self, src_folder="src") def requirements(self): - # Prefer self.requires method instead of requires attribute - # Direct dependencies of header only libs are always transitive since they are included in public headers - self.requires("range-v3/[>=0.11.0]", transitive_headers=True) - self.requires("fmt/[>=10.0.0]", transitive_headers=True) + self.requires("range-v3/[>=0.11.0]") + self.requires("fmt/[>=10.0.0]") - # same package ID for any package def package_id(self): self.info.clear() def validate(self): if self.settings.compiler.get_safe("cppstd"): - # Validate the minimum cpp standard supported when installing the package. For C++ projects only check_min_cppstd(self, self._min_cppstd) minimum_version = self._compilers_minimum_version.get(str(self.settings.compiler), False) if minimum_version and Version(self.settings.compiler.version) < minimum_version: @@ -70,12 +56,7 @@ def validate(self): f"{self.ref} requires C++{self._min_cppstd}, which your compiler does not support." ) - # In case this library does not work in some another configuration, it should be validated here too - if self.settings.os == "Windows": - raise ConanInvalidConfiguration(f"{self.ref} can not be used on Windows.") - def source(self): - # Download source package and extract to source folder get(self, **self.conan_data["sources"][self.version], strip_root=True) # Not mandatory when there is no patch, but will suppress warning message about missing build() method @@ -83,7 +64,6 @@ def build(self): # The attribute no_copy_source should not be used when applying patches in build apply_conandata_patches(self) - # Copy all files to the package folder def package(self): copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses")) copy( @@ -94,24 +74,8 @@ def package(self): ) def package_info(self): - # Folders not used for header-only self.cpp_info.bindirs = [] self.cpp_info.libdirs = [] - # Set these to the appropriate values if the package has an official FindPACKAGE.cmake - # listed in https://cmake.org/cmake/help/latest/manual/cmake-modules.7.html#find-modules - # examples: bzip2, freetype, gdal, icu, libcurl, libjpeg, libpng, libtiff, openssl, sqlite3, zlib... - # self.cpp_info.set_property("cmake_module_file_name", "melon") - # self.cpp_info.set_property("cmake_module_target_name", "melon::melon") - - # Set these to the appropriate values if package provides a CMake config file - # (package-config.cmake or packageConfig.cmake, with package::package target, usually installed in /lib/cmake//) - # self.cpp_info.set_property("cmake_file_name", "melon") - # self.cpp_info.set_property("cmake_target_name", "melon::melon") - # Set this to the appropriate value if the package provides a pkgconfig file - # (package.pc, usually installed in /lib/pkgconfig/) - # self.cpp_info.set_property("pkg_config_name", "melon") - - # Add m, pthread and dl if needed in Linux/FreeBSD if self.settings.os in ["Linux", "FreeBSD"]: self.cpp_info.system_libs.extend(["pthread"]) diff --git a/recipes/melon/all/test_package/test_package.cpp b/recipes/melon/all/test_package/test_package.cpp index 7e18262cace47..bff007b231748 100644 --- a/recipes/melon/all/test_package/test_package.cpp +++ b/recipes/melon/all/test_package/test_package.cpp @@ -4,31 +4,44 @@ using namespace fhamonic::melon; -int main(int argc, char * argv[]) { +// test_package with bidirectional dijkstra because it condenses range-v3 uses +// shown to overwhelm some compilers + +int main(int argc, char *argv[]) +{ static_digraph_builder builder(6); - builder.add_arc(0u, 1u, 7); - builder.add_arc(0u, 2u, 9); - builder.add_arc(0u, 5u, 14); - builder.add_arc(1u, 0u, 7); - builder.add_arc(1u, 2u, 10); - builder.add_arc(1u, 3u, 15); - builder.add_arc(2u, 0u, 9); - builder.add_arc(2u, 1u, 10); - builder.add_arc(2u, 3u, 12); - builder.add_arc(2u, 5u, 2); - builder.add_arc(3u, 1u, 15); - builder.add_arc(3u, 2u, 12); - builder.add_arc(3u, 4u, 6); - builder.add_arc(4u, 3u, 6); - builder.add_arc(4u, 5u, 9); - builder.add_arc(5u, 0u, 14); - builder.add_arc(5u, 2u, 2); - builder.add_arc(5u, 4u, 9); + builder.add_arc(0u, 1u, 7); // 0 + builder.add_arc(0u, 2u, 9); // 1 + builder.add_arc(0u, 5u, 14); // 2 + builder.add_arc(1u, 0u, 7); // 3 + builder.add_arc(1u, 2u, 10); // 4 + builder.add_arc(1u, 3u, 15); // 5 + builder.add_arc(2u, 0u, 9); // 6 + builder.add_arc(2u, 1u, 10); // 7 + builder.add_arc(2u, 3u, 12); // 8 + builder.add_arc(2u, 5u, 2); // 9 + builder.add_arc(3u, 1u, 15); // 10 + builder.add_arc(3u, 2u, 12); // 11 + builder.add_arc(3u, 4u, 6); // 12 + builder.add_arc(4u, 3u, 6); // 13 + builder.add_arc(4u, 5u, 9); // 14 + builder.add_arc(5u, 0u, 14); // 15 + builder.add_arc(5u, 2u, 2); // 16 + builder.add_arc(5u, 4u, 9); // 17 auto [graph, length_map] = builder.build(); bidirectional_dijkstra alg(graph, length_map, 0u, 3u); - return alg.run() == 21 ? EXIT_SUCCESS : EXIT_FAILURE; + int dist = alg.run(); + if (dist != 21) return EXIT_FAILURE; + + if (!alg.path_found()) return EXIT_FAILURE; + auto path = alg.path(); + if (std::ranges::distance(path) != 2) return EXIT_FAILURE; + if (std::ranges::find(path, 1u) == path.end()) return EXIT_FAILURE; + if (std::ranges::find(path, 8u) == path.end()) return EXIT_FAILURE; + + return EXIT_SUCCESS; } \ No newline at end of file From 45111c259f8be8264769d4174e9faa7bb1a7a9f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Abril=20Rinc=C3=B3n=20Blanco?= Date: Mon, 16 Sep 2024 11:56:54 +0200 Subject: [PATCH 4/4] Cleanup, pin dependencies --- recipes/melon/all/conanfile.py | 13 ++++--------- recipes/melon/all/test_package/CMakeLists.txt | 5 +---- recipes/melon/all/test_package/test_package.cpp | 2 +- 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/recipes/melon/all/conanfile.py b/recipes/melon/all/conanfile.py index 8251aea3e522e..0d83d36ecc529 100644 --- a/recipes/melon/all/conanfile.py +++ b/recipes/melon/all/conanfile.py @@ -1,7 +1,7 @@ from conan import ConanFile from conan.errors import ConanInvalidConfiguration from conan.tools.build import check_min_cppstd -from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get +from conan.tools.files import copy, get from conan.tools.layout import basic_layout from conan.tools.scm import Version import os @@ -34,15 +34,12 @@ def _compilers_minimum_version(self): "Visual Studio": "17", } - def export_sources(self): - export_conandata_patches(self) - def layout(self): basic_layout(self, src_folder="src") def requirements(self): - self.requires("range-v3/[>=0.11.0]") - self.requires("fmt/[>=10.0.0]") + self.requires("range-v3/0.12.0") + self.requires("fmt/10.2.1") def package_id(self): self.info.clear() @@ -59,10 +56,8 @@ def validate(self): def source(self): get(self, **self.conan_data["sources"][self.version], strip_root=True) - # Not mandatory when there is no patch, but will suppress warning message about missing build() method def build(self): - # The attribute no_copy_source should not be used when applying patches in build - apply_conandata_patches(self) + pass def package(self): copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses")) diff --git a/recipes/melon/all/test_package/CMakeLists.txt b/recipes/melon/all/test_package/CMakeLists.txt index fbed126ed191d..17e2b8206c6aa 100644 --- a/recipes/melon/all/test_package/CMakeLists.txt +++ b/recipes/melon/all/test_package/CMakeLists.txt @@ -1,11 +1,8 @@ cmake_minimum_required(VERSION 3.15) -# project(test_package LANGUAGES C) # if the project is pure C -project(test_package LANGUAGES CXX) # if the project uses c++ +project(test_package LANGUAGES CXX) find_package(melon REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.cpp) -# don't link to ${CONAN_LIBS} or CONAN_PKG::package target_link_libraries(${PROJECT_NAME} PRIVATE melon::melon) -# In case the target project need a specific C++ standard target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20) diff --git a/recipes/melon/all/test_package/test_package.cpp b/recipes/melon/all/test_package/test_package.cpp index bff007b231748..f0417c2d7cc52 100644 --- a/recipes/melon/all/test_package/test_package.cpp +++ b/recipes/melon/all/test_package/test_package.cpp @@ -44,4 +44,4 @@ int main(int argc, char *argv[]) if (std::ranges::find(path, 8u) == path.end()) return EXIT_FAILURE; return EXIT_SUCCESS; -} \ No newline at end of file +}