Skip to content

Commit

Permalink
Merge pull request #290 from davidhewitt/fix-dylibs
Browse files Browse the repository at this point in the history
build: fix locating dylib artifacts
  • Loading branch information
davidhewitt authored Sep 18, 2022
2 parents b81ec4b + 2fa3ff9 commit 972d528
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
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

0 comments on commit 972d528

Please sign in to comment.