Skip to content

Added support of building using the deps fetched from pkg-config. #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions headers/fastpfor
4 changes: 2 additions & 2 deletions python_bindings/pyfastpfor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>

#include "headers/codecfactory.h"
#include "headers/deltautil.h"
#include <fastpfor/codecfactory.h>
#include <fastpfor/deltautil.h>

namespace py = pybind11;

Expand Down
113 changes: 96 additions & 17 deletions python_bindings/setup.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,119 @@
import os
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
import shutil
import subprocess
import sys

import setuptools
from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext

__version__ = '1.3.6'

maindir = os.path.join(".", "fastpfor")
library_file = os.path.join(maindir, "libFastPFor.a")
source_files = ['pyfastpfor.cc']
pcCommand = shutil.which("pkgconf")
if not pcCommand:
pcCommand = shutil.which("pkg-config")
pcCommand = None


def runPkgConfig(arg, package):
return subprocess.run([pcCommand, arg, package], capture_output=True).stdout.decode(
"utf-8"
)


def getInfoFromPkgConfig(arg, pkgName):
res = str(runPkgConfig(arg, pkgName))[:-1].split(" ")
if len(res) == 1 and not res[0]:
return ()

return res


def processPkgConfigLibDir(l):
if l.startswith("-L"):
l = l[2:]
return l

raise ValueError("Wrong lib dir flag", l)


def processPkgConfigIncludeDir(i):
if i.startswith("-I"):
i = i[2:]
return i

libraries = []
extra_objects = []
raise ValueError("Wrong include dir flag", i)

requirements_list = ['pybind11>=2.4', 'numpy']

if os.path.exists(library_file):
# if we have a prebuilt library file, use that.
extra_objects.append(library_file)
def processPkgConfigLib(l):
if l.startswith("-l"):
l = l[2:]
if l.startswith(":"):
l = l[1:]
return l

raise ValueError("Wrong lib flag", l)


def getPcInfo(pkgName):
if pcCommand:
extra_compile_args = getInfoFromPkgConfig("-cflags", pkgName)
include_dirs = [
processPkgConfigIncludeDir(l)
for l in getInfoFromPkgConfig("--cflags-only-I", pkgName)
]
libs_dirs = [
processPkgConfigLibDir(l) for l in getInfoFromPkgConfig("--libs-only-L", pkgName)
]
libraries = [processPkgConfigLib(l) for l in getInfoFromPkgConfig("--libs", pkgName)]
extra_objects = getInfoFromPkgConfig("--static", pkgName)
else:
extra_compile_args = include_dirs = libs_dirs = libraries = extra_objects = ()

return extra_compile_args, include_dirs, libs_dirs, libraries, extra_objects


extra_compile_args, include_dirs, libs_dirs, libraries, extra_objects = pkgConfigInfo = getPcInfo("fastpfor")

source_files = ["pyfastpfor.cc"]
requirements_list = ["pybind11>=2.4", "numpy"]


if any(pkgConfigInfo):
pass
else:
# Otherwise build all the files here directly (excluding test files)
exclude_files = set("""unit.cpp codecs.cpp""".split())
maindir = os.path.join(".", "fastpfor")
library_file = os.path.join(maindir, "libFastPFor.a")
extra_compile_args = ()

for root, subdirs, files in os.walk(os.path.join(maindir, "src")):
source_files.extend(os.path.join(root, f) for f in files
if (f.endswith(".cc") or f.endswith(".c") or f.endswith(".cpp")) and f not in exclude_files)
extra_objects = []

if os.path.exists(library_file):
# if we have a prebuilt library file, use that.
extra_objects.append(library_file)

else:
# Otherwise build all the files here directly (excluding test files)
exclude_files = set("""unit.cpp codecs.cpp""".split())

for root, subdirs, files in os.walk(os.path.join(maindir, "src")):
source_files.extend(
os.path.join(root, f)
for f in files
if (f.endswith(".cc") or f.endswith(".c") or f.endswith(".cpp"))
and f not in exclude_files
)
include_dirs = [maindir, os.path.join(maindir, "headers")]

ext_modules = [
Extension(
'pyfastpfor',
source_files,
include_dirs=[maindir, os.path.join(maindir, "headers")],
include_dirs=include_dirs,
libraries=libraries,
language='c++',
extra_objects=extra_objects,
extra_compile_args = extra_compile_args,
),
]

Expand Down