File: build.py

package info (click to toggle)
python-suitesparse-graphblas 7.4.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 956 kB
  • sloc: ansic: 9,939; python: 3,575; sh: 52; makefile: 13
file content (41 lines) | stat: -rw-r--r-- 1,098 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import os
import sys
import platform

from cffi import FFI

is_win = sys.platform.startswith("win")
is_arm64 = platform.machine() == "arm64"
is_ppc64le = platform.machine() == "ppc64le"  # Use same header as arm64, which *may* work
thisdir = os.path.dirname(__file__)

ffibuilder = FFI()

with open(os.path.join(thisdir, "source.c")) as f:
    source = f.read()

include_dirs = [os.path.join(sys.prefix, "include")]
library_dirs = [os.path.join(sys.prefix, "lib")]
if is_win:
    include_dirs.append(os.path.join(sys.prefix, "Library", "include"))
    library_dirs.append(os.path.join(sys.prefix, "Library", "lib"))

ffibuilder.set_source(
    "suitesparse_graphblas._graphblas",
    source,
    libraries=["graphblas"],
    include_dirs=include_dirs,
    library_dirs=library_dirs,
)

header = "suitesparse_graphblas.h"
if is_win:
    header = "suitesparse_graphblas_no_complex.h"
if is_arm64 or is_ppc64le:
    header = "suitesparse_graphblas_arm64.h"
gb_cdef = open(os.path.join(thisdir, header))

ffibuilder.cdef(gb_cdef.read())

if __name__ == "__main__":
    ffibuilder.compile(verbose=True)