From 2fbeaf8d8bb42fdf98df71d02b825094559ed6cb Mon Sep 17 00:00:00 2001 From: Adam Lugowski Date: Tue, 2 May 2023 19:53:58 -0700 Subject: [PATCH 1/2] Support building from source with user-specified GraphBLAS Look for GraphBLAS first in GraphBLAS_ROOT env var, if empty then fallback to current paths --- README.md | 29 +++++++++++++++++++++++++++++ build_graphblas_cffi.py | 20 +++++++++++++------- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 17f7ffa..b193eb8 100644 --- a/README.md +++ b/README.md @@ -12,3 +12,32 @@ This is a base package that exposes only the low level CFFI API bindings and symbols. This package is shared by the syntax bindings [pygraphblas](https://github.com/Graphegon/pygraphblas) and [python-graphblas](https://github.com/python-graphblas/python-graphblas). + + +## Installation via pre-built wheels +Pre-built wheels for common platforms are available via PyPI and conda. These bundle a compiled copy of SuiteSparse:GraphBLAS. + +```bash +pip install suitesparse-graphblas +``` + +or + +```bash +conda install -c conda-forge python-suitesparse-graphblas +``` + +## Installation from source +If you wish to link against your own copy of SuiteSparse:GraphBLAS you may build from source. + +Specify the location of your SuiteSparse:GraphBLAS installation in the `GraphBLAS_ROOT` environment variable then use the standard pip build from source mechanism. This location must contain `include/GraphBLAS.h` and `lib/`. + +```bash +export GraphBLAS_ROOT="/path/to/graphblas" +pip install suitesparse-graphblas-*.tar.gz +``` + +For example, to use Homebrew's SuiteSparse:GraphBLAS on macOS, with the sdist from PyPI, and with all dependencies using wheels: +```bash +GraphBLAS_ROOT="$(brew --prefix suitesparse)" pip install --no-binary suitesparse-graphblas suitesparse-graphblas +``` diff --git a/build_graphblas_cffi.py b/build_graphblas_cffi.py index dff21e6..1c73e1c 100644 --- a/build_graphblas_cffi.py +++ b/build_graphblas_cffi.py @@ -10,17 +10,23 @@ ffibuilder = FFI() -include_dirs = [os.path.join(sys.prefix, "include")] -library_dirs = [os.path.join(sys.prefix, "lib")] +# GraphBLAS_ROOT env var can point to the root directory of GraphBLAS to link against. +# Expected subdirectories: include/ (contains GraphBLAS.h), lib/, and bin/ (on Windows only) +# Otherwise fallback to default system folders. +graphblas_root = os.environ.get("GraphBLAS_ROOT", None) +if not graphblas_root: + # Windows wheels.yml configures suitesparse.sh to install GraphBLAS to "C:\\GraphBLAS". + graphblas_root = "C:\\GraphBLAS" if is_win else sys.prefix + +include_dirs = [os.path.join(graphblas_root, "include")] +library_dirs = [os.path.join(graphblas_root, "lib")] if is_win: include_dirs.append(os.path.join(sys.prefix, "Library", "include")) library_dirs.append(os.path.join(sys.prefix, "Library", "lib")) - # wheels.yml configures suitesparse.sh to install GraphBLAS here. - prefix = "C:\\GraphBLAS" - include_dirs.append(os.path.join(prefix, "include")) - library_dirs.append(os.path.join(prefix, "lib")) - library_dirs.append(os.path.join(prefix, "bin")) + include_dirs.append(os.path.join(graphblas_root, "include")) + library_dirs.append(os.path.join(graphblas_root, "lib")) + library_dirs.append(os.path.join(graphblas_root, "bin")) ffibuilder.set_source( "suitesparse_graphblas._graphblas", From 4dc451a39825191970d55c7e88e7a8294d3dfb0d Mon Sep 17 00:00:00 2001 From: Adam Lugowski Date: Wed, 3 May 2023 12:26:18 -0700 Subject: [PATCH 2/2] Add note about LD_LIBRARY_PATH --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b193eb8..2d15f15 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,8 @@ bindings and symbols. This package is shared by the syntax bindings [python-graphblas](https://github.com/python-graphblas/python-graphblas). -## Installation via pre-built wheels -Pre-built wheels for common platforms are available via PyPI and conda. These bundle a compiled copy of SuiteSparse:GraphBLAS. +## Installation from pre-built wheels +Pre-built wheels for common platforms are available from PyPI and conda. These bundle a compiled copy of SuiteSparse:GraphBLAS. ```bash pip install suitesparse-graphblas @@ -36,6 +36,7 @@ Specify the location of your SuiteSparse:GraphBLAS installation in the `GraphBLA export GraphBLAS_ROOT="/path/to/graphblas" pip install suitesparse-graphblas-*.tar.gz ``` +You may also have to appropriately set `LD_LIBRARY_PATH` to find `libgraphblas` at runtime. For example, to use Homebrew's SuiteSparse:GraphBLAS on macOS, with the sdist from PyPI, and with all dependencies using wheels: ```bash