Skip to content

Commit

Permalink
simplify cross arch preloading
Browse files Browse the repository at this point in the history
This commit does a couple of things. In the mangohud launch script, the library will be found using $LIB with ld, so the correct path is selected depending on the cpu arch. The same is done for mangohud.json (vulkan layer). In addition some now unused files have been deleted.

Signed-off-by: Stephan Lachnit <stephanlachnit@protonmail.com>
  • Loading branch information
stephanlachnit authored and jackun committed Aug 4, 2020
1 parent 6ee225e commit d712d35
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 58 deletions.
24 changes: 11 additions & 13 deletions bin/mangohud.in
@@ -1,10 +1,5 @@
#!/bin/sh

MANGOHUD_LIB_NAME="libMangoHud.so"
if [ "$MANGOHUD_DLSYM" = "1" ]; then
MANGOHUD_LIB_NAME="libMangoHud_dlsym.so:${MANGOHUD_LIB_NAME}"
fi

if [ "$#" -eq 0 ]; then
programname=`basename "$0"`
echo "ERROR: No program supplied"
Expand All @@ -13,13 +8,16 @@ if [ "$#" -eq 0 ]; then
exit 1
fi

# Execute the program under a clean environment
# pass through the overriden LD_PRELOAD environment variables
LD_PRELOAD="${LD_PRELOAD}:${MANGOHUD_LIB_NAME}"
LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:@libdir_mangohud@"
MANGOHUD_LIB_NAME="libMangoHud.so"

if hash @mangohud_sh@ 2>/dev/null; then
exec env MANGOHUD=1 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}" LD_PRELOAD="${LD_PRELOAD}" @mangohud_sh@ "$@"
else
exec env MANGOHUD=1 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}" LD_PRELOAD="${LD_PRELOAD}" "$@"
if [ "$MANGOHUD_DLSYM" = "1" ]; then
MANGOHUD_LIB_NAME="libMangoHud_dlsym.so:${MANGOHUD_LIB_NAME}"
fi

# Preload using the plain filesnames of the libs, the dynamic linker will
# figure out whether the 32 or 64 bit version should be used, and will search
# for it in the correct directory
LD_PRELOAD="${LD_PRELOAD}:${MANGOHUD_LIB_NAME}"
LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:@ld_libdir_mangohud@"

exec env MANGOHUD=1 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}" LD_PRELOAD="${LD_PRELOAD}" "$@"
2 changes: 0 additions & 2 deletions libmangohud.conf

This file was deleted.

1 change: 0 additions & 1 deletion libmangohud.conf.in

This file was deleted.

22 changes: 0 additions & 22 deletions src/mangohud.json

This file was deleted.

5 changes: 2 additions & 3 deletions src/mangohud.json.in
@@ -1,10 +1,10 @@
{
"file_format_version" : "1.0.0",
"layer" : {
"name": "@PROJECT_NAME@@LAYER_SUFFIX@",
"name": "VK_LAYER_@PROJECT_NAME@_overlay",
"type": "GLOBAL",
"api_version": "1.2.135",
"library_path": "@libdir_mangohud@libMangoHud.so",
"library_path": "@ld_libdir_mangohud@libMangoHud.so",
"implementation_version": "1",
"description": "Vulkan Hud Overlay",
"functions": {
Expand All @@ -19,4 +19,3 @@
}
}
}

26 changes: 9 additions & 17 deletions src/meson.build
Expand Up @@ -2,9 +2,11 @@ glslang = find_program('glslangValidator')

# Needs prefix for configure_file()
if get_option('append_libdir_mangohud')
libdir_mangohud = join_paths(get_option('prefix'), get_option('libdir'), 'mangohud')
libdir_mangohud = join_paths(get_option('libdir'), 'mangohud')
ld_libdir_mangohud = get_option('prefix') + '/\$LIB/mangohud/'
else
libdir_mangohud = join_paths(get_option('prefix'), get_option('libdir'))
libdir_mangohud = get_option('libdir')
ld_libdir_mangohud = get_option('prefix') + '/\$LIB/'
endif

overlay_shaders = [
Expand Down Expand Up @@ -163,26 +165,16 @@ mangohud_dlsym = shared_library(
)

configure_file(input : 'mangohud.json.in',
output : '@0@.@1@.json'.format(meson.project_name(), target_machine.cpu_family()),
configuration : {'libdir_mangohud' : libdir_mangohud + '/',
'PROJECT_NAME' : meson.project_name() + ' ',
'LAYER_SUFFIX' : target_machine.cpu_family()},
output : '@0@.json'.format(meson.project_name()),
configuration : {'ld_libdir_mangohud' : ld_libdir_mangohud,
'PROJECT_NAME' : meson.project_name()},
install : true,
install_dir : join_paths(get_option('datadir'), 'vulkan', 'implicit_layer.d'),
)

if target_machine.cpu_family() == 'x86_64'
mangohud_cpu_family = ''
mangohud_opposite_bin = 'mangohud.x86'
else
mangohud_cpu_family = '.@0@'.format(target_machine.cpu_family())
#this is probably dumb but works for now
mangohud_opposite_bin = 'intentionally_borked'
endif

configure_file(input : '../bin/mangohud.in',
output : 'mangohud@0@'.format(mangohud_cpu_family),
configuration : {'libdir_mangohud' : libdir_mangohud, 'mangohud_sh' : mangohud_opposite_bin},
output : 'mangohud',
configuration : {'ld_libdir_mangohud' : ld_libdir_mangohud},
install_dir : get_option('bindir'),
)

Expand Down

0 comments on commit d712d35

Please sign in to comment.