Commit b5bd136c authored by Kirill Smelkov's avatar Kirill Smelkov

setup: Reuse golang.pyx.build to build DSOs

We already reuse golang.pyx.build in setup.py to build Extensions, but
DSOs were built via setuptools_dso directly so far. To support Windows
we will soon need to adjust compilation flags for both Extensions and
DSOs. It makes sense to first concentrate build recipes in one place
before doing that.

-> Move/factor DSOs build flags into golang.pyx.build and reuse that
from setup.
parent 0ffef2d8
# Copyright (C) 2019-2022 Nexedi SA and Contributors. # Copyright (C) 2019-2023 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com> # Kirill Smelkov <kirr@nexedi.com>
# #
# This program is free software: you can Use, Study, Modify and Redistribute # This program is free software: you can Use, Study, Modify and Redistribute
...@@ -128,14 +128,14 @@ def setup(**kw): ...@@ -128,14 +128,14 @@ def setup(**kw):
# x_dsos = [DSO('mypkg.mydso', ['mypkg/mydso.cpp'])], # x_dsos = [DSO('mypkg.mydso', ['mypkg/mydso.cpp'])],
# ) # )
def DSO(name, sources, **kw): def DSO(name, sources, **kw):
_, kw = _with_build_defaults(kw) _, kw = _with_build_defaults(name, kw)
dso = setuptools_dso.DSO(name, sources, **kw) dso = setuptools_dso.DSO(name, sources, **kw)
return dso return dso
# _with_build_defaults returns copy of kw amended with build options common for # _with_build_defaults returns copy of kw amended with build options common for
# both DSO and Extension. # both DSO and Extension.
def _with_build_defaults(kw): # -> (pygo, kw') def _with_build_defaults(name, kw): # -> (pygo, kw')
# find pygolang root # find pygolang root
gopkg = _findpkg("golang") gopkg = _findpkg("golang")
pygo = dirname(gopkg.path) # .../pygolang/golang -> .../pygolang pygo = dirname(gopkg.path) # .../pygolang/golang -> .../pygolang
...@@ -149,10 +149,11 @@ def _with_build_defaults(kw): # -> (pygo, kw') ...@@ -149,10 +149,11 @@ def _with_build_defaults(kw): # -> (pygo, kw')
incv.insert(0, pygo) incv.insert(0, pygo)
kw['include_dirs'] = incv kw['include_dirs'] = incv
# link with libgolang.so # link with libgolang.so if it is not libgolang itself
dsov = kw.get('dsos', [])[:] if name != 'golang.runtime.libgolang':
dsov.insert(0, 'golang.runtime.libgolang') dsov = kw.get('dsos', [])[:]
kw['dsos'] = dsov dsov.insert(0, 'golang.runtime.libgolang')
kw['dsos'] = dsov
# default language to C++ (chan[T] & co are accessible only via C++) # default language to C++ (chan[T] & co are accessible only via C++)
lang = kw.setdefault('language', 'c++') lang = kw.setdefault('language', 'c++')
...@@ -160,7 +161,11 @@ def _with_build_defaults(kw): # -> (pygo, kw') ...@@ -160,7 +161,11 @@ def _with_build_defaults(kw): # -> (pygo, kw')
# default to C++11 (chan[T] & co require C++11 features) # default to C++11 (chan[T] & co require C++11 features)
ccdefault = [] ccdefault = []
if lang == 'c++': if lang == 'c++':
ccdefault.append('-std=c++11') if name == 'golang.runtime.libgolang':
ccdefault.append('-std=gnu++11') # not c++11 as linux/list.h uses typeof
else:
ccdefault.append('-std=c++11')
# default to no strict-aliasing # default to no strict-aliasing
ccdefault.append('-fno-strict-aliasing') ccdefault.append('-fno-strict-aliasing')
...@@ -203,7 +208,7 @@ def _with_build_defaults(kw): # -> (pygo, kw') ...@@ -203,7 +208,7 @@ def _with_build_defaults(kw): # -> (pygo, kw')
# ext_modules = [Extension('mypkg.mymod', ['mypkg/mymod.pyx'])], # ext_modules = [Extension('mypkg.mymod', ['mypkg/mymod.pyx'])],
# ) # )
def Extension(name, sources, **kw): def Extension(name, sources, **kw):
pygo, kw = _with_build_defaults(kw) pygo, kw = _with_build_defaults(name, kw)
# some pyx-level depends to workaround a bit lack of proper dependency # some pyx-level depends to workaround a bit lack of proper dependency
# tracking in setuptools/distutils. # tracking in setuptools/distutils.
......
...@@ -19,10 +19,6 @@ ...@@ -19,10 +19,6 @@
# See https://www.nexedi.com/licensing for rationale and options. # See https://www.nexedi.com/licensing for rationale and options.
from setuptools import find_packages from setuptools import find_packages
# setuptools has Library but this days it is not well supported and test for it
# has been killed https://github.com/pypa/setuptools/commit/654c26f78a30
# -> use setuptools_dso instead.
from setuptools_dso import DSO
from setuptools.command.install_scripts import install_scripts as _install_scripts from setuptools.command.install_scripts import install_scripts as _install_scripts
from setuptools.command.develop import develop as _develop from setuptools.command.develop import develop as _develop
from distutils import sysconfig from distutils import sysconfig
...@@ -34,13 +30,13 @@ def readfile(path): ...@@ -34,13 +30,13 @@ def readfile(path):
with open(path, 'r') as f: with open(path, 'r') as f:
return f.read() return f.read()
# reuse golang.pyx.build to build pygolang extensions. # reuse golang.pyx.build to build pygolang dso and extensions.
# we have to be careful and inject synthetic golang package in order to be # we have to be careful and inject synthetic golang package in order to be
# able to import golang.pyx.build without built/working golang. # able to import golang.pyx.build without built/working golang.
trun = {} trun = {}
exec(readfile('trun'), trun) exec(readfile('trun'), trun)
trun['ximport_empty_golangmod']() trun['ximport_empty_golangmod']()
from golang.pyx.build import setup, Extension as Ext from golang.pyx.build import setup, DSO, Extension as Ext
# grep searches text for pattern. # grep searches text for pattern.
...@@ -223,19 +219,16 @@ setup( ...@@ -223,19 +219,16 @@ setup(
'golang/strings.h', 'golang/strings.h',
'golang/sync.h', 'golang/sync.h',
'golang/time.h'], 'golang/time.h'],
include_dirs = ['.', '3rdparty/include'], include_dirs = ['3rdparty/include'],
define_macros = [('BUILDING_LIBGOLANG', None)], define_macros = [('BUILDING_LIBGOLANG', None)],
extra_compile_args = ['-std=gnu++11'], # not c++11 as linux/list.h uses typeof
soversion = '0.1'), soversion = '0.1'),
DSO('golang.runtime.libpyxruntime', DSO('golang.runtime.libpyxruntime',
['golang/runtime/libpyxruntime.cpp'], ['golang/runtime/libpyxruntime.cpp'],
depends = ['golang/pyx/runtime.h'], depends = ['golang/pyx/runtime.h'],
include_dirs = ['.', sysconfig.get_python_inc()], include_dirs = [sysconfig.get_python_inc()],
define_macros = [('BUILDING_LIBPYXRUNTIME', None)], define_macros = [('BUILDING_LIBPYXRUNTIME', None)],
extra_compile_args = ['-std=c++11'], soversion = '0.1')],
soversion = '0.1',
dsos = ['golang.runtime.libgolang'])],
ext_modules = [ ext_modules = [
Ext('golang._golang', Ext('golang._golang',
......
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