Skip to content

Commit ab79618

Browse files
committed
Switch to using lief
patchelf is failing on recent Fedora releases Signed-off-by: Cristian Le <[email protected]>
1 parent d2847a2 commit ab79618

File tree

5 files changed

+24
-23
lines changed

5 files changed

+24
-23
lines changed

pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ test-hatchling = [
6969
test-meta = [
7070
"hatch-fancy-pypi-readme>=22.3",
7171
"setuptools-scm",
72-
"auditwheel; platform_system=='Linux'",
72+
"lief; platform_system=='Linux'",
7373
"delocate; platform_system=='Darwin'",
7474
]
7575
test-numpy = [
@@ -199,8 +199,8 @@ module = [
199199
"setuptools_scm",
200200
"hatch_fancy_pypi_readme",
201201
"virtualenv",
202-
"auditwheel.*",
203202
"delocate.*",
203+
"lief.*",
204204
]
205205
ignore_missing_imports = true
206206

@@ -344,3 +344,6 @@ known-local-folder = ["pathutils"]
344344

345345
[tool.check-sdist]
346346
sdist-only = ["src/scikit_build_core/_version.py"]
347+
348+
[tool.codespell]
349+
ignore-words-list = "lief"

src/scikit_build_core/builder/get_requires.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import importlib.util
66
import os
77
import platform
8-
import shutil
98
import sysconfig
109
from typing import TYPE_CHECKING, Literal
1110

@@ -150,10 +149,7 @@ def other_dynamic_requires(self) -> Generator[str, None, None]:
150149
if self.settings.wheel.repair.enable:
151150
platform_system = platform.system()
152151
if platform_system == "Linux":
153-
yield "auditwheel"
154-
patchelf_path = shutil.which("patchelf")
155-
if patchelf_path is None:
156-
yield "patchelf"
152+
yield "lief"
157153
elif platform_system == "Darwin":
158154
yield "delocate"
159155

src/scikit_build_core/repair_wheel/linux.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import dataclasses
88
from typing import TYPE_CHECKING
99

10-
from .._shutil import Run
1110
from .rpath import RpathWheelRepairer
1211

1312
if TYPE_CHECKING:
@@ -30,17 +29,24 @@ class LinuxWheelRepairer(RpathWheelRepairer):
3029
_origin_symbol = "$ORIGIN"
3130

3231
def get_library_rpath(self, artifact: Path) -> list[str]:
33-
from auditwheel.elfutils import elf_read_rpaths
32+
import lief.ELF
3433

35-
return [
36-
path
37-
for dt_rpaths in elf_read_rpaths(artifact).values()
38-
for path in dt_rpaths
39-
]
34+
elf = lief.ELF.parse(artifact)
35+
if not elf.has(lief.ELF.DynamicEntry.TAG.RUNPATH):
36+
# Early exit if library does not have rpaths
37+
return []
38+
elf_rpaths = elf.get(lief.ELF.DynamicEntry.TAG.RUNPATH)
39+
return list(elf_rpaths.paths)
4040

4141
def patch_library_rpath(self, artifact: Path, rpaths: list[str]) -> None:
4242
final_rpaths = set(rpaths)
4343
if final_rpaths:
44-
run = Run()
45-
run.live("patchelf", "--remove-rpath", artifact)
46-
run.live("patchelf", "--set-rpath", ":".join(final_rpaths), artifact)
44+
import lief.ELF
45+
46+
elf_rpaths = lief.ELF.DynamicEntryRunPath()
47+
for rpath in final_rpaths:
48+
elf_rpaths.append(rpath)
49+
elf = lief.ELF.parse(artifact)
50+
elf.remove(lief.ELF.DynamicEntry.TAG.RUNPATH)
51+
elf.add(elf_rpaths)
52+
elf.write(str(artifact))

tests/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ def pep518_wheelhouse(tmp_path_factory: pytest.TempPathFactory) -> Path:
5858
"wheel",
5959
]
6060
if platform.system() == "Linux":
61-
packages.append("auditwheel")
62-
packages.append("patchelf")
61+
packages.append("lief")
6362
if platform.system() == "Darwin":
6463
packages.append("delocate")
6564

tests/test_repair_wheel.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import platform
2-
import shutil
32
from pathlib import Path
43

54
import pytest
@@ -47,9 +46,7 @@ def test_full_build(
4746
if not with_isolation:
4847
isolated.install("scikit-build-core")
4948
if platform.system() == "Linux":
50-
isolated.install("auditwheel")
51-
if shutil.which("patchelf") is None:
52-
isolated.install("patchelf")
49+
isolated.install("lief")
5350
if platform.system() == "Darwin":
5451
isolated.install("delocate")
5552
isolated.install("./extern", isolated=with_isolation)

0 commit comments

Comments
 (0)