Commit 8e19af30 authored by Kirill Smelkov's avatar Kirill Smelkov

setup: Factor common code to build a py extension into Ext

Currently we have only one extension wendelin.bigfile._bigfile, but we
are going to add more both python extensions and non-python DSOs. Start
preparing to that by factoring-out common code.
parent c45c2de8
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
# #
# See COPYING file for full licensing terms. # See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options. # See https://www.nexedi.com/licensing for rationale and options.
from setuptools import setup, Extension, Command, find_packages from setuptools import setup, Extension as _Ext, Command, find_packages
from setuptools.command.build_py import build_py as _build_py from setuptools.command.build_py import build_py as _build_py
from setuptools.command.build_ext import build_ext as _build_ext from setuptools.command.build_ext import build_ext as _build_ext
from pkg_resources import working_set, EntryPoint from pkg_resources import working_set, EntryPoint
...@@ -28,47 +28,52 @@ import os ...@@ -28,47 +28,52 @@ import os
import sys import sys
_bigfile = Extension('wendelin.bigfile._bigfile', # _with_defaults calls what(*argv, **kw) with kw amended with default build flags.
sources = [ # e.g. _with_defaults(_Ext, *argv, **kw)
'bigfile/_bigfile.c', def _with_defaults(what, *argv, **kw):
'bigfile/pagefault.c', kw = kw.copy()
'bigfile/pagemap.c', kw['include_dirs'] = [
'bigfile/ram.c', '.',
'bigfile/ram_shmfs.c', './include',
'bigfile/ram_hugetlbfs.c', './3rdparty/ccan',
'bigfile/virtmem.c', './3rdparty/include',
'lib/bug.c', ]
'lib/utils.c',
], ccdefault = [
include_dirs = [ '-std=gnu99', # declarations inside for-loop
'.', '-fplan9-extensions', # anonymous-structs + simple inheritance
'./include', '-fvisibility=hidden', # by default symbols not visible outside DSO
'./3rdparty/ccan',
'./3rdparty/include' # in C99 declaration after statement is ok, and we explicitly compile with -std=gnu99.
], # Python >= 3.4 however adds -Werror=declaration-after-statement even for extension
define_macros = [('_GNU_SOURCE',None)], # modules irregardless of their compilation flags:
extra_compile_args = [ #
'-std=gnu99', # declarations inside for-loop # https://bugs.python.org/issue21121
'-fplan9-extensions', # anonymous-structs + simple inheritance #
'-fvisibility=hidden', # by default symbols not visible outside DSO # ensure there is no warnings / errors for decl-after-statements.
'-Wno-declaration-after-statement',
# in C99 declaration after statement is ok, and we explicitly compile with -std=gnu99. '-Wno-error=declaration-after-statement',
# Python >= 3.4 however adds -Werror=declaration-after-statement even for extension ]
# modules irregardless of their compilation flags:
# _ = kw.get('extra_compile_args', [])[:]
# https://bugs.python.org/issue21121 _[0:0] = ccdefault
# kw['extra_compile_args'] = _
# ensure there is no warnings / errors for decl-after-statements.
'-Wno-declaration-after-statement', lddefault = []
'-Wno-error=declaration-after-statement', # python extensions cannot be built with -Wl,--no-undefined: at runtime
], # they link with either python (without libpython) or libpython. linking
# with both libpython and python would be wrong.
# can't - at runtime links with either python (without libpython) or libpython if 0:
# linking with both libpython and python would be wrong lddefault.append('-Wl,--no-undefined') # check DSO for undefined symbols at link time
#extra_link_args = [
# '-Wl,--no-undefined', # check DSO for undefined symbols at link time _ = kw.get('extra_link_args', [])[:]
#] _[0:0] = lddefault
) kw['extra_link_args'] = _
return what(*argv, **kw)
def Ext(*argv, **kw): return _with_defaults(_Ext, *argv, **kw)
# build_py that # build_py that
...@@ -239,7 +244,19 @@ setup( ...@@ -239,7 +244,19 @@ setup(
keywords = 'bigdata out-of-core numpy virtual-memory', keywords = 'bigdata out-of-core numpy virtual-memory',
ext_modules = [_bigfile], ext_modules = [
Ext('wendelin.bigfile._bigfile',
['bigfile/_bigfile.c',
'bigfile/pagefault.c',
'bigfile/pagemap.c',
'bigfile/ram.c',
'bigfile/ram_shmfs.c',
'bigfile/ram_hugetlbfs.c',
'bigfile/virtmem.c',
'lib/bug.c',
'lib/utils.c'],
define_macros = [('_GNU_SOURCE',None)]),
],
package_dir = {'wendelin': ''}, package_dir = {'wendelin': ''},
packages = ['wendelin'] + ['wendelin.%s' % _ for _ in packages = ['wendelin'] + ['wendelin.%s' % _ for _ in
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment