From bbf84d7cf3270c56140dc08eb609b7f78ab54e11 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Mon, 15 Apr 2024 11:11:08 +0300 Subject: [PATCH 1/3] suitesparse-lagraph: new recipe --- recipes/suitesparse-lagraph/all/conandata.yml | 4 + recipes/suitesparse-lagraph/all/conanfile.py | 102 ++++++++++++++++++ .../all/test_package/A.mtx | 18 ++++ .../all/test_package/CMakeLists.txt | 8 ++ .../all/test_package/conanfile.py | 27 +++++ .../all/test_package/test_package.c | 30 ++++++ recipes/suitesparse-lagraph/config.yml | 3 + 7 files changed, 192 insertions(+) create mode 100644 recipes/suitesparse-lagraph/all/conandata.yml create mode 100644 recipes/suitesparse-lagraph/all/conanfile.py create mode 100644 recipes/suitesparse-lagraph/all/test_package/A.mtx create mode 100644 recipes/suitesparse-lagraph/all/test_package/CMakeLists.txt create mode 100644 recipes/suitesparse-lagraph/all/test_package/conanfile.py create mode 100644 recipes/suitesparse-lagraph/all/test_package/test_package.c create mode 100644 recipes/suitesparse-lagraph/config.yml diff --git a/recipes/suitesparse-lagraph/all/conandata.yml b/recipes/suitesparse-lagraph/all/conandata.yml new file mode 100644 index 0000000000000..61b638ca85911 --- /dev/null +++ b/recipes/suitesparse-lagraph/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "1.1.3": + url: "https://github.com/DrTimothyAldenDavis/SuiteSparse/archive/refs/tags/v7.7.0.tar.gz" + sha256: "529b067f5d80981f45ddf6766627b8fc5af619822f068f342aab776e683df4f3" diff --git a/recipes/suitesparse-lagraph/all/conanfile.py b/recipes/suitesparse-lagraph/all/conanfile.py new file mode 100644 index 0000000000000..fd78f8d808a93 --- /dev/null +++ b/recipes/suitesparse-lagraph/all/conanfile.py @@ -0,0 +1,102 @@ +import os + +from conan import ConanFile +from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout +from conan.tools.env import VirtualBuildEnv +from conan.tools.files import get, rm, rmdir, copy + +required_conan_version = ">=1.53.0" + + +class SuiteSparseLagraphConan(ConanFile): + name = "suitesparse-lagraph" + description = "LAGraph: Library plus test harness for collecting algorithms that use GraphBLAS" + license = "BSD-2-Clause" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://lagraph.readthedocs.io/en/latest/" + topics = ("graph-algorithms", "mathematics", "sparse-matrix", "linear-algebra") + + package_type = "library" + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + } + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + + def configure(self): + if self.options.shared: + self.options.rm_safe("fPIC") + self.settings.rm_safe("compiler.cppstd") + self.settings.rm_safe("compiler.libcxx") + + def layout(self): + cmake_layout(self, src_folder="src") + + def requirements(self): + self.requires("suitesparse-graphblas/9.1.0", transitive_headers=True, transitive_libs=True) + + def build_requirements(self): + self.tool_requires("cmake/[>=3.20 <4]") + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + venv = VirtualBuildEnv(self) + venv.generate() + + tc = CMakeToolchain(self) + tc.variables["BUILD_SHARED_LIBS"] = self.options.shared + tc.variables["BUILD_STATIC_LIBS"] = not self.options.shared + tc.variables["SUITESPARSE_USE_OPENMP"] = True + tc.variables["SUITESPARSE_USE_CUDA"] = False + tc.variables["SUITESPARSE_DEMOS"] = False + tc.variables["SUITESPARSE_USE_FORTRAN"] = False # Fortran sources are translated to C instead + tc.generate() + + deps = CMakeDeps(self) + deps.generate() + + def build(self): + cmake = CMake(self) + cmake.configure(build_script_folder=os.path.join(self.source_folder, "LAGraph")) + cmake.build() + + def package(self): + copy(self, "LICENSE", os.path.join(self.source_folder, "Doc"), os.path.join(self.package_folder, "licenses")) + cmake = CMake(self) + cmake.install() + rmdir(self, 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, "share")) + rm(self, "*.pdb", self.package_folder, recursive=True) + + def package_info(self): + self.cpp_info.set_property("cmake_file_name", "LAGraph") + + self.cpp_info.components["LAGraph"].set_property("cmake_target_name", "SuiteSparse::LAGraph") + if not self.options.shared: + self.cpp_info.components["KLU"].set_property("cmake_target_aliases", ["SuiteSparse::LAGraph_static"]) + self.cpp_info.components["LAGraph"].set_property("pkg_config_name", "LAGraph") + self.cpp_info.components["LAGraph"].libs = ["lagraph"] + self.cpp_info.components["LAGraph"].requires = ["suitesparse-graphblas::suitesparse-graphblas"] + self.cpp_info.components["LAGraph"].includedirs.append(os.path.join("include", "suitesparse")) + self.cpp_info.components["LAGraph"].defines.append("LG_DLL") + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.components["LAGraph"].system_libs.extend(["m", "pthread"]) + + self.cpp_info.components["LAGraphX"].set_property("cmake_target_name", "SuiteSparse::LAGraphX") + if not self.options.shared: + self.cpp_info.components["KLU"].set_property("cmake_target_aliases", ["SuiteSparse::LAGraph_static"]) + self.cpp_info.components["LAGraphX"].set_property("pkg_config_name", "LAGraphX") + self.cpp_info.components["LAGraphX"].libs = ["lagraphx"] + self.cpp_info.components["LAGraphX"].requires = ["LAGraph"] + diff --git a/recipes/suitesparse-lagraph/all/test_package/A.mtx b/recipes/suitesparse-lagraph/all/test_package/A.mtx new file mode 100644 index 0000000000000..47a8bbbae798a --- /dev/null +++ b/recipes/suitesparse-lagraph/all/test_package/A.mtx @@ -0,0 +1,18 @@ +%%MatrixMarket matrix coordinate pattern symmetric +%%GraphBLAS type bool +7 7 15 +2 1 +3 1 +3 2 +4 2 +4 3 +5 2 +5 4 +6 2 +6 3 +6 4 +7 1 +7 3 +7 4 +7 5 +7 6 diff --git a/recipes/suitesparse-lagraph/all/test_package/CMakeLists.txt b/recipes/suitesparse-lagraph/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..2d55672af1c1f --- /dev/null +++ b/recipes/suitesparse-lagraph/all/test_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES C) + +find_package(LAGraph REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.c) +target_link_libraries(${PROJECT_NAME} PRIVATE SuiteSparse::LAGraph) +target_compile_features(${PROJECT_NAME} PRIVATE c_std_11) diff --git a/recipes/suitesparse-lagraph/all/test_package/conanfile.py b/recipes/suitesparse-lagraph/all/test_package/conanfile.py new file mode 100644 index 0000000000000..b3531cb5ede2b --- /dev/null +++ b/recipes/suitesparse-lagraph/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 + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + 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) + cmake.configure() + cmake.build() + + def test(self): + if can_run(self): + bin_path = os.path.join(self.cpp.build.bindir, "test_package") + test_matrix = os.path.join(self.source_folder, "A.mtx") + self.run(f"{bin_path} < {test_matrix}", env="conanrun") diff --git a/recipes/suitesparse-lagraph/all/test_package/test_package.c b/recipes/suitesparse-lagraph/all/test_package/test_package.c new file mode 100644 index 0000000000000..583bb52508e59 --- /dev/null +++ b/recipes/suitesparse-lagraph/all/test_package/test_package.c @@ -0,0 +1,30 @@ +#include + +int main (void) +{ + // initialize LAGraph + char msg [LAGRAPH_MSG_LEN] ; + LAGraph_Init (msg) ; + GrB_Matrix A = NULL ; + GrB_Vector centrality = NULL ; + LAGraph_Graph G = NULL ; + + // read a Matrix Market file from stdin and create a graph + LAGraph_MMRead (&A, stdin, msg) ; + LAGraph_New (&G, &A, LAGraph_ADJACENCY_UNDIRECTED, msg) ; + + // compute the out-degree of every node + LAGraph_Cached_OutDegree (G, msg) ; + + // compute the pagerank + int niters = 0 ; + LAGr_PageRank (¢rality, &niters, G, 0.85, 1e-4, 100, msg) ; + + // print the result + LAGraph_Vector_Print (centrality, LAGraph_COMPLETE, stdout, msg) ; + + // free the graph, the pagerank, and finish LAGraph + LAGraph_Delete (&G, msg) ; + GrB_free (¢rality) ; + LAGraph_Finalize (msg) ; +} diff --git a/recipes/suitesparse-lagraph/config.yml b/recipes/suitesparse-lagraph/config.yml new file mode 100644 index 0000000000000..e1c4f3be24983 --- /dev/null +++ b/recipes/suitesparse-lagraph/config.yml @@ -0,0 +1,3 @@ +versions: + "1.1.3": + folder: all From 1bafea29f29ccdeec37b1a80b08aab2e8c253f01 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Fri, 14 Jun 2024 14:35:49 +0300 Subject: [PATCH 2/3] suitesparse-lagraph: fix license installation --- recipes/suitesparse-lagraph/all/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/suitesparse-lagraph/all/conanfile.py b/recipes/suitesparse-lagraph/all/conanfile.py index fd78f8d808a93..49c44071c537e 100644 --- a/recipes/suitesparse-lagraph/all/conanfile.py +++ b/recipes/suitesparse-lagraph/all/conanfile.py @@ -71,7 +71,7 @@ def build(self): cmake.build() def package(self): - copy(self, "LICENSE", os.path.join(self.source_folder, "Doc"), os.path.join(self.package_folder, "licenses")) + copy(self, "LICENSE", os.path.join(self.source_folder, "LAGraph"), os.path.join(self.package_folder, "licenses")) cmake = CMake(self) cmake.install() rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) From 6e46cd8cea7d5d62d1e99f7577478ce875276105 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Wed, 16 Oct 2024 18:34:02 +0300 Subject: [PATCH 3/3] suitesparse-lagraph: fix static build --- recipes/suitesparse-lagraph/all/conanfile.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/recipes/suitesparse-lagraph/all/conanfile.py b/recipes/suitesparse-lagraph/all/conanfile.py index 49c44071c537e..ad2b5475ebfd5 100644 --- a/recipes/suitesparse-lagraph/all/conanfile.py +++ b/recipes/suitesparse-lagraph/all/conanfile.py @@ -1,9 +1,10 @@ import os +from pydoc import replace from conan import ConanFile from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout from conan.tools.env import VirtualBuildEnv -from conan.tools.files import get, rm, rmdir, copy +from conan.tools.files import get, rm, rmdir, copy, replace_in_file required_conan_version = ">=1.53.0" @@ -63,9 +64,16 @@ def generate(self): tc.generate() deps = CMakeDeps(self) + deps.set_property("suitesparse-graphblas", "cmake_find_mode", "both") deps.generate() + def _patch_sources(self): + replace_in_file(self, os.path.join(self.source_folder, "LAGraph", "CMakeLists.txt"), + 'set ( LAGRAPH_STATIC_LIBS "-l$ ${LAGRAPH_STATIC_LIBS}" )', + 'set ( LAGRAPH_STATIC_LIBS "GraphBLAS::GraphBLAS ${LAGRAPH_STATIC_LIBS}" )') + def build(self): + self._patch_sources() cmake = CMake(self) cmake.configure(build_script_folder=os.path.join(self.source_folder, "LAGraph")) cmake.build()