-
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 package linking a library from a subproject
Note that for Meson versions older than 1.2.0, CI failed with: ``` mesonpy.BuildError: Could not map installation path to an equivalent wheel directory: '{libdir_static}/libexamplelib.a' ``` because the `--skip-subprojects` install option isn't honored. Hence the test skip on older versions. In addition, the `c_shared_libs` usage requires Meson 1.3.0
- Loading branch information
Showing
10 changed files
with
167 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,8 @@ | ||
# SPDX-FileCopyrightText: 2024 The meson-python developers | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
from ._example import example_sum | ||
|
||
|
||
__all__ = ['example_sum'] |
37 changes: 37 additions & 0 deletions
37
tests/packages/link-library-in-subproject/foo/_examplemod.c
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,16 @@ | ||
# SPDX-FileCopyrightText: 2022 The meson-python developers | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
py.extension_module( | ||
'_example', | ||
'_examplemod.c', | ||
dependencies: bar_dep, | ||
install: true, | ||
subdir: 'foo', | ||
) | ||
|
||
py.install_sources( | ||
['__init__.py'], | ||
subdir: 'foo', | ||
) |
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,17 @@ | ||
# SPDX-FileCopyrightText: 2022 The meson-python developers | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
project( | ||
'link-library-in-subproject', | ||
'c', | ||
version: '1.0.0', | ||
meson_version: '>=1.2.0', | ||
) | ||
|
||
py = import('python').find_installation(pure: false) | ||
|
||
bar_proj = subproject('bar') | ||
bar_dep = bar_proj.get_variable('bar_dep') | ||
|
||
subdir('foo') |
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,15 @@ | ||
# SPDX-FileCopyrightText: 2022 The meson-python developers | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
[build-system] | ||
build-backend = 'mesonpy' | ||
requires = ['meson-python'] | ||
|
||
[project] | ||
name = 'link-library-in-subproject' | ||
version = '1.2.3' | ||
|
||
[tool.meson-python.args] | ||
setup = ['--default-library=static'] | ||
install = ['--skip-subprojects'] |
15 changes: 15 additions & 0 deletions
15
tests/packages/link-library-in-subproject/subprojects/bar/bar_dll.h
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,15 @@ | ||
#pragma once | ||
|
||
// When building the `examplelib` DLL, this macro expands to `__declspec(dllexport)` | ||
// so we can annotate symbols appropriately as being exported. When used in | ||
// headers consuming a DLL, this macro expands to `__declspec(dllimport)` so | ||
// that consumers know the symbol is defined inside the DLL. In all other cases, | ||
// the macro expands to nothing. | ||
// Note: BAR_DLL_{EX,IM}PORTS are set in meson.build | ||
#if defined(BAR_DLL_EXPORTS) | ||
#define BAR_DLL __declspec(dllexport) | ||
#elif defined(BAR_DLL_IMPORTS) | ||
#define BAR_DLL __declspec(dllimport) | ||
#else | ||
#define BAR_DLL | ||
#endif |
9 changes: 9 additions & 0 deletions
9
tests/packages/link-library-in-subproject/subprojects/bar/examplelib.c
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 | ||
|
||
#include "bar_dll.h" | ||
|
||
BAR_DLL int sum(int a, int b) { | ||
return a + b; | ||
} |
7 changes: 7 additions & 0 deletions
7
tests/packages/link-library-in-subproject/subprojects/bar/examplelib.h
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 | ||
|
||
#include "bar_dll.h" | ||
|
||
BAR_DLL int sum(int a, int b); |
36 changes: 36 additions & 0 deletions
36
tests/packages/link-library-in-subproject/subprojects/bar/meson.build
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,36 @@ | ||
# SPDX-FileCopyrightText: 2022 The meson-python developers | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
project('bar', 'c', version: '1.2.3', meson_version: '>= 1.3.0') | ||
|
||
if get_option('default_library') == 'shared' and meson.get_compiler('c').get_id() in ['msvc', 'clang-cl', 'intel-cl'] | ||
export_dll_args = ['-DBAR_DLL_EXPORTS'] | ||
import_dll_args = ['-DBAR_DLL_IMPORTS'] | ||
else | ||
export_dll_args = [] | ||
import_dll_args = [] | ||
endif | ||
|
||
example_lib = library( | ||
'examplelib', | ||
'examplelib.c', | ||
c_shared_args: export_dll_args, | ||
install: true, | ||
) | ||
|
||
# A second library that we don't link from `foo`. If we install the subproject, | ||
# this second library also ends up in the wheel. To prevent that, we need to | ||
# skip installing this `bar` subproject, and statically link `example_lib`. | ||
unwanted_lib = library( | ||
'unwantedlib', | ||
'examplelib.c', | ||
c_shared_args: export_dll_args, | ||
install: true, | ||
) | ||
|
||
bar_dep = declare_dependency( | ||
compile_args: import_dll_args, | ||
link_with: example_lib, | ||
include_directories: '.', | ||
) |
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