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,26 +28,18 @@ import os ...@@ -28,26 +28,18 @@ 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',
'bigfile/ram_hugetlbfs.c',
'bigfile/virtmem.c',
'lib/bug.c',
'lib/utils.c',
],
include_dirs = [
'.', '.',
'./include', './include',
'./3rdparty/ccan', './3rdparty/ccan',
'./3rdparty/include' './3rdparty/include',
], ]
define_macros = [('_GNU_SOURCE',None)],
extra_compile_args = [ ccdefault = [
'-std=gnu99', # declarations inside for-loop '-std=gnu99', # declarations inside for-loop
'-fplan9-extensions', # anonymous-structs + simple inheritance '-fplan9-extensions', # anonymous-structs + simple inheritance
'-fvisibility=hidden', # by default symbols not visible outside DSO '-fvisibility=hidden', # by default symbols not visible outside DSO
...@@ -61,14 +53,27 @@ _bigfile = Extension('wendelin.bigfile._bigfile', ...@@ -61,14 +53,27 @@ _bigfile = Extension('wendelin.bigfile._bigfile',
# ensure there is no warnings / errors for decl-after-statements. # ensure there is no warnings / errors for decl-after-statements.
'-Wno-declaration-after-statement', '-Wno-declaration-after-statement',
'-Wno-error=declaration-after-statement', '-Wno-error=declaration-after-statement',
], ]
# can't - at runtime links with either python (without libpython) or libpython _ = kw.get('extra_compile_args', [])[:]
# linking with both libpython and python would be wrong _[0:0] = ccdefault
#extra_link_args = [ kw['extra_compile_args'] = _
# '-Wl,--no-undefined', # check DSO for undefined symbols at link time
#] lddefault = []
) # 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.
if 0:
lddefault.append('-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