From 98d00386b141771a62668198f36bd38b1a9e6112 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Fri, 12 Feb 2016 21:57:31 +0200 Subject: Can build a Python extension module. --- test cases/python3/2 extmodule/ext/meson.build | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 test cases/python3/2 extmodule/ext/meson.build (limited to 'test cases/python3/2 extmodule/ext/meson.build') diff --git a/test cases/python3/2 extmodule/ext/meson.build b/test cases/python3/2 extmodule/ext/meson.build new file mode 100644 index 000000000..1184835d8 --- /dev/null +++ b/test cases/python3/2 extmodule/ext/meson.build @@ -0,0 +1,6 @@ +pylib = shared_library('tachyon', + 'tachyon_module.c', + dependencies : py3_dep, + name_prefix : '') + +pypathdir = meson.current_build_dir() -- cgit v1.2.3 From a04c33e12527d3ed7a07dce0380afabb46cf4f3d Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sun, 21 Feb 2016 17:12:09 +0200 Subject: Can build Python extension on OSX. --- mesonbuild/build.py | 25 ++++++++++++++++++++----- mesonbuild/dependencies.py | 9 +++++++++ test cases/python3/2 extmodule/ext/meson.build | 10 +++++++++- 3 files changed, 38 insertions(+), 6 deletions(-) (limited to 'test cases/python3/2 extmodule/ext/meson.build') diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 7b4f3c9ab..31f12b142 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -46,6 +46,7 @@ known_shlib_kwargs = known_basic_kwargs.copy() known_shlib_kwargs.update({'version' : True, 'soversion' : True, 'name_prefix' : True, + 'name_suffix' : True, }) backslash_explanation = \ @@ -415,9 +416,20 @@ class BuildTarget(): self.resources = resources if 'name_prefix' in kwargs: name_prefix = kwargs['name_prefix'] - if not isinstance(name_prefix, str): + if isinstance(name_prefix, list): + if len(name_prefix) != 0: + raise InvalidArguments('Array must be empty to signify null.') + elif not isinstance(name_prefix, str): raise InvalidArguments('Name prefix must be a string.') self.prefix = name_prefix + if 'name_suffix' in kwargs: + name_suffix = kwargs['name_suffix'] + if isinstance(name_suffix, list): + if len(name_suffix) != 0: + raise InvalidArguments('Array must be empty to signify null.') + elif not isinstance(name_suffix, str): + raise InvalidArguments('Name suffix must be a string.') + self.suffix = name_suffix def get_subdir(self): return self.subdir @@ -684,14 +696,17 @@ class SharedLibrary(BuildTarget): super().__init__(name, subdir, subproject, is_cross, sources, objects, environment, kwargs); if len(self.sources) > 0 and self.sources[0].endswith('.cs'): prefix = 'lib' - self.suffix = 'dll' + suffix = 'dll' else: prefix = environment.get_shared_lib_prefix() - self.suffix = environment.get_shared_lib_suffix() + suffix = environment.get_shared_lib_suffix() if not hasattr(self, 'prefix'): self.prefix = prefix - if len(self.sources) > 0 and self.sources[0].endswith('.rs'): - self.suffix = 'rlib' + if not hasattr(self, 'suffix'): + if len(self.sources) > 0 and self.sources[0].endswith('.rs'): + self.suffix = 'rlib' + else: + self.suffix = suffix self.importsuffix = environment.get_import_lib_suffix() self.filename = self.prefix + self.name + '.' + self.suffix diff --git a/mesonbuild/dependencies.py b/mesonbuild/dependencies.py index 6171c41ed..ca5fa8984 100644 --- a/mesonbuild/dependencies.py +++ b/mesonbuild/dependencies.py @@ -1077,6 +1077,7 @@ class ThreadDependency(Dependency): class Python3Dependency(Dependency): def __init__(self, environment, kwargs): super().__init__() + self.name = 'python3' self.is_found = False try: pkgdep = PkgConfigDependency('python3', environment, kwargs) @@ -1100,6 +1101,14 @@ class Python3Dependency(Dependency): self.libs = ['-L{}/libs'.format(basedir), '-lpython{}'.format(vernum)] self.is_found = True + elif mesonlib.is_osx(): + # In OSX the Python 3 framework does not have a version + # number in its name. + fw = ExtraFrameworkDependency('python', False) + if fw.found(): + self.cargs = fw.get_compile_args() + self.libs = fw.get_link_args() + self.is_found = True if self.is_found: mlog.log('Dependency', mlog.bold(self.name), 'found:', mlog.green('YES')) else: diff --git a/test cases/python3/2 extmodule/ext/meson.build b/test cases/python3/2 extmodule/ext/meson.build index 1184835d8..04c0592c2 100644 --- a/test cases/python3/2 extmodule/ext/meson.build +++ b/test cases/python3/2 extmodule/ext/meson.build @@ -1,6 +1,14 @@ +if host_machine.system() == 'darwin' + # Default suffix is 'dylib' but Python does not use for extensions. + suffix = 'so' +else + suffix = [] +endif + pylib = shared_library('tachyon', 'tachyon_module.c', dependencies : py3_dep, - name_prefix : '') + name_prefix : '', + name_suffix : suffix) pypathdir = meson.current_build_dir() -- cgit v1.2.3 From efceac497fa2702124398b2712761015d9a1c78a Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Fri, 26 Feb 2016 21:04:11 +0200 Subject: Python extension module finally works on Windows. --- test cases/python3/2 extmodule/ext/meson.build | 3 +++ test cases/python3/2 extmodule/meson.build | 5 ++++- test cases/python3/3 cython/libdir/meson.build | 11 +++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) (limited to 'test cases/python3/2 extmodule/ext/meson.build') diff --git a/test cases/python3/2 extmodule/ext/meson.build b/test cases/python3/2 extmodule/ext/meson.build index 04c0592c2..7d67953cb 100644 --- a/test cases/python3/2 extmodule/ext/meson.build +++ b/test cases/python3/2 extmodule/ext/meson.build @@ -1,6 +1,9 @@ if host_machine.system() == 'darwin' # Default suffix is 'dylib' but Python does not use for extensions. suffix = 'so' +elif host_machine.system() == 'windows' + # On Windows the extension is pyd for some unexplainable reason. + suffix = 'pyd' else suffix = [] endif diff --git a/test cases/python3/2 extmodule/meson.build b/test cases/python3/2 extmodule/meson.build index a86a1222c..858bbea9f 100644 --- a/test cases/python3/2 extmodule/meson.build +++ b/test cases/python3/2 extmodule/meson.build @@ -1,4 +1,7 @@ -project('Python extension module', 'c') +project('Python extension module', 'c', + default_options : ['buildtype=release']) +# Because Windows Python ships only with optimized libs, +# we must build this project the same way. py3_dep = dependency('python3') diff --git a/test cases/python3/3 cython/libdir/meson.build b/test cases/python3/3 cython/libdir/meson.build index baa4c1dbf..5c0352e88 100644 --- a/test cases/python3/3 cython/libdir/meson.build +++ b/test cases/python3/3 cython/libdir/meson.build @@ -1,3 +1,13 @@ +if host_machine.system() == 'darwin' + # Default suffix is 'dylib' but Python does not use for extensions. + suffix = 'so' +elif host_machine.system() == 'windows' + # On Windows the extension is pyd for some unexplainable reason. + suffix = 'pyd' +else + suffix = [] +endif + pyx_c = custom_target('storer_pyx', output : 'storer_pyx.c', input : 'storer.pyx', @@ -7,6 +17,7 @@ pyx_c = custom_target('storer_pyx', slib = shared_library('storer', 'storer.c', pyx_c, name_prefix : '', + name_suffix : suffix, dependencies : py3_dep) pydir = meson.current_build_dir() -- cgit v1.2.3