Commit 64765688 authored by Kirill Smelkov's avatar Kirill Smelkov

pyx.build: Provide DSO that should be used to build DSOs that use/link-to libgolang

Providing pygolang-specific DSO is needed because using just
setuptools_dso.DSO in external project will result in that e.g.
"<golang/libgolang.h>" won't be found.
parent c5c3071b
......@@ -4,6 +4,7 @@ include golang/runtime/libgolang.cpp
include golang/runtime/libpyxruntime.cpp
include golang/pyx/runtime.h
include golang/pyx/runtime.cpp
include golang/pyx/testprog/golang_dso_user/dsouser/dso.cpp
include golang/context.h
include golang/context.cpp
include golang/cxx.h
......
......@@ -119,15 +119,23 @@ def setup(**kw):
finally:
setuptools_dso.build_ext = _
# Extension should be used to build extensions that use pygolang.
# DSO should be used to build DSOs that use libgolang.
#
# For example:
#
# setup(
# ...
# ext_modules = [Extension('mypkg.mymod', ['mypkg/mymod.pyx'])],
# x_dsos = [DSO('mypkg.mydso', ['mypkg/mydso.cpp'])],
# )
def Extension(name, sources, **kw):
def DSO(name, sources, **kw):
_, kw = _with_build_defaults(kw)
dso = setuptools_dso.DSO(name, sources, **kw)
return dso
# _with_build_defaults returns copy of kw amended with build options common for
# both DSO and Extension.
def _with_build_defaults(kw): # -> (pygo, kw')
# find pygolang root
gopkg = _findpkg("golang")
pygo = dirname(gopkg.path) # .../pygolang/golang -> .../pygolang
......@@ -160,31 +168,50 @@ def Extension(name, sources, **kw):
_[0:0] = ccdefault # if another e.g. -std=... was already there -
kw['extra_compile_args'] = _ # - it will override us
# some depends to workaround a bit lack of proper dependency tracking in
# setuptools/distutils.
# some C-level depends to workaround a bit lack of proper dependency
# tracking in setuptools/distutils.
dependv = kw.get('depends', [])[:]
dependv.append('%s/golang/libgolang.h' % pygo)
dependv.append('%s/golang/context.h' % pygo)
dependv.append('%s/golang/cxx.h' % pygo)
dependv.append('%s/golang/errors.h' % pygo)
dependv.append('%s/golang/fmt.h' % pygo)
dependv.append('%s/golang/strings.h' % pygo)
dependv.append('%s/golang/sync.h' % pygo)
dependv.append('%s/golang/time.h' % pygo)
dependv.append('%s/golang/pyx/runtime.h' % pygo)
kw['depends'] = dependv
return pygo, kw
# Extension should be used to build extensions that use pygolang.
#
# For example:
#
# setup(
# ...
# ext_modules = [Extension('mypkg.mymod', ['mypkg/mymod.pyx'])],
# )
def Extension(name, sources, **kw):
pygo, kw = _with_build_defaults(kw)
# some pyx-level depends to workaround a bit lack of proper dependency
# tracking in setuptools/distutils.
dependv = kw.get('depends', [])[:]
dependv.append('%s/golang/_golang.pxd' % pygo)
dependv.append('%s/golang/__init__.pxd' % pygo)
dependv.append('%s/golang/context.h' % pygo)
dependv.append('%s/golang/context.pxd' % pygo)
dependv.append('%s/golang/_context.pxd' % pygo)
dependv.append('%s/golang/cxx.h' % pygo)
dependv.append('%s/golang/cxx.pxd' % pygo)
dependv.append('%s/golang/errors.h' % pygo)
dependv.append('%s/golang/errors.pxd' % pygo)
dependv.append('%s/golang/_errors.pxd' % pygo)
dependv.append('%s/golang/fmt.h' % pygo)
dependv.append('%s/golang/fmt.pxd' % pygo)
dependv.append('%s/golang/strings.h' % pygo)
dependv.append('%s/golang/strings.pxd' % pygo)
dependv.append('%s/golang/sync.h' % pygo)
dependv.append('%s/golang/sync.pxd' % pygo)
dependv.append('%s/golang/_sync.pxd' % pygo)
dependv.append('%s/golang/time.h' % pygo)
dependv.append('%s/golang/time.pxd' % pygo)
dependv.append('%s/golang/_time.pxd' % pygo)
dependv.append('%s/golang/pyx/runtime.h' % pygo)
dependv.append('%s/golang/pyx/runtime.pxd' % pygo)
kw['depends'] = dependv
......
......@@ -41,6 +41,20 @@ def test_pyx_build():
assert _ == b"test.pyx: OK\n"
# verify that we can build/run external dso that uses libgolang.
def test_dso_build():
dsouser = testprog + "/golang_dso_user"
pyrun(["setup.py", "build_dso", "-i"], cwd=dsouser)
pyrun(["setup.py", "build_ext", "-i"], cwd=dsouser)
# run built test.
_ = pyout(["-c",
# XXX `import golang` is a hack - see test_pyx_build for details.
"import golang;" +
"from dsouser import test; test.main()"], cwd=dsouser)
assert _ == b"dso.cpp: OK\n"
# verify that custom classes can be used via cmdclass
def test_pyx_build_cmdclass():
_ = pyout(["cmdclass_custom.py", "build_ext"], cwd=testprog)
......
// Copyright (C) 2019 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Free Software licenses or any of the Open Source
// Initiative approved licenses and Convey the resulting work. Corresponding
// source of such a combination shall include the source code for all other
// software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
// Small library that uses a bit of libgolang features, mainly to verify
// that external project can build against libgolang.
#include <golang/libgolang.h>
using namespace golang;
#include <stdio.h>
void dsotest() {
chan<int> ch = makechan<int>();
ch.close();
printf("dso.cpp: OK\n");
}
# cython: language_level=2
#
# Copyright (C) 2019 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# You can also Link and Combine this program with other software covered by
# the terms of any of the Free Software licenses or any of the Open Source
# Initiative approved licenses and Convey the resulting work. Corresponding
# source of such a combination shall include the source code for all other
# software used.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
# Small test driver that calls dso.so .
cdef extern from * nogil:
"""
void dsotest();
"""
void dsotest()
def main():
dsotest()
[build-system]
requires = ["pygolang[pyx.build]"]
# Copyright (C) 2019 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# You can also Link and Combine this program with other software covered by
# the terms of any of the Free Software licenses or any of the Open Source
# Initiative approved licenses and Convey the resulting work. Corresponding
# source of such a combination shall include the source code for all other
# software used.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
# See https://www.nexedi.com/licensing for rationale and options.
"""Demo package that links to and uses libgolang from a DSO."""
from golang.pyx.build import setup, DSO, Extension
setup(
name = 'golang_dso_user',
description = 'test project that uses libgolang from a dso',
x_dsos = [DSO('dsouser.dso', ['dsouser/dso.cpp'])],
ext_modules = [Extension('dsouser.test',
['dsouser/test.pyx'],
dsos = ['dsouser.dso'])],
)
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