-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TST: add test package with internal shared library, installed in site…
…-packages
- Loading branch information
Showing
8 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# SPDX-FileCopyrightText: 2022 The meson-python developers | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
project('sharedlib-in-package', 'c', version: '1.0.0') | ||
|
||
py = import('python').find_installation(pure: false) | ||
|
||
subdir('mypkg') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# SPDX-FileCopyrightText: 2024 The meson-python developers | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
def _load_sharedlib(): | ||
"""Load the `example_lib.dll` shared library on Windows | ||
This shared library is installed alongside this __init__.py file. Due to | ||
lack of rpath support, Windows cannot find shared libraries installed | ||
within wheels. So pre-load it. | ||
""" | ||
if os.name == "nt": | ||
from ctypes import WinDLL | ||
basedir = os.path.dirname(__file__) | ||
dll_path = os.path.join(basedir, "example_lib.dll") | ||
WinDLL(dll_path) | ||
|
||
|
||
_load_sharedlib() | ||
|
||
|
||
from ._example import example_sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// SPDX-FileCopyrightText: 2022 The meson-python developers | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
#include <Python.h> | ||
|
||
#include "examplelib.h" | ||
|
||
static PyObject* example_sum(PyObject* self, PyObject *args) | ||
{ | ||
int a, b; | ||
if (!PyArg_ParseTuple(args, "ii", &a, &b)) { | ||
return NULL; | ||
} | ||
|
||
long result = sum(a, b); | ||
|
||
return PyLong_FromLong(result); | ||
} | ||
|
||
static PyMethodDef methods[] = { | ||
{"example_sum", (PyCFunction)example_sum, METH_VARARGS, NULL}, | ||
{NULL, NULL, 0, NULL}, | ||
}; | ||
|
||
static struct PyModuleDef module = { | ||
PyModuleDef_HEAD_INIT, | ||
"_example", | ||
NULL, | ||
-1, | ||
methods, | ||
}; | ||
|
||
PyMODINIT_FUNC PyInit__example(void) | ||
{ | ||
return PyModule_Create(&module); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// SPDX-FileCopyrightText: 2022 The meson-python developers | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
int sum(int a, int b) { | ||
return a + b; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// SPDX-FileCopyrightText: 2022 The meson-python developers | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
int sum(int a, int b); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# SPDX-FileCopyrightText: 2022 The meson-python developers | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
example_lib = shared_library( | ||
'examplelib', | ||
'examplelib.c', | ||
install: true, | ||
install_dir: py.get_install_dir() / 'mypkg', | ||
) | ||
|
||
py.extension_module( | ||
'_example', | ||
'_examplemod.c', | ||
link_with: example_lib, | ||
install: true, | ||
subdir: 'mypkg', | ||
install_rpath: '$ORIGIN', | ||
) | ||
|
||
py.install_sources( | ||
['__init__.py'], | ||
subdir: 'mypkg', | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# SPDX-FileCopyrightText: 2022 The meson-python developers | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
[build-system] | ||
build-backend = 'mesonpy' | ||
requires = ['meson-python'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters