From d712d35aaf5d548f23cc1e1596646cbafc4004a3 Mon Sep 17 00:00:00 2001 From: Stephan Lachnit Date: Mon, 6 Jul 2020 18:59:17 +0200 Subject: [PATCH] simplify cross arch preloading 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 --- bin/mangohud.in | 24 +++++++++++------------- libmangohud.conf | 2 -- libmangohud.conf.in | 1 - src/mangohud.json | 22 ---------------------- src/mangohud.json.in | 5 ++--- src/meson.build | 26 +++++++++----------------- 6 files changed, 22 insertions(+), 58 deletions(-) delete mode 100644 libmangohud.conf delete mode 100644 libmangohud.conf.in delete mode 100644 src/mangohud.json diff --git a/bin/mangohud.in b/bin/mangohud.in index 3fed8a6b..9f91374c 100755 --- a/bin/mangohud.in +++ b/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" @@ -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}" "$@" diff --git a/libmangohud.conf b/libmangohud.conf deleted file mode 100644 index f1170b10..00000000 --- a/libmangohud.conf +++ /dev/null @@ -1,2 +0,0 @@ -/usr/lib/mangohud/lib32 -/usr/lib/mangohud/lib64 diff --git a/libmangohud.conf.in b/libmangohud.conf.in deleted file mode 100644 index 4a68d757..00000000 --- a/libmangohud.conf.in +++ /dev/null @@ -1 +0,0 @@ -@libdir_mangohud@ diff --git a/src/mangohud.json b/src/mangohud.json deleted file mode 100644 index 5b102aa4..00000000 --- a/src/mangohud.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "file_format_version" : "1.0.0", - "layer" : { - "name": "MangoHud", - "type": "GLOBAL", - "api_version": "1.1.125", - "library_path": "libMangoHud.so", - "implementation_version": "1", - "description": "Vulkan Hud Overlay", - "functions": { - "vkGetInstanceProcAddr": "overlay_GetInstanceProcAddr", - "vkGetDeviceProcAddr": "overlay_GetDeviceProcAddr" - }, - "enable_environment": { - "MANGOHUD": "1" - }, - "disable_environment": { - "DISABLE_MANGOHUD": "1" - } - } -} - \ No newline at end of file diff --git a/src/mangohud.json.in b/src/mangohud.json.in index 0e51d629..bfa13187 100644 --- a/src/mangohud.json.in +++ b/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": { @@ -19,4 +19,3 @@ } } } - \ No newline at end of file diff --git a/src/meson.build b/src/meson.build index 12034299..b4867153 100644 --- a/src/meson.build +++ b/src/meson.build @@ -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 = [ @@ -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'), )