Skip to content

Commit 3eac822

Browse files
committed
TST: extend local lib test to verify Windows support
1 parent 900b5cf commit 3eac822

File tree

8 files changed

+59
-9
lines changed

8 files changed

+59
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# SPDX-FileCopyrightText: 2025 The meson-python developers
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import os
6+
import sys
7+
8+
9+
_path = os.path.join(os.path.dirname(__file__), '..', '.link_against_local_lib.mesonpy.libs')
10+
if os.name == 'nt':
11+
os.add_dll_directory(_path)
12+
elif sys.platform == 'cygwin':
13+
os.environ['PATH'] = os.pathsep.join((os.environ['PATH'], _path))
14+
del _path
15+
16+
17+
from ._example import example_sum # noqa: E402
18+
19+
20+
__all__ = ['example_sum']

tests/packages/link-against-local-lib/examplemod.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ static PyMethodDef methods[] = {
2525

2626
static struct PyModuleDef module = {
2727
PyModuleDef_HEAD_INIT,
28-
"example",
28+
"_example",
2929
NULL,
3030
-1,
3131
methods,
3232
};
3333

34-
PyMODINIT_FUNC PyInit_example(void)
34+
PyMODINIT_FUNC PyInit__example(void)
3535
{
3636
return PyModule_Create(&module);
3737
}

tests/packages/link-against-local-lib/lib/examplelib.c

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
//
33
// SPDX-License-Identifier: MIT
44

5+
#include "examplelib.h"
6+
57
int sum(int a, int b) {
68
return a + b;
79
}

tests/packages/link-against-local-lib/lib/examplelib.h

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,15 @@
22
//
33
// SPDX-License-Identifier: MIT
44

5-
int sum(int a, int b);
5+
#pragma once
6+
7+
#if defined(EXAMPLE_DLL_EXPORTS)
8+
#define EXAMPLE_DLL __declspec(dllexport)
9+
#elif defined(BAR_DLL_IMPORTS)
10+
#define EXAMPLE_DLL __declspec(dllimport)
11+
#else
12+
#define EXAMPLE_DLL
13+
#endif
14+
15+
16+
EXAMPLE_DLL int sum(int a, int b);

tests/packages/link-against-local-lib/lib/meson.build

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
example_lib = shared_library(
66
'example',
77
'examplelib.c',
8+
c_args: lib_compile_args,
89
install: true,
910
)

tests/packages/link-against-local-lib/meson.build

+17-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,28 @@
44

55
project('link-against-local-lib', 'c', version: '1.0.0')
66

7+
if meson.get_compiler('c').get_id() in ['msvc', 'clang-cl', 'intel-cl']
8+
lib_compile_args = ['-DEXAMPLE_DLL_EXPORTS']
9+
link_args = ['-DEXAMPLE_DLL_IMPORTS']
10+
else
11+
lib_compile_args = []
12+
link_args = ['-Wl,-rpath,custom-rpath']
13+
endif
14+
715
subdir('lib')
816

9-
py = import('python').find_installation()
17+
py = import('python').find_installation(pure: false)
18+
19+
py.install_sources(
20+
'__init__.py',
21+
subdir: 'example',
22+
)
1023

1124
py.extension_module(
12-
'example',
25+
'_example',
1326
'examplemod.c',
1427
link_with: example_lib,
15-
link_args: ['-Wl,-rpath,custom-rpath'],
28+
link_args: link_args,
1629
install: true,
30+
subdir: 'example',
1731
)

tests/packages/link-against-local-lib/pyproject.toml

+3
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
[build-system]
66
build-backend = 'mesonpy'
77
requires = ['meson-python']
8+
9+
[tool.meson-python]
10+
allow-windows-internal-shared-libs = true

tests/test_wheel.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ def test_contents(package_library, wheel_library):
172172
}
173173

174174

175-
@pytest.mark.skipif(sys.platform not in {'linux', 'darwin', 'sunos5'}, reason='Not supported on this platform')
176175
def test_local_lib(venv, wheel_link_against_local_lib):
177176
venv.pip('install', wheel_link_against_local_lib)
178177
output = venv.python('-c', 'import example; print(example.example_sum(1, 2))')
@@ -200,9 +199,9 @@ def test_rpath(wheel_link_against_local_lib, tmp_path):
200199
artifact.extractall(tmp_path)
201200

202201
origin = {'linux': '$ORIGIN', 'darwin': '@loader_path', 'sunos5': '$ORIGIN'}[sys.platform]
203-
expected = {f'{origin}/.link_against_local_lib.mesonpy.libs', 'custom-rpath',}
202+
expected = {f'{origin}/../.link_against_local_lib.mesonpy.libs', 'custom-rpath',}
204203

205-
rpath = set(mesonpy._rpath._get_rpath(tmp_path / f'example{EXT_SUFFIX}'))
204+
rpath = set(mesonpy._rpath._get_rpath(tmp_path / 'example' / f'_example{EXT_SUFFIX}'))
206205
# Verify that rpath is a superset of the expected one: linking to
207206
# the Python runtime may require additional rpath entries.
208207
assert rpath >= expected

0 commit comments

Comments
 (0)