Skip to content

Commit c9f701f

Browse files
committed
Initial support for hwcaps-loader
https://github.com/jrelvas-ipc/hwcaps-loader The downside of glibc-hwcaps is it can only support loading higher micro-arch _libraries_, some packages may only provide binaries or their binary front-end does not link against their own library The hwcaps-loader mechanism rectifies that
1 parent f6cc1aa commit c9f701f

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

ypkg2/examine.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@
3737

3838
global_xattrs = dict()
3939

40+
def is_elf_file(file_path):
41+
try:
42+
with open(file_path, 'rb') as file:
43+
magic = file.read(4)
44+
return magic == b'\x7fELF'
45+
except FileNotFoundError as e:
46+
print(f"File not found: {file_path} {e}")
47+
return False
48+
except Exception as e:
49+
print(f"{e}")
50+
return False
4051

4152
def is_pkgconfig_file(pretty, mgs):
4253
""" Simple as it sounds, work out if this is a pkgconfig file """

ypkg2/main.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from .ypkgcontext import YpkgContext
2020
from .scripts import ScriptGenerator
2121
from .packages import PackageGenerator, PRIORITY_USER
22-
from .examine import PackageExaminer
22+
from .examine import PackageExaminer, is_elf_file
2323
from . import metadata
2424
from .dependencies import DependencyResolver
2525
from . import packager_name, packager_email
@@ -38,6 +38,7 @@
3838

3939
from timeit import default_timer as timer
4040
from datetime import timedelta
41+
from pathlib import Path
4142

4243

4344
def show_version():
@@ -190,6 +191,41 @@ def execute_step(context, step, step_n, work_dir):
190191
return False
191192
return True
192193

194+
was_avx2_context = False
195+
196+
def post_execute_step(context, step, step_n, work_dir):
197+
198+
hwcaps_v3_bin_dir = os.path.join(context.get_install_dir(), "usr", "hwcaps", "x86-64-v3", "bin")
199+
hwcaps_v1_bin_dir = os.path.join(context.get_install_dir(), "usr", "hwcaps", "x86-64-v1", "bin")
200+
bin_dir = os.path.join(context.get_install_dir(), "usr", "bin")
201+
202+
if context.avx2 and step_n == "install":
203+
global was_avx2_context
204+
was_avx2_context = True
205+
206+
os.makedirs(hwcaps_v3_bin_dir, exist_ok=True)
207+
for dirpath, dirnames, filenames in os.walk(bin_dir):
208+
for file in filenames:
209+
file_path = os.path.join(dirpath, file)
210+
if is_elf_file(file_path):
211+
shutil.move(file_path, hwcaps_v3_bin_dir)
212+
213+
if context.emul32 is False and context.avx2 is False and step_n == "install" and was_avx2_context is True:
214+
os.makedirs(hwcaps_v1_bin_dir, exist_ok=True)
215+
216+
dummy_hwcaps_loader = Path(bin_dir, "hwcaps-loader")
217+
dummy_hwcaps_loader.touch()
218+
219+
for dirpath, dirnames, filenames in os.walk(bin_dir):
220+
for file in filenames:
221+
file_path = os.path.join(dirpath, file)
222+
if is_elf_file(file_path):
223+
shutil.move(file_path, hwcaps_v1_bin_dir)
224+
relative_target = os.path.relpath(dummy_hwcaps_loader, start=os.path.dirname(file_path))
225+
os.symlink(relative_target, file_path)
226+
227+
os.unlink(dummy_hwcaps_loader)
228+
193229

194230
def build_package(filename, outputDir, buildDir=None):
195231
""" Will in future be moved to a separate part of the module """
@@ -380,6 +416,7 @@ def build_package(filename, outputDir, buildDir=None):
380416
end_time = timer()
381417
console_ui.emit_success("Build", "{} successful ({})".
382418
format(step, timedelta(seconds=end_time-start_time)))
419+
post_execute_step(context, r_step, step, work_dir)
383420
continue
384421
console_ui.emit_error("Build", "{} failed for {}".format(step, spec.pkg_name))
385422
sys.exit(1)

0 commit comments

Comments
 (0)