Skip to content

Commit 329f944

Browse files
authored
Support building from source with user-specified GraphBLAS (#85)
* Support building from source with user-specified GraphBLAS Look for GraphBLAS first in GraphBLAS_ROOT env var, if empty then fallback to current paths * Add note about LD_LIBRARY_PATH
1 parent 1d266a9 commit 329f944

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

README.md

+30
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,33 @@ This is a base package that exposes only the low level CFFI API
1212
bindings and symbols. This package is shared by the syntax bindings
1313
[pygraphblas](https://github.com/Graphegon/pygraphblas) and
1414
[python-graphblas](https://github.com/python-graphblas/python-graphblas).
15+
16+
17+
## Installation from pre-built wheels
18+
Pre-built wheels for common platforms are available from PyPI and conda. These bundle a compiled copy of SuiteSparse:GraphBLAS.
19+
20+
```bash
21+
pip install suitesparse-graphblas
22+
```
23+
24+
or
25+
26+
```bash
27+
conda install -c conda-forge python-suitesparse-graphblas
28+
```
29+
30+
## Installation from source
31+
If you wish to link against your own copy of SuiteSparse:GraphBLAS you may build from source.
32+
33+
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/`.
34+
35+
```bash
36+
export GraphBLAS_ROOT="/path/to/graphblas"
37+
pip install suitesparse-graphblas-*.tar.gz
38+
```
39+
You may also have to appropriately set `LD_LIBRARY_PATH` to find `libgraphblas` at runtime.
40+
41+
For example, to use Homebrew's SuiteSparse:GraphBLAS on macOS, with the sdist from PyPI, and with all dependencies using wheels:
42+
```bash
43+
GraphBLAS_ROOT="$(brew --prefix suitesparse)" pip install --no-binary suitesparse-graphblas suitesparse-graphblas
44+
```

build_graphblas_cffi.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,23 @@
1010

1111
ffibuilder = FFI()
1212

13-
include_dirs = [os.path.join(sys.prefix, "include")]
14-
library_dirs = [os.path.join(sys.prefix, "lib")]
13+
# GraphBLAS_ROOT env var can point to the root directory of GraphBLAS to link against.
14+
# Expected subdirectories: include/ (contains GraphBLAS.h), lib/, and bin/ (on Windows only)
15+
# Otherwise fallback to default system folders.
16+
graphblas_root = os.environ.get("GraphBLAS_ROOT", None)
17+
if not graphblas_root:
18+
# Windows wheels.yml configures suitesparse.sh to install GraphBLAS to "C:\\GraphBLAS".
19+
graphblas_root = "C:\\GraphBLAS" if is_win else sys.prefix
20+
21+
include_dirs = [os.path.join(graphblas_root, "include")]
22+
library_dirs = [os.path.join(graphblas_root, "lib")]
1523
if is_win:
1624
include_dirs.append(os.path.join(sys.prefix, "Library", "include"))
1725
library_dirs.append(os.path.join(sys.prefix, "Library", "lib"))
1826

19-
# wheels.yml configures suitesparse.sh to install GraphBLAS here.
20-
prefix = "C:\\GraphBLAS"
21-
include_dirs.append(os.path.join(prefix, "include"))
22-
library_dirs.append(os.path.join(prefix, "lib"))
23-
library_dirs.append(os.path.join(prefix, "bin"))
27+
include_dirs.append(os.path.join(graphblas_root, "include"))
28+
library_dirs.append(os.path.join(graphblas_root, "lib"))
29+
library_dirs.append(os.path.join(graphblas_root, "bin"))
2430

2531
ffibuilder.set_source(
2632
"suitesparse_graphblas._graphblas",

0 commit comments

Comments
 (0)