Merge pull request #787 from mesonbuild/py3module
Created a Python 3 module for simpler building of Python extension mo…pull/1295/merge
commit
34caf6471c
18 changed files with 140 additions and 62 deletions
@ -0,0 +1,49 @@ |
||||
# Copyright 2016-2017 The Meson development team |
||||
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
# you may not use this file except in compliance with the License. |
||||
# You may obtain a copy of the License at |
||||
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
||||
# Unless required by applicable law or agreed to in writing, software |
||||
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
# See the License for the specific language governing permissions and |
||||
# limitations under the License. |
||||
|
||||
import sys |
||||
from .. import mesonlib, dependencies |
||||
|
||||
from . import ExtensionModule |
||||
from mesonbuild.modules import ModuleReturnValue |
||||
|
||||
class Python3Module(ExtensionModule): |
||||
def __init__(self): |
||||
super().__init__() |
||||
self.snippets.add('extension_module') |
||||
|
||||
def extension_module(self, interpreter, state, args, kwargs): |
||||
if 'name_prefix' in kwargs: |
||||
raise mesonlib.MesonException('Name_prefix is set automatically, specifying it is forbidden.') |
||||
if 'name_suffix' in kwargs: |
||||
raise mesonlib.MesonException('Name_suffix is set automatically, specifying it is forbidden.') |
||||
host_system = state.host_machine.system |
||||
if host_system == 'darwin': |
||||
# Default suffix is 'dylib' but Python does not use it for extensions. |
||||
suffix = 'so' |
||||
elif host_system == 'windows': |
||||
# On Windows the extension is pyd for some unexplainable reason. |
||||
suffix = 'pyd' |
||||
else: |
||||
suffix = [] |
||||
kwargs['name_prefix'] = '' |
||||
kwargs['name_suffix'] = suffix |
||||
return interpreter.func_shared_module(None, args, kwargs) |
||||
|
||||
def find_python(self, state, args, kwargs): |
||||
py3 = dependencies.ExternalProgram('python3', sys.executable, silent=True) |
||||
return ModuleReturnValue(py3, [py3]) |
||||
|
||||
def initialize(): |
||||
return Python3Module() |
@ -1,5 +1,4 @@ |
||||
submain = find_program('subprog.py') |
||||
|
||||
test('subdir', |
||||
submain, |
||||
py3, |
||||
args : files('subprog.py'), |
||||
env : 'PYTHONPATH=' + meson.source_root()) |
||||
|
@ -1,17 +1,6 @@ |
||||
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 |
||||
|
||||
pylib = shared_library('tachyon', |
||||
pylib = py3_mod.extension_module('tachyon', |
||||
'tachyon_module.c', |
||||
dependencies : py3_dep, |
||||
name_prefix : '', |
||||
name_suffix : suffix) |
||||
) |
||||
|
||||
pypathdir = meson.current_build_dir() |
||||
|
@ -1,23 +1,11 @@ |
||||
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', |
||||
command : [cython, '@INPUT@', '-o', '@OUTPUT@'], |
||||
) |
||||
|
||||
slib = shared_library('storer', |
||||
slib = py3_mod.extension_module('storer', |
||||
'storer.c', pyx_c, |
||||
name_prefix : '', |
||||
name_suffix : suffix, |
||||
dependencies : py3_dep) |
||||
|
||||
pydir = meson.current_build_dir() |
||||
|
Loading…
Reference in new issue