Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: fix locating dylib artifacts #290

Merged
merged 1 commit into from
Sep 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased
### Fixed
- Fix regression in `dylib` build artifacts not being found since 1.5.0. [#280](https://github.com/PyO3/setuptools-rust/pull/280)

## 1.5.1 (2022-08-14)
### Fixed
- Fix regression in `get_lib_name` crashing since 1.5.0. [#280](https://github.com/PyO3/setuptools-rust/pull/280)
Expand Down
20 changes: 10 additions & 10 deletions setuptools_rust/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def build_extension(
artifacts = _find_cargo_artifacts(
cargo_messages.splitlines(),
package_id=package_id,
kind="bin",
kinds={"bin"},
)
for name, dest in ext.target.items():
if not name:
Expand Down Expand Up @@ -277,15 +277,15 @@ def build_extension(
artifacts = _find_cargo_artifacts(
cargo_messages.splitlines(),
package_id=package_id,
kind="cdylib",
kinds={"cdylib", "dylib"},
)
if len(artifacts) == 0:
raise DistutilsExecError(
"Rust build failed; unable to find any build artifacts"
"Rust build failed; unable to find any cdylib or dylib build artifacts"
)
elif len(artifacts) > 1:
raise DistutilsExecError(
f"Rust build failed; expected only one build artifact but found {artifacts}"
f"Rust build failed; expected only one cdylib or dylib build artifact but found {artifacts}"
)

artifact_path = artifacts[0]
Expand Down Expand Up @@ -657,7 +657,7 @@ def _find_cargo_artifacts(
cargo_messages: List[str],
*,
package_id: str,
kind: str,
kinds: Set[str],
) -> List[str]:
"""Identifies cargo artifacts built for the given `package_id` from the
provided cargo_messages.
Expand All @@ -666,11 +666,11 @@ def _find_cargo_artifacts(
... [
... '{"some_irrelevant_message": []}',
... '{"reason":"compiler-artifact","package_id":"some_id","target":{"kind":["cdylib"]},"filenames":["/some/path/baz.so"]}',
... '{"reason":"compiler-artifact","package_id":"some_id","target":{"kind":["cdylib", "rlib"]},"filenames":["/file/two/baz.dylib", "/file/two/baz.rlib"]}',
... '{"reason":"compiler-artifact","package_id":"some_id","target":{"kind":["dylib", "rlib"]},"filenames":["/file/two/baz.dylib", "/file/two/baz.rlib"]}',
... '{"reason":"compiler-artifact","package_id":"some_other_id","target":{"kind":["cdylib"]},"filenames":["/not/this.so"]}',
... ],
... package_id="some_id",
... kind="cdylib",
... kinds={"cdylib", "dylib"},
... )
['/some/path/baz.so', '/file/two/baz.dylib']
>>> _find_cargo_artifacts(
Expand All @@ -681,14 +681,14 @@ def _find_cargo_artifacts(
... '{"reason":"compiler-artifact","package_id":"some_other_id","target":{"kind":["cdylib"]},"filenames":["/not/this.so"]}',
... ],
... package_id="some_id",
... kind="rlib",
... kinds={"rlib"},
... )
['/file/two/baz.rlib']
"""
artifacts = []
for message in cargo_messages:
# only bother parsing messages that look like a match
if "compiler-artifact" in message and package_id in message and kind in message:
if "compiler-artifact" in message and package_id in message:
parsed = json.loads(message)
# verify the message is correct
if (
Expand All @@ -698,7 +698,7 @@ def _find_cargo_artifacts(
for artifact_kind, filename in zip(
parsed["target"]["kind"], parsed["filenames"]
):
if artifact_kind == kind:
if artifact_kind in kinds:
artifacts.append(filename)
return artifacts

Expand Down