Skip to content

Commit

Permalink
ENH: support shared libraries on Windows when explicitly enabled
Browse files Browse the repository at this point in the history
Fixes #525.
  • Loading branch information
dnicolodi committed Dec 9, 2023
1 parent 2a4443e commit d56441c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
14 changes: 12 additions & 2 deletions mesonpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,12 @@ def __init__(
metadata: Metadata,
manifest: Dict[str, List[Tuple[pathlib.Path, str]]],
limited_api: bool,
shared_libs_win32: bool,
) -> None:
self._metadata = metadata
self._manifest = manifest
self._limited_api = limited_api
self._shared_libs_win32 = shared_libs_win32

@property
def _has_internal_libs(self) -> bool:
Expand Down Expand Up @@ -430,6 +432,9 @@ def _install_path(self, wheel_file: mesonpy._wheelfile.WheelFile, origin: Path,

if self._has_internal_libs:
if _is_native(origin):
if sys.platform == 'win32' and not self._shared_libs_win32:
raise NotImplementedError(f'Bundling libraries in wheel is not supported on {sys.platform}')

Check warning on line 436 in mesonpy/__init__.py

View check run for this annotation

Codecov / codecov/patch

mesonpy/__init__.py#L436

Added line #L436 was not covered by tests

# When an executable, libray, or Python extension module is
# dynamically linked to a library built as part of the project,
# Meson adds a library load path to it pointing to the build
Expand Down Expand Up @@ -566,6 +571,7 @@ def _string_or_path(value: Any, name: str) -> str:
scheme = _table({
'meson': _string_or_path,
'limited-api': _bool,
'shared-libs-win32': _bool,
'args': _table({
name: _strings for name in _MESON_ARGS_KEYS
}),
Expand Down Expand Up @@ -757,6 +763,10 @@ def __init__(
if not value:
self._limited_api = False

# Shared library support on Windows requires collaboration
# from the package, make sure the developpers aknowledge this.
self._shared_libs_win32 = pyproject_config.get('shared-libs-win32')

def _run(self, cmd: Sequence[str]) -> None:
"""Invoke a subprocess."""
# Flush the line to ensure that the log line with the executed
Expand Down Expand Up @@ -920,13 +930,13 @@ def sdist(self, directory: Path) -> pathlib.Path:
def wheel(self, directory: Path) -> pathlib.Path:
"""Generates a wheel in the specified directory."""
self.build()
builder = _WheelBuilder(self._metadata, self._manifest, self._limited_api)
builder = _WheelBuilder(self._metadata, self._manifest, self._limited_api, self._shared_libs_win32)
return builder.build(directory)

def editable(self, directory: Path) -> pathlib.Path:
"""Generates an editable wheel in the specified directory."""
self.build()
builder = _EditableWheelBuilder(self._metadata, self._manifest, self._limited_api)
builder = _EditableWheelBuilder(self._metadata, self._manifest, self._limited_api, self._shared_libs_win32)
return builder.build(directory, self._source_dir, self._build_dir, self._build_command, self._editable_verbose)


Expand Down
2 changes: 1 addition & 1 deletion mesonpy/_rpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
if sys.platform == 'win32':

def fix_rpath(filepath: Path, libs_relative_path: str) -> None:
raise NotImplementedError(f'Bundling libraries in wheel is not supported on {sys.platform}')
pass

Check warning on line 22 in mesonpy/_rpath.py

View check run for this annotation

Codecov / codecov/patch

mesonpy/_rpath.py#L22

Added line #L22 was not covered by tests

elif sys.platform == 'darwin':

Expand Down
2 changes: 1 addition & 1 deletion tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_python_host_platform(monkeypatch):
def wheel_builder_test_factory(content, pure=True, limited_api=False):
manifest = defaultdict(list)
manifest.update({key: [(pathlib.Path(x), os.path.join('build', x)) for x in value] for key, value in content.items()})
return mesonpy._WheelBuilder(None, manifest, limited_api)
return mesonpy._WheelBuilder(None, manifest, limited_api, False)


def test_tag_empty_wheel():
Expand Down

0 comments on commit d56441c

Please sign in to comment.